DisplayData.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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.Collections.Generic;
  24. namespace DragonBones
  25. {
  26. /// <internal/>
  27. /// <private/>
  28. public class VerticesData
  29. {
  30. public bool isShared;
  31. public bool inheritDeform;
  32. public int offset;
  33. public DragonBonesData data;
  34. public WeightData weight; // Initial value.
  35. public void Clear()
  36. {
  37. if (!this.isShared && this.weight != null)
  38. {
  39. this.weight.ReturnToPool();
  40. }
  41. this.isShared = false;
  42. this.inheritDeform = false;
  43. this.offset = 0;
  44. this.data = null;
  45. this.weight = null;
  46. }
  47. public void ShareFrom(VerticesData value)
  48. {
  49. this.isShared = true;
  50. this.offset = value.offset;
  51. this.weight = value.weight;
  52. }
  53. }
  54. /// <internal/>
  55. /// <private/>
  56. public abstract class DisplayData : BaseObject
  57. {
  58. public DisplayType type;
  59. public string name;
  60. public string path;
  61. public SkinData parent;
  62. public readonly TransformDB transform = new TransformDB();
  63. protected override void _OnClear()
  64. {
  65. this.name = "";
  66. this.path = "";
  67. this.transform.Identity();
  68. this.parent = null; //
  69. }
  70. }
  71. /// <internal/>
  72. /// <private/>
  73. public class ImageDisplayData : DisplayData
  74. {
  75. public readonly Point pivot = new Point();
  76. public TextureData texture = null;
  77. protected override void _OnClear()
  78. {
  79. base._OnClear();
  80. this.type = DisplayType.Image;
  81. this.pivot.Clear();
  82. this.texture = null;
  83. }
  84. }
  85. /// <internal/>
  86. /// <private/>
  87. public class ArmatureDisplayData : DisplayData
  88. {
  89. public bool inheritAnimation;
  90. public readonly List<ActionData> actions = new List<ActionData>();
  91. public ArmatureData armature = null;
  92. protected override void _OnClear()
  93. {
  94. base._OnClear();
  95. foreach (var action in this.actions)
  96. {
  97. action.ReturnToPool();
  98. }
  99. this.type = DisplayType.Armature;
  100. this.inheritAnimation = false;
  101. this.actions.Clear();
  102. this.armature = null;
  103. }
  104. /// <private/>
  105. internal void AddAction(ActionData value)
  106. {
  107. this.actions.Add(value);
  108. }
  109. }
  110. /// <internal/>
  111. /// <private/>
  112. public class MeshDisplayData : DisplayData
  113. {
  114. public readonly VerticesData vertices = new VerticesData();
  115. public TextureData texture;
  116. protected override void _OnClear()
  117. {
  118. base._OnClear();
  119. this.type = DisplayType.Mesh;
  120. this.vertices.Clear();
  121. this.texture = null;
  122. }
  123. }
  124. /// <internal/>
  125. /// <private/>
  126. public class BoundingBoxDisplayData : DisplayData
  127. {
  128. public BoundingBoxData boundingBox = null; // Initial value.
  129. protected override void _OnClear()
  130. {
  131. base._OnClear();
  132. if (this.boundingBox != null)
  133. {
  134. this.boundingBox.ReturnToPool();
  135. }
  136. this.type = DisplayType.BoundingBox;
  137. this.boundingBox = null;
  138. }
  139. }
  140. /// <internal/>
  141. /// <private/>
  142. public class PathDisplayData : DisplayData
  143. {
  144. public bool closed;
  145. public bool constantSpeed;
  146. public readonly VerticesData vertices = new VerticesData();
  147. public readonly List<float> curveLengths = new List<float>();
  148. protected override void _OnClear()
  149. {
  150. base._OnClear();
  151. this.type = DisplayType.Path;
  152. this.closed = false;
  153. this.constantSpeed = false;
  154. this.vertices.Clear();
  155. this.curveLengths.Clear();
  156. }
  157. }
  158. /// <internal/>
  159. /// <private/>
  160. public class WeightData : BaseObject
  161. {
  162. public int count;
  163. public int offset; // IntArray.
  164. public readonly List<BoneData> bones = new List<BoneData>();
  165. protected override void _OnClear()
  166. {
  167. this.count = 0;
  168. this.offset = 0;
  169. this.bones.Clear();
  170. }
  171. internal void AddBone(BoneData value)
  172. {
  173. this.bones.Add(value);
  174. }
  175. }
  176. }