TweenHeight.cs 1.9 KB

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