1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using UnityEngine;
- using UnityEngine.UI;
- /// <summary>
- /// Tween the object's alpha.
- /// </summary>
- [RequireComponent(typeof(Image))]
- public class TweenFillAmount : Tweener
- {
- [Range(0f, 1f)]
- public float from = 1f;
- [Range(0f, 1f)]
- public float to = 1f;
- public bool resetOnEnable = false;
- Image mGraphic;
- /// <summary>
- /// Tween's current value.
- /// </summary>
- public float value {
- get {
- if (mGraphic == null)
- mGraphic = GetComponent<Image>();
- return mGraphic.fillAmount;
- }
- set {
- if (mGraphic == null)
- mGraphic = GetComponent<Image>();
- mGraphic.fillAmount = value;
- }
- }
- protected override void Awake()
- {
- base.Awake();
- mGraphic = GetComponent<Image>();
- }
- void OnEnable()
- {
- if (resetOnEnable)
- {
- tweenFactor = 0;
- Sample(0, false);
- }
- }
- /// <summary>
- /// Tween the value.
- /// </summary>
- protected override void OnUpdate(float factor, bool isFinished)
- {
- value = Mathf.Lerp(from, to, factor);
- }
- /// <summary>
- /// Start the tweening operation.
- /// </summary>
- static public TweenFillAmount Begin(GameObject go, float duration, float alpha)
- {
- TweenFillAmount comp = Tweener.Begin<TweenFillAmount>(go, duration);
- comp.from = comp.value;
- comp.to = alpha;
- if (duration <= 0f)
- {
- comp.Sample(1f, true);
- comp.enabled = false;
- }
- return comp;
- }
- public override void SetStartToCurrentValue()
- {
- from = value;
- }
- public override void SetEndToCurrentValue()
- {
- to = value;
- }
- }
|