GMovieClip.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. using UnityEngine;
  2. using FairyGUI.Utils;
  3. namespace FairyGUI
  4. {
  5. /// <summary>
  6. /// GMovieClip class.
  7. /// </summary>
  8. public class GMovieClip : GObject, IAnimationGear, IColorGear
  9. {
  10. MovieClip _content;
  11. EventListener _onPlayEnd;
  12. public GMovieClip()
  13. {
  14. }
  15. override protected void CreateDisplayObject()
  16. {
  17. _content = new MovieClip();
  18. _content.gOwner = this;
  19. _content.ignoreEngineTimeScale = true;
  20. displayObject = _content;
  21. }
  22. /// <summary>
  23. ///
  24. /// </summary>
  25. public EventListener onPlayEnd
  26. {
  27. get { return _onPlayEnd ?? (_onPlayEnd = new EventListener(this, "onPlayEnd")); }
  28. }
  29. /// <summary>
  30. ///
  31. /// </summary>
  32. public bool playing
  33. {
  34. get { return _content.playing; }
  35. set
  36. {
  37. _content.playing = value;
  38. UpdateGear(5);
  39. }
  40. }
  41. /// <summary>
  42. ///
  43. /// </summary>
  44. public int frame
  45. {
  46. get { return _content.frame; }
  47. set
  48. {
  49. _content.frame = value;
  50. UpdateGear(5);
  51. }
  52. }
  53. /// <summary>
  54. ///
  55. /// </summary>
  56. public Color color
  57. {
  58. get { return _content.color; }
  59. set
  60. {
  61. _content.color = value;
  62. UpdateGear(4);
  63. }
  64. }
  65. /// <summary>
  66. ///
  67. /// </summary>
  68. public FlipType flip
  69. {
  70. get { return _content.graphics.flip; }
  71. set { _content.graphics.flip = value; }
  72. }
  73. /// <summary>
  74. ///
  75. /// </summary>
  76. public Material material
  77. {
  78. get { return _content.material; }
  79. set { _content.material = value; }
  80. }
  81. /// <summary>
  82. ///
  83. /// </summary>
  84. public string shader
  85. {
  86. get { return _content.shader; }
  87. set { _content.shader = value; }
  88. }
  89. /// <summary>
  90. ///
  91. /// </summary>
  92. public float timeScale
  93. {
  94. get { return _content.timeScale; }
  95. set { _content.timeScale = value; }
  96. }
  97. /// <summary>
  98. ///
  99. /// </summary>
  100. public bool ignoreEngineTimeScale
  101. {
  102. get { return _content.ignoreEngineTimeScale; }
  103. set { _content.ignoreEngineTimeScale = value; }
  104. }
  105. /// <summary>
  106. ///
  107. /// </summary>
  108. public void Rewind()
  109. {
  110. _content.Rewind();
  111. }
  112. /// <summary>
  113. ///
  114. /// </summary>
  115. /// <param name="anotherMc"></param>
  116. public void SyncStatus(GMovieClip anotherMc)
  117. {
  118. _content.SyncStatus(anotherMc._content);
  119. }
  120. /// <summary>
  121. ///
  122. /// </summary>
  123. /// <param name="time"></param>
  124. public void Advance(float time)
  125. {
  126. _content.Advance(time);
  127. }
  128. /// <summary>
  129. /// Play from the start to end, repeat times, set to endAt on complete.
  130. /// 从start帧开始,播放到end帧(-1表示结尾),重复times次(0表示无限循环),循环结束后,停止在endAt帧(-1表示参数end)
  131. /// </summary>
  132. /// <param name="start">Start frame</param>
  133. /// <param name="end">End frame. -1 indicates the last frame.</param>
  134. /// <param name="times">Repeat times. 0 indicates infinite loop.</param>
  135. /// <param name="endAt">Stop frame. -1 indicates to equal to the end parameter.</param>
  136. public void SetPlaySettings(int start, int end, int times, int endAt)
  137. {
  138. ((MovieClip)displayObject).SetPlaySettings(start, end, times, endAt);
  139. }
  140. override public void ConstructFromResource()
  141. {
  142. this.gameObjectName = packageItem.name;
  143. PackageItem contentItem = packageItem.getBranch();
  144. sourceWidth = contentItem.width;
  145. sourceHeight = contentItem.height;
  146. initWidth = sourceWidth;
  147. initHeight = sourceHeight;
  148. contentItem = contentItem.getHighResolution();
  149. contentItem.Load();
  150. _content.interval = contentItem.interval;
  151. _content.swing = contentItem.swing;
  152. _content.repeatDelay = contentItem.repeatDelay;
  153. _content.frames = contentItem.frames;
  154. SetSize(sourceWidth, sourceHeight);
  155. }
  156. override public void Setup_BeforeAdd(ByteBuffer buffer, int beginPos)
  157. {
  158. base.Setup_BeforeAdd(buffer, beginPos);
  159. buffer.Seek(beginPos, 5);
  160. if (buffer.ReadBool())
  161. _content.color = buffer.ReadColor();
  162. _content.graphics.flip = (FlipType)buffer.ReadByte();
  163. _content.frame = buffer.ReadInt();
  164. _content.playing = buffer.ReadBool();
  165. }
  166. }
  167. }