GearBase.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using FairyGUI.Utils;
  2. namespace FairyGUI
  3. {
  4. /// <summary>
  5. /// Gear is a connection between object and controller.
  6. /// </summary>
  7. abstract public class GearBase
  8. {
  9. public static bool disableAllTweenEffect = false;
  10. protected GObject _owner;
  11. protected Controller _controller;
  12. protected GearTweenConfig _tweenConfig;
  13. public GearBase(GObject owner)
  14. {
  15. _owner = owner;
  16. }
  17. public void Dispose()
  18. {
  19. if (_tweenConfig != null && _tweenConfig._tweener != null)
  20. {
  21. _tweenConfig._tweener.Kill();
  22. _tweenConfig._tweener = null;
  23. }
  24. }
  25. /// <summary>
  26. /// Controller object.
  27. /// </summary>
  28. public Controller controller
  29. {
  30. get
  31. {
  32. return _controller;
  33. }
  34. set
  35. {
  36. if (value != _controller)
  37. {
  38. _controller = value;
  39. if (_controller != null)
  40. Init();
  41. }
  42. }
  43. }
  44. public GearTweenConfig tweenConfig
  45. {
  46. get
  47. {
  48. if (_tweenConfig == null)
  49. _tweenConfig = new GearTweenConfig();
  50. return _tweenConfig;
  51. }
  52. }
  53. public void Setup(ByteBuffer buffer)
  54. {
  55. _controller = _owner.parent.GetControllerAt(buffer.ReadShort());
  56. Init();
  57. int cnt = buffer.ReadShort();
  58. if (this is GearDisplay)
  59. {
  60. ((GearDisplay)this).pages = buffer.ReadSArray(cnt);
  61. }
  62. else if (this is GearDisplay2)
  63. {
  64. ((GearDisplay2)this).pages = buffer.ReadSArray(cnt);
  65. }
  66. else
  67. {
  68. for (int i = 0; i < cnt; i++)
  69. {
  70. string page = buffer.ReadS();
  71. if (page == null)
  72. continue;
  73. AddStatus(page, buffer);
  74. }
  75. if (buffer.ReadBool())
  76. AddStatus(null, buffer);
  77. }
  78. if (buffer.ReadBool())
  79. {
  80. _tweenConfig = new GearTweenConfig();
  81. _tweenConfig.easeType = (EaseType)buffer.ReadByte();
  82. _tweenConfig.duration = buffer.ReadFloat();
  83. _tweenConfig.delay = buffer.ReadFloat();
  84. }
  85. if (buffer.version >= 2)
  86. {
  87. if (this is GearXY)
  88. {
  89. if (buffer.ReadBool())
  90. {
  91. ((GearXY)this).positionsInPercent = true;
  92. for (int i = 0; i < cnt; i++)
  93. {
  94. string page = buffer.ReadS();
  95. if (page == null)
  96. continue;
  97. ((GearXY)this).AddExtStatus(page, buffer);
  98. }
  99. if (buffer.ReadBool())
  100. ((GearXY)this).AddExtStatus(null, buffer);
  101. }
  102. }
  103. else if (this is GearDisplay2)
  104. ((GearDisplay2)this).condition = buffer.ReadByte();
  105. }
  106. if (buffer.version >= 4 && _tweenConfig != null && _tweenConfig.easeType == EaseType.Custom)
  107. {
  108. _tweenConfig.customEase = new CustomEase();
  109. _tweenConfig.customEase.Create(buffer.ReadPath());
  110. }
  111. }
  112. virtual public void UpdateFromRelations(float dx, float dy)
  113. {
  114. }
  115. abstract protected void AddStatus(string pageId, ByteBuffer buffer);
  116. abstract protected void Init();
  117. /// <summary>
  118. /// Call when controller active page changed.
  119. /// </summary>
  120. abstract public void Apply();
  121. /// <summary>
  122. /// Call when object's properties changed.
  123. /// </summary>
  124. abstract public void UpdateState();
  125. }
  126. public class GearTweenConfig
  127. {
  128. /// <summary>
  129. /// Use tween to apply change.
  130. /// </summary>
  131. public bool tween;
  132. /// <summary>
  133. /// Ease type.
  134. /// </summary>
  135. public EaseType easeType;
  136. /// <summary>
  137. ///
  138. /// </summary>
  139. public CustomEase customEase;
  140. /// <summary>
  141. /// Tween duration in seconds.
  142. /// </summary>
  143. public float duration;
  144. /// <summary>
  145. /// Tween delay in seconds.
  146. /// </summary>
  147. public float delay;
  148. internal uint _displayLockToken;
  149. internal GTweener _tweener;
  150. public GearTweenConfig()
  151. {
  152. tween = true;
  153. easeType = EaseType.QuadOut;
  154. duration = 0.3f;
  155. delay = 0;
  156. }
  157. }
  158. }