TweenScale.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //----------------------------------------------
  2. // NGUI: Next-Gen UI kit
  3. // Copyright © 2011-2014 Tasharen Entertainment
  4. //----------------------------------------------
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. /// <summary>
  8. /// Tween the object's local scale.
  9. /// </summary>
  10. public class TweenScale : Tweener
  11. {
  12. public Vector3 from = Vector3.one;
  13. public Vector3 to = Vector3.one;
  14. public bool updateTable = false;
  15. Transform mTrans;
  16. public Transform cachedTransform { get { if (mTrans == null) mTrans = transform; return mTrans; } }
  17. public Vector3 value { get { return cachedTransform.localScale; } set { cachedTransform.localScale = value; } }
  18. /// <summary>
  19. /// Tween the value.
  20. /// </summary>
  21. protected override void OnUpdate (float factor, bool isFinished)
  22. {
  23. value = from * (1f - factor) + to * factor;
  24. }
  25. /// <summary>
  26. /// Start the tweening operation.
  27. /// </summary>
  28. static public TweenScale Begin (GameObject go, float duration, Vector3 scale)
  29. {
  30. TweenScale comp = Tweener.Begin<TweenScale>(go, duration);
  31. comp.from = comp.value;
  32. comp.to = scale;
  33. if (duration <= 0f)
  34. {
  35. comp.Sample(1f, true);
  36. comp.enabled = false;
  37. }
  38. return comp;
  39. }
  40. [ContextMenu("Set 'From' to current value")]
  41. public override void SetStartToCurrentValue () { from = value; }
  42. [ContextMenu("Set 'To' to current value")]
  43. public override void SetEndToCurrentValue () { to = value; }
  44. [ContextMenu("Assume value of 'From'")]
  45. void SetCurrentValueToStart () { value = from; }
  46. [ContextMenu("Assume value of 'To'")]
  47. void SetCurrentValueToEnd () { value = to; }
  48. }