TweenScale.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using UnityEngine;
  3. [AddComponentMenu("NGUI/Tween/Tween Scale")]
  4. public class TweenScale : UITweener
  5. {
  6. public Transform cachedTransform
  7. {
  8. get
  9. {
  10. if (this.mTrans == null)
  11. {
  12. this.mTrans = base.transform;
  13. }
  14. return this.mTrans;
  15. }
  16. }
  17. public Vector3 value
  18. {
  19. get
  20. {
  21. return this.cachedTransform.localScale;
  22. }
  23. set
  24. {
  25. this.cachedTransform.localScale = value;
  26. }
  27. }
  28. [Obsolete("Use 'value' instead")]
  29. public Vector3 scale
  30. {
  31. get
  32. {
  33. return this.value;
  34. }
  35. set
  36. {
  37. this.value = value;
  38. }
  39. }
  40. protected override void OnUpdate(float factor, bool isFinished)
  41. {
  42. this.value = this.from * (1f - factor) + this.to * factor;
  43. if (this.updateTable)
  44. {
  45. if (this.mTable == null)
  46. {
  47. this.mTable = NGUITools.FindInParents<UITable>(base.gameObject);
  48. if (this.mTable == null)
  49. {
  50. this.updateTable = false;
  51. return;
  52. }
  53. }
  54. this.mTable.repositionNow = true;
  55. }
  56. }
  57. public static TweenScale Begin(GameObject go, float duration, Vector3 scale)
  58. {
  59. TweenScale tweenScale = UITweener.Begin<TweenScale>(go, duration);
  60. tweenScale.from = tweenScale.value;
  61. tweenScale.to = scale;
  62. if (duration <= 0f)
  63. {
  64. tweenScale.Sample(1f, true);
  65. tweenScale.enabled = false;
  66. }
  67. return tweenScale;
  68. }
  69. [ContextMenu("Set 'From' to current value")]
  70. public override void SetStartToCurrentValue()
  71. {
  72. this.from = this.value;
  73. }
  74. [ContextMenu("Set 'To' to current value")]
  75. public override void SetEndToCurrentValue()
  76. {
  77. this.to = this.value;
  78. }
  79. [ContextMenu("Assume value of 'From'")]
  80. private void SetCurrentValueToStart()
  81. {
  82. this.value = this.from;
  83. }
  84. [ContextMenu("Assume value of 'To'")]
  85. private void SetCurrentValueToEnd()
  86. {
  87. this.value = this.to;
  88. }
  89. public Vector3 from = Vector3.one;
  90. public Vector3 to = Vector3.one;
  91. public bool updateTable;
  92. private Transform mTrans;
  93. private UITable mTable;
  94. }