DragonBonesData.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /**
  2. * The MIT License (MIT)
  3. *
  4. * Copyright (c) 2012-2017 DragonBones team and other contributors
  5. *
  6. * Permission is hereby granted, free of charge, to any person obtaining a copy of
  7. * this software and associated documentation files (the "Software"), to deal in
  8. * the Software without restriction, including without limitation the rights to
  9. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10. * the Software, and to permit persons to whom the Software is furnished to do so,
  11. * subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all
  14. * copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18. * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19. * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20. * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22. */
  23. using System;
  24. using System.Collections.Generic;
  25. using System.Text;
  26. namespace DragonBones
  27. {
  28. /// <summary>
  29. /// - The DragonBones data.
  30. /// A DragonBones data contains multiple armature data.
  31. /// </summary>
  32. /// <see cref="DragonBones.ArmatureData"/>
  33. /// <version>DragonBones 3.0</version>
  34. /// <language>en_US</language>
  35. /// <summary>
  36. /// - 龙骨数据。
  37. /// 一个龙骨数据包含多个骨架数据。
  38. /// </summary>
  39. /// <see cref="DragonBones.ArmatureData"/>
  40. /// <version>DragonBones 3.0</version>
  41. /// <language>zh_CN</language>
  42. public class DragonBonesData : BaseObject
  43. {
  44. /// <private/>
  45. public bool autoSearch;
  46. /// <summary>
  47. /// - The animation frame rate.
  48. /// </summary>
  49. /// <version>DragonBones 3.0</version>
  50. /// <language>en_US</language>
  51. /// <summary>
  52. /// - 动画帧频。
  53. /// </summary>
  54. /// <version>DragonBones 3.0</version>
  55. /// <language>zh_CN</language>
  56. public uint frameRate;
  57. /// <summary>
  58. /// - The data version.
  59. /// </summary>
  60. /// <version>DragonBones 3.0</version>
  61. /// <language>en_US</language>
  62. /// <summary>
  63. /// - 数据版本。
  64. /// </summary>
  65. /// <version>DragonBones 3.0</version>
  66. /// <language>zh_CN</language>
  67. public string version;
  68. /// <summary>
  69. /// - The DragonBones data name.
  70. /// The name is consistent with the DragonBones project name.
  71. /// </summary>
  72. /// <version>DragonBones 3.0</version>
  73. /// <language>en_US</language>
  74. /// <summary>
  75. /// - 龙骨数据名称。
  76. /// 该名称与龙骨项目名保持一致。
  77. /// </summary>
  78. /// <version>DragonBones 3.0</version>
  79. /// <language>zh_CN</language>
  80. public string name;
  81. /// <private/>
  82. public ArmatureData stage;
  83. /// <internal/>
  84. /// <private/>
  85. public readonly List<uint> frameIndices = new List<uint>();
  86. /// <internal/>
  87. /// <private/>
  88. public readonly List<float> cachedFrames = new List<float>();
  89. /// <summary>
  90. /// - All armature data names.
  91. /// </summary>
  92. /// <version>DragonBones 3.0</version>
  93. /// <language>en_US</language>
  94. /// <summary>
  95. /// - 所有的骨架数据名称。
  96. /// </summary>
  97. /// <version>DragonBones 3.0</version>
  98. /// <language>zh_CN</language>
  99. public readonly List<string> armatureNames = new List<string>();
  100. /// <private/>
  101. public readonly Dictionary<string, ArmatureData> armatures = new Dictionary<string, ArmatureData>();
  102. /// <internal/>
  103. /// <private/>
  104. internal byte[] binary;
  105. /// <internal/>
  106. /// <private/>
  107. internal short[] intArray;
  108. /// <internal/>
  109. /// <private/>
  110. internal float[] floatArray;
  111. /// <internal/>
  112. /// <private/>
  113. internal short[] frameIntArray;
  114. /// <internal/>
  115. /// <private/>
  116. internal float[] frameFloatArray;
  117. /// <internal/>
  118. /// <private/>
  119. internal short[] frameArray;
  120. /// <internal/>
  121. /// <private/>
  122. internal ushort[] timelineArray;
  123. /// <private/>
  124. internal UserData userData = null; // Initial value.
  125. /// <inheritDoc/>
  126. protected override void _OnClear()
  127. {
  128. foreach (var k in this.armatures.Keys)
  129. {
  130. this.armatures[k].ReturnToPool();
  131. }
  132. if (this.userData != null)
  133. {
  134. this.userData.ReturnToPool();
  135. }
  136. this.autoSearch = false;
  137. this.frameRate = 0;
  138. this.version = "";
  139. this.name = "";
  140. this.stage = null;
  141. this.frameIndices.Clear();
  142. this.cachedFrames.Clear();
  143. this.armatureNames.Clear();
  144. this.armatures.Clear();
  145. this.binary = null;
  146. this.intArray = null; //
  147. this.floatArray = null; //
  148. this.frameIntArray = null; //
  149. this.frameFloatArray = null; //
  150. this.frameArray = null; //
  151. this.timelineArray = null; //
  152. this.userData = null;
  153. }
  154. /// <internal/>
  155. /// <private/>
  156. public void AddArmature(ArmatureData value)
  157. {
  158. if (this.armatures.ContainsKey(value.name))
  159. {
  160. Helper.Assert(false, "Same armature: " + value.name);
  161. this.armatures[value.name].ReturnToPool();
  162. }
  163. value.parent = this;
  164. this.armatures[value.name] = value;
  165. this.armatureNames.Add(value.name);
  166. }
  167. /// <summary>
  168. /// - Get a specific armature data.
  169. /// </summary>
  170. /// <param name="armatureName">- The armature data name.</param>
  171. /// <version>DragonBones 3.0</version>
  172. /// <language>en_US</language>
  173. /// <summary>
  174. /// - 获取特定的骨架数据。
  175. /// </summary>
  176. /// <param name="armatureName">- 骨架数据名称。</param>
  177. /// <version>DragonBones 3.0</version>
  178. /// <language>zh_CN</language>
  179. public ArmatureData GetArmature(string armatureName)
  180. {
  181. return this.armatures.ContainsKey(armatureName) ? this.armatures[armatureName] : null;
  182. }
  183. }
  184. }