TweenAnchorMin.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using UnityEngine;
  2. /// <summary>
  3. /// Tween the object's position.
  4. /// </summary>
  5. [RequireComponent(typeof(RectTransform))]
  6. public class TweenAnchorMin : Tweener
  7. {
  8. public Vector2 from;
  9. public Vector2 to;
  10. RectTransform mTrans;
  11. public RectTransform cachedTransform {
  12. get {
  13. if (mTrans == null)
  14. {
  15. mTrans = GetComponent<RectTransform>();
  16. if (mTrans == null)
  17. mTrans = gameObject.AddComponent<RectTransform>();
  18. }
  19. return mTrans;
  20. }
  21. }
  22. /// <summary>
  23. /// Tween's current value.
  24. /// </summary>
  25. public Vector2 value {
  26. get {
  27. return cachedTransform.anchorMin;
  28. }
  29. set {
  30. cachedTransform.anchorMin = value;
  31. }
  32. }
  33. /// <summary>
  34. /// Tween the value.
  35. /// </summary>
  36. protected override void OnUpdate(float factor, bool isFinished)
  37. {
  38. value = from * (1f - factor) + to * factor;
  39. }
  40. /// <summary>
  41. /// Start the tweening operation.
  42. /// </summary>
  43. static public TweenSize Begin(GameObject go, float duration, Vector2 size)
  44. {
  45. TweenSize comp = Tweener.Begin<TweenSize>(go, duration);
  46. comp.from = comp.value;
  47. comp.to = size;
  48. if (duration <= 0f)
  49. {
  50. comp.Sample(1f, true);
  51. comp.enabled = false;
  52. }
  53. return comp;
  54. }
  55. [ContextMenu("Set 'From' to current value")]
  56. public override void SetStartToCurrentValue()
  57. {
  58. from = value;
  59. }
  60. [ContextMenu("Set 'To' to current value")]
  61. public override void SetEndToCurrentValue()
  62. {
  63. to = value;
  64. }
  65. [ContextMenu("Assume value of 'From'")]
  66. void SetCurrentValueToStart()
  67. {
  68. value = from;
  69. }
  70. [ContextMenu("Assume value of 'To'")]
  71. void SetCurrentValueToEnd()
  72. {
  73. value = to;
  74. }
  75. }