当前位置: 首页 > article >正文

unity 不规则ui进度条带有圆头效果

using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UniRx;
using UnityEngine.UI;

public class Temperature : MonoBehaviour
{
public enum TempType
{
///
/// 电机
///
Motor,

    /// <summary>
    /// 电池
    /// </summary>
    Battery
}

[SerializeField] private TempType m_TempType;
[SerializeField] private TMP_Text Text_MotorCurrent;
[SerializeField] private TMP_Text Text_MotorHighest;

[SerializeField] private Image Image_Current;
[SerializeField] private Image Image_Highest;

[SerializeField] private FillAmountPoint _currentFAP;
[SerializeField] private FillAmountPoint _highestFAP;
[SerializeField] private ImageControl _currentIC;

// 起点和终点的填充值
private float fillRangeMin = 0.07f;
private float fillRangeMax = 0.94f;

private static readonly string TAG = "Temperature";

// Start is called before the first frame update
void Start()
{
    if (m_TempType == TempType.Motor)
    {
        DataCenter.MotorTemperature.Subscribe(f =>
        {
            if (f == DataCenter.UNDEFIND)
            {
                Text_MotorCurrent.text = "-.-<size=26>\u2103</size>";
                Image_Current.fillAmount = 0;
                SetImageValue(Image_Current,0);
            }
            else
            {
                if (DataCenter.MotorTemperature_Max.Value < f)
                    DataCenter.MotorTemperature_Max.Value = f;

                float showValue = BM.Snake.Utils.GetLimitValue(f, -30f, 150f);
                Text_MotorCurrent.text = $"{showValue:F1}<size=26>\u2103</size>";
                //  温度范围-30~150
                SetImageValue(Image_Current, (f + 30f) / 180f);
            }
        }).AddTo(this);

        DataCenter.MotorTemperature_Max.Subscribe(f =>
        {
            if (f == DataCenter.UNDEFIND)
            {
                Text_MotorHighest.text = "-.-<size=26>\u2103</size>";
                Image_Highest.fillAmount = 0;
                SetImageValue(Image_Highest, 0);
            }
            else
            {
                float showValue = BM.Snake.Utils.GetLimitValue(f, -30f, 150f);
                Text_MotorHighest.text = $"{showValue:F1}\u2103";
                //  温度范围-30~150
                SetImageValue(Image_Highest, (f + 30f) / 180f);
            }
        }).AddTo(this);
    }
    else
    {
        DataCenter.BatteryTemperature.Subscribe(f =>
        {
            if (f == DataCenter.UNDEFIND)
            {
                Text_MotorCurrent.text = "-.-<size=26>\u2103</size>";
                Image_Current.fillAmount = 0;
                SetImageValue(Image_Current, 0);
            }
            else
            {
                if (DataCenter.BatteryTemperature_Max.Value < f)
                    DataCenter.BatteryTemperature_Max.Value = f;

                float showValue = BM.Snake.Utils.GetLimitValue(f, -30f, 60f);
                Text_MotorCurrent.text = $"{showValue:F1}<size=26>\u2103</size>";
                //  温度范围-30~60
                SetImageValue(Image_Current, (f + 30f) / 90f);
            }
        }).AddTo(this);

        DataCenter.BatteryTemperature_Max.Subscribe(f =>
        {
            if (f == DataCenter.UNDEFIND)
            {
                Text_MotorHighest.text = "-.-<size=26>\u2103</size>";
                Image_Highest.fillAmount = 0;
                SetImageValue(Image_Highest,0);
            }
            else
            {
                float showValue = BM.Snake.Utils.GetLimitValue(f, -30f, 60f);
                Text_MotorHighest.text = $"{showValue:F1}\u2103";
                SetImageValue(Image_Highest, (f + 30f) / 90f);
            }
        }).AddTo(this);
    }
}

private void SetImageValue(Image image, float value)
{
    float pre = Mathf.Lerp(fillRangeMin, fillRangeMax, value);
    if (Image_Highest == image)
    {
        if (_highestFAP) { _highestFAP.SetPreImage(pre); }
    }
    else if (Image_Current == image)
    {
        if (_currentFAP) { _currentFAP.SetPreImage(pre); }
        if (_currentIC) { _currentIC.SetPreImage(pre); }
    }
    image.fillAmount = pre;
}

}


http://www.kler.cn/a/281592.html

相关文章:

  • 【开端】基于nginx部署的具有网关的web日志分析
  • Something wrong with the VAD algorithm
  • 深度解读SGM41511电源管理芯片I2C通讯协议REG0B寄存器解释
  • 某张卡NR only下可以驻网 AUTO模式下在2G/3G工作
  • Redis事物和主从同步
  • Java 5.1 - Spring
  • Web3与人工智能的完美结合:如何重塑数字未来
  • 培训第三十八天(上传镜像,私有仓库下载镜像,跨主机容器间的通信,harbor软件包下载)
  • C++对C的扩充(8.28)
  • 【设计模式】创建型模式——简单工厂模式
  • ElementPlus下拉框输入框对齐问题
  • 算法训练第24天|122.买卖股票的最佳时机II|55. 跳跃游戏|45.跳跃游戏II|1005.K次取反后最大化的数组和
  • 网络自动化:利用Python和Ansible实现网络配置管理
  • Neo4J下载安装
  • gptk是什么意思?Mac电脑如何在crossover里安装gptk2.0测试版?借助GPTK玩《原神》《黑神话悟空》游戏
  • 【AI】自动驾驶的分级
  • edge跟谷歌浏览器配置浏览器可跨域
  • 构建Spring Boot应用的多环境配置策略
  • Spring 源码解读:手动实现IoC容器的基本概念与职责
  • 使用maven搭建微服务框架