using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using GameCore; namespace GameLogic { public class SliderCtrl : MonoBehaviour { [SerializeField] Slider slider; [SerializeField] Text progress; float cur; /// /// 更新slider /// /// Current. /// Max. public void UpdateValue(int cur, int max) { this.cur = 1f * cur / max; } /// /// 更新slider /// /// Value. public void UpdateValue(float value) { this.cur = value; } /// /// 强制设置slider /// /// Value. public void SetValue(float value) { this.cur = value; this.slider.value = value; this.progress.text= Mathf.Floor(value*100) + "%"; } void Update() { if (Mathf.Abs(slider.value - cur) < 0.005) return; float fv = Mathf.Lerp(slider.value, cur, Time.deltaTime * 5); slider.value = fv; progress.text = Mathf.Floor(fv * 100) + "%"; } } }