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;
}

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值