源战役客户端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

224 rader
9.7 KiB

1 månad sedan
  1. /******************************************************************************
  2. * Spine Runtimes Software License v2.5
  3. *
  4. * Copyright (c) 2013-2016, Esoteric Software
  5. * All rights reserved.
  6. *
  7. * You are granted a perpetual, non-exclusive, non-sublicensable, and
  8. * non-transferable license to use, install, execute, and perform the Spine
  9. * Runtimes software and derivative works solely for personal or internal
  10. * use. Without the written permission of Esoteric Software (see Section 2 of
  11. * the Spine Software License Agreement), you may not (a) modify, translate,
  12. * adapt, or develop new applications using the Spine Runtimes or otherwise
  13. * create derivative works or improvements of the Spine Runtimes or (b) remove,
  14. * delete, alter, or obscure any trademarks or any copyright, trademark, patent,
  15. * or other intellectual property or proprietary rights notices on or in the
  16. * Software, including any copy thereof. Redistributions in binary or source
  17. * form must include this license and terms.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  22. * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
  25. * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  26. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *****************************************************************************/
  30. using System;
  31. namespace Spine {
  32. /// <summary>Stores the setup pose and all of the stateless data for a skeleton.</summary>
  33. public class SkeletonData {
  34. internal string name;
  35. internal ExposedList<BoneData> bones = new ExposedList<BoneData>(); // Ordered parents first
  36. internal ExposedList<SlotData> slots = new ExposedList<SlotData>(); // Setup pose draw order.
  37. internal ExposedList<Skin> skins = new ExposedList<Skin>();
  38. internal Skin defaultSkin;
  39. internal ExposedList<EventData> events = new ExposedList<EventData>();
  40. internal ExposedList<Animation> animations = new ExposedList<Animation>();
  41. internal ExposedList<IkConstraintData> ikConstraints = new ExposedList<IkConstraintData>();
  42. internal ExposedList<TransformConstraintData> transformConstraints = new ExposedList<TransformConstraintData>();
  43. internal ExposedList<PathConstraintData> pathConstraints = new ExposedList<PathConstraintData>();
  44. internal float width, height;
  45. internal string version, hash;
  46. // Nonessential.
  47. internal float fps;
  48. internal string imagesPath;
  49. public string Name { get { return name; } set { name = value; } }
  50. /// <summary>The skeleton's bones, sorted parent first. The root bone is always the first bone.</summary>
  51. public ExposedList<BoneData> Bones { get { return bones; } }
  52. public ExposedList<SlotData> Slots { get { return slots; } }
  53. /// <summary>All skins, including the default skin.</summary>
  54. public ExposedList<Skin> Skins { get { return skins; } set { skins = value; } }
  55. /// <summary>
  56. /// The skeleton's default skin.
  57. /// By default this skin contains all attachments that were not in a skin in Spine.
  58. /// </summary>
  59. /// <return>May be null.</return>
  60. public Skin DefaultSkin { get { return defaultSkin; } set { defaultSkin = value; } }
  61. public ExposedList<EventData> Events { get { return events; } set { events = value; } }
  62. public ExposedList<Animation> Animations { get { return animations; } set { animations = value; } }
  63. public ExposedList<IkConstraintData> IkConstraints { get { return ikConstraints; } set { ikConstraints = value; } }
  64. public ExposedList<TransformConstraintData> TransformConstraints { get { return transformConstraints; } set { transformConstraints = value; } }
  65. public ExposedList<PathConstraintData> PathConstraints { get { return pathConstraints; } set { pathConstraints = value; } }
  66. public float Width { get { return width; } set { width = value; } }
  67. public float Height { get { return height; } set { height = value; } }
  68. /// <summary>The Spine version used to export this data, or null.</summary>
  69. public string Version { get { return version; } set { version = value; } }
  70. public string Hash { get { return hash; } set { hash = value; } }
  71. public string ImagesPath { get { return imagesPath; } set { imagesPath = value; } }
  72. /// <summary>
  73. /// The dopesheet FPS in Spine. Available only when nonessential data was exported.</summary>
  74. public float Fps { get { return fps; } set { fps = value; } }
  75. // --- Bones.
  76. /// <summary>
  77. /// Finds a bone by comparing each bone's name.
  78. /// It is more efficient to cache the results of this method than to call it multiple times.</summary>
  79. /// <returns>May be null.</returns>
  80. public BoneData FindBone (string boneName) {
  81. if (boneName == null) throw new ArgumentNullException("boneName", "boneName cannot be null.");
  82. var bones = this.bones;
  83. var bonesItems = bones.Items;
  84. for (int i = 0, n = bones.Count; i < n; i++) {
  85. BoneData bone = bonesItems[i];
  86. if (bone.name == boneName) return bone;
  87. }
  88. return null;
  89. }
  90. /// <returns>-1 if the bone was not found.</returns>
  91. public int FindBoneIndex (string boneName) {
  92. if (boneName == null) throw new ArgumentNullException("boneName", "boneName cannot be null.");
  93. var bones = this.bones;
  94. var bonesItems = bones.Items;
  95. for (int i = 0, n = bones.Count; i < n; i++)
  96. if (bonesItems[i].name == boneName) return i;
  97. return -1;
  98. }
  99. // --- Slots.
  100. /// <returns>May be null.</returns>
  101. public SlotData FindSlot (string slotName) {
  102. if (slotName == null) throw new ArgumentNullException("slotName", "slotName cannot be null.");
  103. ExposedList<SlotData> slots = this.slots;
  104. for (int i = 0, n = slots.Count; i < n; i++) {
  105. SlotData slot = slots.Items[i];
  106. if (slot.name == slotName) return slot;
  107. }
  108. return null;
  109. }
  110. /// <returns>-1 if the slot was not found.</returns>
  111. public int FindSlotIndex (string slotName) {
  112. if (slotName == null) throw new ArgumentNullException("slotName", "slotName cannot be null.");
  113. ExposedList<SlotData> slots = this.slots;
  114. for (int i = 0, n = slots.Count; i < n; i++)
  115. if (slots.Items[i].name == slotName) return i;
  116. return -1;
  117. }
  118. // --- Skins.
  119. /// <returns>May be null.</returns>
  120. public Skin FindSkin (string skinName) {
  121. if (skinName == null) throw new ArgumentNullException("skinName", "skinName cannot be null.");
  122. foreach (Skin skin in skins)
  123. if (skin.name == skinName) return skin;
  124. return null;
  125. }
  126. // --- Events.
  127. /// <returns>May be null.</returns>
  128. public EventData FindEvent (string eventDataName) {
  129. if (eventDataName == null) throw new ArgumentNullException("eventDataName", "eventDataName cannot be null.");
  130. foreach (EventData eventData in events)
  131. if (eventData.name == eventDataName) return eventData;
  132. return null;
  133. }
  134. // --- Animations.
  135. /// <returns>May be null.</returns>
  136. public Animation FindAnimation (string animationName) {
  137. if (animationName == null) throw new ArgumentNullException("animationName", "animationName cannot be null.");
  138. ExposedList<Animation> animations = this.animations;
  139. for (int i = 0, n = animations.Count; i < n; i++) {
  140. Animation animation = animations.Items[i];
  141. if (animation.name == animationName) return animation;
  142. }
  143. return null;
  144. }
  145. // --- IK constraints.
  146. /// <returns>May be null.</returns>
  147. public IkConstraintData FindIkConstraint (string constraintName) {
  148. if (constraintName == null) throw new ArgumentNullException("constraintName", "constraintName cannot be null.");
  149. ExposedList<IkConstraintData> ikConstraints = this.ikConstraints;
  150. for (int i = 0, n = ikConstraints.Count; i < n; i++) {
  151. IkConstraintData ikConstraint = ikConstraints.Items[i];
  152. if (ikConstraint.name == constraintName) return ikConstraint;
  153. }
  154. return null;
  155. }
  156. // --- Transform constraints.
  157. /// <returns>May be null.</returns>
  158. public TransformConstraintData FindTransformConstraint (string constraintName) {
  159. if (constraintName == null) throw new ArgumentNullException("constraintName", "constraintName cannot be null.");
  160. ExposedList<TransformConstraintData> transformConstraints = this.transformConstraints;
  161. for (int i = 0, n = transformConstraints.Count; i < n; i++) {
  162. TransformConstraintData transformConstraint = transformConstraints.Items[i];
  163. if (transformConstraint.name == constraintName) return transformConstraint;
  164. }
  165. return null;
  166. }
  167. // --- Path constraints.
  168. /// <returns>May be null.</returns>
  169. public PathConstraintData FindPathConstraint (string constraintName) {
  170. if (constraintName == null) throw new ArgumentNullException("constraintName", "constraintName cannot be null.");
  171. ExposedList<PathConstraintData> pathConstraints = this.pathConstraints;
  172. for (int i = 0, n = pathConstraints.Count; i < n; i++) {
  173. PathConstraintData constraint = pathConstraints.Items[i];
  174. if (constraint.name.Equals(constraintName)) return constraint;
  175. }
  176. return null;
  177. }
  178. /// <returns>-1 if the path constraint was not found.</returns>
  179. public int FindPathConstraintIndex (string pathConstraintName) {
  180. if (pathConstraintName == null) throw new ArgumentNullException("pathConstraintName", "pathConstraintName cannot be null.");
  181. ExposedList<PathConstraintData> pathConstraints = this.pathConstraints;
  182. for (int i = 0, n = pathConstraints.Count; i < n; i++)
  183. if (pathConstraints.Items[i].name.Equals(pathConstraintName)) return i;
  184. return -1;
  185. }
  186. // ---
  187. override public string ToString () {
  188. return name ?? base.ToString();
  189. }
  190. }
  191. }