//------------------------------------------------- // NGUI: Next-Gen UI kit // Copyright © 2011-2019 Tasharen Entertainment Inc //------------------------------------------------- using UnityEngine; /// /// Tween the sprite's fill. /// [RequireComponent(typeof(UIBasicSprite))] [AddComponentMenu("NGUI/Tween/Tween Fill")] public class TweenFill : UITweener { [Range(0f, 1f)] public float from = 1f; [Range(0f, 1f)] public float to = 1f; bool mCached = false; UIBasicSprite mSprite; void Cache () { mCached = true; mSprite = GetComponent(); } /// /// Tween's current value. /// public float value { get { if (!mCached) Cache(); if (mSprite != null) return mSprite.fillAmount; return 0f; } set { if (!mCached) Cache(); if (mSprite != null) mSprite.fillAmount = value; } } /// /// Tween the value. /// protected override void OnUpdate (float factor, bool isFinished) { value = Mathf.Lerp(from, to, factor); } /// /// Start the tweening operation. /// static public TweenFill Begin (GameObject go, float duration, float fill) { TweenFill comp = UITweener.Begin(go, duration); comp.from = comp.value; comp.to = fill; if (duration <= 0f) { comp.Sample(1f, true); comp.enabled = false; } return comp; } public override void SetStartToCurrentValue () { from = value; } public override void SetEndToCurrentValue () { to = value; } }