GearBase.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. if (buffer.version >= 6)
  112. {
  113. if (this is GearAnimation)
  114. {
  115. for (int i = 0; i < cnt; i++)
  116. {
  117. string page = buffer.ReadS();
  118. if (page == null)
  119. continue;
  120. ((GearAnimation)this).AddExtStatus(page, buffer);
  121. }
  122. if (buffer.ReadBool())
  123. ((GearAnimation)this).AddExtStatus(null, buffer);
  124. }
  125. }
  126. }
  127. virtual public void UpdateFromRelations(float dx, float dy)
  128. {
  129. }
  130. abstract protected void AddStatus(string pageId, ByteBuffer buffer);
  131. abstract protected void Init();
  132. /// <summary>
  133. /// Call when controller active page changed.
  134. /// </summary>
  135. abstract public void Apply();
  136. /// <summary>
  137. /// Call when object's properties changed.
  138. /// </summary>
  139. abstract public void UpdateState();
  140. }
  141. public class GearTweenConfig
  142. {
  143. /// <summary>
  144. /// Use tween to apply change.
  145. /// </summary>
  146. public bool tween;
  147. /// <summary>
  148. /// Ease type.
  149. /// </summary>
  150. public EaseType easeType;
  151. /// <summary>
  152. ///
  153. /// </summary>
  154. public CustomEase customEase;
  155. /// <summary>
  156. /// Tween duration in seconds.
  157. /// </summary>
  158. public float duration;
  159. /// <summary>
  160. /// Tween delay in seconds.
  161. /// </summary>
  162. public float delay;
  163. internal uint _displayLockToken;
  164. internal GTweener _tweener;
  165. public GearTweenConfig()
  166. {
  167. tween = true;
  168. easeType = EaseType.QuadOut;
  169. duration = 0.3f;
  170. delay = 0;
  171. }
  172. }
  173. }