using System; using UnityEngine; using UnityEngine.UI; namespace Superlazy.UI { [RequireComponent(typeof(Text))] public class SLUISmoothValue : SLUIComponent { public float smoothDuration; public float colorDuration; public Color normalColor = Color.black; public Color increaseColor = new Color(0.706f, 1.0f, 0.122f, 1.0f); public Color decreaseColor = new Color(1.0f, 0.0f, 0.0f, 1.0f); public bool noBigNumStr = false; public string prefix; public string postfix; public string bindingValue; [NonSerialized] public Text text; private double oldValue; private double current; private double newValue; private float currSmoothDuration; private float currColorDuration; protected override void Validate() { text = GetComponent(); } protected override void Init() { } protected override void Enable() { text.color = normalColor; current = SLGame.SessionGet(bindParent.BindPath).Get(bindingValue); SetText(current); } protected override void Disable() { oldValue = 0; current = 0; newValue = 0; currColorDuration = 0; currSmoothDuration = 0; } private void Update() { if (bindParent.Active == false) return; var target = SLGame.SessionGet(bindParent.BindPath).Get(bindingValue); if (target != newValue) { currSmoothDuration = smoothDuration; currColorDuration = colorDuration; newValue = target; oldValue = current; if (oldValue > newValue) { text.color = decreaseColor; } else if (oldValue < newValue) { text.color = increaseColor; } } if (currSmoothDuration > 0) { currSmoothDuration -= Time.deltaTime; if (currSmoothDuration <= 0) { current = newValue; } else { double rate = (currSmoothDuration / smoothDuration); current = rate * oldValue + (1 - rate) * newValue; } SetText(current); } if (currColorDuration > 0) { currColorDuration -= Time.deltaTime; if (currColorDuration <= 0) { text.color = normalColor; } } } private void SetText(double value) { //TODO gstar 임시 string val; //if (noBigNumStr) { val = value.ToString(); } //else //{ // val = value.BigNumString(); //} text.text = val; //text.text = SLGame.GetString(prefix, SLGame.SessionGet(sessionEntity.BindPath)) + SLSystem.GetString(val, SLGame.SessionGet(sessionEntity.BindPath)) + SLSystem.GetString(postfix, SLGame.SessionGet(sessionEntity.BindPath)); } } }