源战役客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

291 linhas
16 KiB

  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. // Contributed by: Mitch Thompson
  31. using UnityEngine;
  32. using System;
  33. using System.Collections;
  34. namespace Spine.Unity {
  35. [AttributeUsage(AttributeTargets.Field, Inherited = true, AllowMultiple = false)]
  36. public abstract class SpineAttributeBase : PropertyAttribute {
  37. public string dataField = "";
  38. public string startsWith = "";
  39. public bool includeNone = true;
  40. public bool fallbackToTextField = false;
  41. }
  42. public class SpineSlot : SpineAttributeBase {
  43. public bool containsBoundingBoxes = false;
  44. /// <summary>
  45. /// Smart popup menu for Spine Slots
  46. /// </summary>
  47. /// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
  48. /// <param name="containsBoundingBoxes">Disables popup results that don't contain bounding box attachments when true.</param>
  49. /// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
  50. /// <param name = "fallbackToTextField">If true, and an animation list source can't be found, the field will fall back to a normal text field. If false, it will show an error.</param>
  51. /// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
  52. /// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives).
  53. /// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
  54. /// </param>
  55. public SpineSlot (string startsWith = "", string dataField = "", bool containsBoundingBoxes = false, bool includeNone = true, bool fallbackToTextField = false) {
  56. this.startsWith = startsWith;
  57. this.dataField = dataField;
  58. this.containsBoundingBoxes = containsBoundingBoxes;
  59. this.includeNone = includeNone;
  60. this.fallbackToTextField = fallbackToTextField;
  61. }
  62. }
  63. public class SpineEvent : SpineAttributeBase {
  64. /// <summary>
  65. /// Smart popup menu for Spine Events (Spine.EventData)
  66. /// </summary>
  67. /// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
  68. /// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
  69. /// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
  70. /// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives).
  71. /// If left empty and the script the attribute is applied to is derived from Component, GetComponent(SkeletonRenderer)() will be called as a fallback.
  72. /// </param>
  73. /// <param name="fallbackToTextField">If true, and an animation list source can't be found, the field will fall back to a normal text field. If false, it will show an error.</param>
  74. public SpineEvent (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) {
  75. this.startsWith = startsWith;
  76. this.dataField = dataField;
  77. this.includeNone = includeNone;
  78. this.fallbackToTextField = fallbackToTextField;
  79. }
  80. }
  81. public class SpineIkConstraint : SpineAttributeBase {
  82. /// <summary>
  83. /// Smart popup menu for Spine IK Constraints (Spine.IkConstraint)
  84. /// </summary>
  85. /// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
  86. /// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
  87. /// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
  88. /// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives).
  89. /// If left empty and the script the attribute is applied to is derived from Component, GetComponent(SkeletonRenderer)() will be called as a fallback.
  90. /// </param>
  91. /// <param name = "fallbackToTextField">If true, and an animation list source can't be found, the field will fall back to a normal text field. If false, it will show an error.</param>
  92. public SpineIkConstraint (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) {
  93. this.startsWith = startsWith;
  94. this.dataField = dataField;
  95. this.includeNone = includeNone;
  96. this.fallbackToTextField = fallbackToTextField;
  97. }
  98. }
  99. public class SpinePathConstraint : SpineAttributeBase {
  100. /// <summary>
  101. /// Smart popup menu for Spine Events (Spine.PathConstraint)
  102. /// </summary>
  103. /// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
  104. /// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
  105. /// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
  106. /// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives).
  107. /// If left empty and the script the attribute is applied to is derived from Component, GetComponent(SkeletonRenderer)() will be called as a fallback.
  108. /// </param>
  109. public SpinePathConstraint (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) {
  110. this.startsWith = startsWith;
  111. this.dataField = dataField;
  112. this.includeNone = includeNone;
  113. this.fallbackToTextField = fallbackToTextField;
  114. }
  115. }
  116. public class SpineTransformConstraint : SpineAttributeBase {
  117. /// <summary>
  118. /// Smart popup menu for Spine Transform Constraints (Spine.TransformConstraint)
  119. /// </summary>
  120. /// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
  121. /// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
  122. /// <param name = "fallbackToTextField">If true, and an animation list source can't be found, the field will fall back to a normal text field. If false, it will show an error.</param>
  123. /// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
  124. /// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives).
  125. /// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
  126. /// </param>
  127. public SpineTransformConstraint (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) {
  128. this.startsWith = startsWith;
  129. this.dataField = dataField;
  130. this.includeNone = includeNone;
  131. this.fallbackToTextField = fallbackToTextField;
  132. }
  133. }
  134. public class SpineSkin : SpineAttributeBase {
  135. /// <summary>
  136. /// Smart popup menu for Spine Skins
  137. /// </summary>
  138. /// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
  139. /// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
  140. /// <param name = "fallbackToTextField">If true, and an animation list source can't be found, the field will fall back to a normal text field. If false, it will show an error.</param>
  141. /// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
  142. /// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
  143. /// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
  144. /// </param>
  145. public SpineSkin (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) {
  146. this.startsWith = startsWith;
  147. this.dataField = dataField;
  148. this.includeNone = includeNone;
  149. this.fallbackToTextField = fallbackToTextField;
  150. }
  151. }
  152. public class SpineAnimation : SpineAttributeBase {
  153. /// <summary>
  154. /// Smart popup menu for Spine Animations
  155. /// </summary>
  156. /// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
  157. /// <param name = "fallbackToTextField">If true, and an animation list source can't be found, the field will fall back to a normal text field. If false, it will show an error.</param>
  158. /// <param name="includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
  159. /// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
  160. /// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
  161. /// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
  162. /// </param>
  163. public SpineAnimation (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) {
  164. this.startsWith = startsWith;
  165. this.dataField = dataField;
  166. this.includeNone = includeNone;
  167. this.fallbackToTextField = fallbackToTextField;
  168. }
  169. }
  170. public class SpineAttachment : SpineAttributeBase {
  171. public bool returnAttachmentPath = false;
  172. public bool currentSkinOnly = false;
  173. public bool placeholdersOnly = false;
  174. public string skinField = "";
  175. public string slotField = "";
  176. /// <summary>
  177. /// Smart popup menu for Spine Attachments
  178. /// </summary>
  179. /// <param name="currentSkinOnly">Filters popup results to only include the current Skin. Only valid when a SkeletonRenderer is the data source.</param>
  180. /// <param name="returnAttachmentPath">Returns a fully qualified path for an Attachment in the format "Skin/Slot/AttachmentName". This path format is only used by the SpineAttachment helper methods like SpineAttachment.GetAttachment and .GetHierarchy. Do not use full path anywhere else in Spine's system.</param>
  181. /// <param name="placeholdersOnly">Filters popup results to exclude attachments that are not children of Skin Placeholders</param>
  182. /// <param name="slotField">If specified, a locally scoped field with the name supplied by in slotField will be used to limit the popup results to children of a named slot</param>
  183. /// <param name="skinField">If specified, a locally scoped field with the name supplied by in skinField will be used to limit the popup results to entries of the named skin</param>
  184. /// <param name="includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
  185. /// <param name = "fallbackToTextField">If true, and an animation list source can't be found, the field will fall back to a normal text field. If false, it will show an error.</param>
  186. /// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
  187. /// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
  188. /// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
  189. /// </param>
  190. public SpineAttachment (bool currentSkinOnly = true, bool returnAttachmentPath = false, bool placeholdersOnly = false, string slotField = "", string dataField = "", string skinField = "", bool includeNone = true, bool fallbackToTextField = false) {
  191. this.currentSkinOnly = currentSkinOnly;
  192. this.returnAttachmentPath = returnAttachmentPath;
  193. this.placeholdersOnly = placeholdersOnly;
  194. this.slotField = slotField;
  195. this.dataField = dataField;
  196. this.skinField = skinField;
  197. this.includeNone = includeNone;
  198. this.fallbackToTextField = fallbackToTextField;
  199. }
  200. public static SpineAttachment.Hierarchy GetHierarchy (string fullPath) {
  201. return new SpineAttachment.Hierarchy(fullPath);
  202. }
  203. public static Spine.Attachment GetAttachment (string attachmentPath, Spine.SkeletonData skeletonData) {
  204. var hierarchy = SpineAttachment.GetHierarchy(attachmentPath);
  205. return string.IsNullOrEmpty(hierarchy.name) ? null : skeletonData.FindSkin(hierarchy.skin).GetAttachment(skeletonData.FindSlotIndex(hierarchy.slot), hierarchy.name);
  206. }
  207. public static Spine.Attachment GetAttachment (string attachmentPath, SkeletonDataAsset skeletonDataAsset) {
  208. return GetAttachment(attachmentPath, skeletonDataAsset.GetSkeletonData(true));
  209. }
  210. /// <summary>
  211. /// A struct that represents 3 strings that help identify and locate an attachment in a skeleton.</summary>
  212. public struct Hierarchy {
  213. public string skin;
  214. public string slot;
  215. public string name;
  216. public Hierarchy (string fullPath) {
  217. string[] chunks = fullPath.Split(new char[]{'/'}, System.StringSplitOptions.RemoveEmptyEntries);
  218. if (chunks.Length == 0) {
  219. skin = "";
  220. slot = "";
  221. name = "";
  222. return;
  223. }
  224. else if (chunks.Length < 2) {
  225. throw new System.Exception("Cannot generate Attachment Hierarchy from string! Not enough components! [" + fullPath + "]");
  226. }
  227. skin = chunks[0];
  228. slot = chunks[1];
  229. name = "";
  230. for (int i = 2; i < chunks.Length; i++) {
  231. name += chunks[i];
  232. }
  233. }
  234. }
  235. }
  236. public class SpineBone : SpineAttributeBase {
  237. /// <summary>
  238. /// Smart popup menu for Spine Bones
  239. /// </summary>
  240. /// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
  241. /// <param name="includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
  242. /// <param name = "fallbackToTextField">If true, and an animation list source can't be found, the field will fall back to a normal text field. If false, it will show an error.</param>
  243. /// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
  244. /// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
  245. /// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
  246. /// </param>
  247. public SpineBone (string startsWith = "", string dataField = "", bool includeNone = true, bool fallbackToTextField = false) {
  248. this.startsWith = startsWith;
  249. this.dataField = dataField;
  250. this.includeNone = includeNone;
  251. this.fallbackToTextField = fallbackToTextField;
  252. }
  253. public static Spine.Bone GetBone(string boneName, SkeletonRenderer renderer) {
  254. return renderer.skeleton == null ? null : renderer.skeleton.FindBone(boneName);
  255. }
  256. public static Spine.BoneData GetBoneData(string boneName, SkeletonDataAsset skeletonDataAsset) {
  257. var data = skeletonDataAsset.GetSkeletonData(true);
  258. return data.FindBone(boneName);
  259. }
  260. }
  261. public class SpineAtlasRegion : PropertyAttribute {
  262. public string atlasAssetField;
  263. public SpineAtlasRegion (string atlasAssetField = "") {
  264. this.atlasAssetField = atlasAssetField;
  265. }
  266. }
  267. }