DragonBonesData.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. using System.Collections.Generic;
  2. namespace DragonBones
  3. {
  4. /**
  5. * @language zh_CN
  6. * 自定义数据。
  7. * @version DragonBones 5.0
  8. */
  9. public class CustomData : BaseObject
  10. {
  11. /**
  12. * @language zh_CN
  13. * 自定义整数。
  14. * @version DragonBones 5.0
  15. */
  16. public readonly List<int> ints = new List<int>();
  17. /**
  18. * @language zh_CN
  19. * 自定义浮点数。
  20. * @version DragonBones 5.0
  21. */
  22. public readonly List<float> floats = new List<float>();
  23. /**
  24. * @language zh_CN
  25. * 自定义字符串。
  26. * @version DragonBones 5.0
  27. */
  28. public readonly List<string> strings = new List<string>();
  29. /**
  30. * @private
  31. */
  32. public CustomData()
  33. {
  34. }
  35. /**
  36. * @private
  37. */
  38. protected override void _onClear()
  39. {
  40. ints.Clear();
  41. floats.Clear();
  42. strings.Clear();
  43. }
  44. /**
  45. * @language zh_CN
  46. * 获取自定义整数。
  47. * @version DragonBones 5.0
  48. */
  49. public int getInt(int index = 0)
  50. {
  51. return index >= 0 && index < ints.Count ? ints[index] : 0;
  52. }
  53. /**
  54. * @language zh_CN
  55. * 获取自定义浮点数。
  56. * @version DragonBones 5.0
  57. */
  58. public float getFloat(int index = 0)
  59. {
  60. return index >= 0 && index < floats.Count ? floats[index] : 0.0f;
  61. }
  62. /**
  63. * @language zh_CN
  64. * 获取自定义字符串。
  65. * @version DragonBones 5.0
  66. */
  67. public string getString(int index = 0)
  68. {
  69. return index >= 0 && index < strings.Count ? strings[index] : null;
  70. }
  71. }
  72. /**
  73. * @private
  74. */
  75. public class EventData : BaseObject
  76. {
  77. public EventType type;
  78. public string name;
  79. public BoneData bone;
  80. public SlotData slot;
  81. public CustomData data;
  82. public EventData()
  83. {
  84. }
  85. protected override void _onClear()
  86. {
  87. if (data != null)
  88. {
  89. data.ReturnToPool();
  90. }
  91. type = EventType.None;
  92. name = null;
  93. bone = null;
  94. slot = null;
  95. data = null;
  96. }
  97. }
  98. /**
  99. * @private
  100. */
  101. public class ActionData : BaseObject
  102. {
  103. public ActionType type;
  104. public BoneData bone;
  105. public SlotData slot;
  106. public AnimationConfig animationConfig;
  107. public ActionData()
  108. {
  109. }
  110. protected override void _onClear()
  111. {
  112. if (animationConfig != null)
  113. {
  114. animationConfig.ReturnToPool();
  115. }
  116. type = ActionType.Play;
  117. bone = null;
  118. slot = null;
  119. animationConfig = null;
  120. }
  121. }
  122. /**
  123. * @language zh_CN
  124. * 龙骨数据。
  125. * 一个龙骨数据包含多个骨架数据。
  126. * @see DragonBones.ArmatureData
  127. * @version DragonBones 3.0
  128. */
  129. public class DragonBonesData : BaseObject
  130. {
  131. /**
  132. * @language zh_CN
  133. * 是否开启共享搜索。
  134. * @default false
  135. * @see DragonBones.ArmatureData
  136. * @version DragonBones 4.5
  137. */
  138. public bool autoSearch;
  139. /**
  140. * @language zh_CN
  141. * 动画帧频。
  142. * @version DragonBones 3.0
  143. */
  144. public uint frameRate;
  145. /**
  146. * @language zh_CN
  147. * 数据名称。
  148. * @version DragonBones 3.0
  149. */
  150. public string name;
  151. /**
  152. * @language zh_CN
  153. * 所有骨架数据。
  154. * @see DragonBones.ArmatureData
  155. * @version DragonBones 3.0
  156. */
  157. public readonly Dictionary<string, ArmatureData> armatures = new Dictionary<string, ArmatureData>();
  158. /**
  159. * @private
  160. */
  161. public readonly List<float> cachedFrames = new List<float>();
  162. /**
  163. * @private
  164. */
  165. public CustomData userData;
  166. private readonly List<string> _armatureNames = new List<string>();
  167. /**
  168. * @private
  169. */
  170. public DragonBonesData()
  171. {
  172. }
  173. /**
  174. * @private
  175. */
  176. protected override void _onClear()
  177. {
  178. foreach (var pair in armatures)
  179. {
  180. pair.Value.ReturnToPool();
  181. }
  182. if (userData != null)
  183. {
  184. userData.ReturnToPool();
  185. }
  186. autoSearch = false;
  187. frameRate = 0;
  188. name = null;
  189. armatures.Clear();
  190. cachedFrames.Clear();
  191. userData = null;
  192. _armatureNames.Clear();
  193. }
  194. /**
  195. * @language zh_CN
  196. * 获取骨架。
  197. * @param name 骨架数据骨架名称。
  198. * @see DragonBones.ArmatureData
  199. * @version DragonBones 3.0
  200. */
  201. public ArmatureData GetArmature(string name)
  202. {
  203. return armatures.ContainsKey(name) ? armatures[name] : null;
  204. }
  205. /**
  206. * @private
  207. */
  208. public void AddArmature(ArmatureData value)
  209. {
  210. if (value != null && value.name != null && !armatures.ContainsKey(value.name))
  211. {
  212. armatures[value.name] = value;
  213. _armatureNames.Add(value.name);
  214. value.parent = this;
  215. }
  216. else
  217. {
  218. DragonBones.Assert(false, DragonBones.ARGUMENT_ERROR);
  219. }
  220. }
  221. /**
  222. * @language zh_CN
  223. * 所有骨架数据名称。
  224. * @see #armatures
  225. * @version DragonBones 3.0
  226. */
  227. public List<string> armatureNames
  228. {
  229. get { return _armatureNames; }
  230. }
  231. }
  232. }