using DG.Tweening; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; public class TestUiSlider : MonoBehaviour { public Transform parten; public Transform left; public Transform right; public TextMeshProUGUI txt_left; public TextMeshProUGUI txt_Right; // Start is called before the first frame update void Start() { } public void Leftinit(double value, double upper, double lower = 0) { if (left == null) { return; } if (txt_left != null) { txt_left.text = value.ToString(); } if (value > upper ) { value = upper; //数据异常 } if (value < lower) { value = lower; } float date = (float)(value - lower); float data = (float)(upper - lower); float height = parten.GetComponent().rect.height; float y = (float)(date / data) * height; left.DOLocalMoveY(y, 0.5f); } public void Rightinit(double value, double upper,double lower = 0) { if (right == null ) { return; } if (txt_Right != null) { txt_Right.text = value.ToString(); } if (value>upper) { value = upper; //数据异常 } if (value < lower) { value = lower; } float date =(float) (value - lower); float data = (float)(upper - lower); float height = parten.GetComponent().rect.height; float y = (float)(date / data) * height; right.DOLocalMoveY(y, 0.5f); } }