소스 검색

[unity] New SpineAttributes and Skeleton extensions.

pharan 8 년 전
부모
커밋
47724ea9d8

+ 1 - 4
spine-unity/Assets/spine-unity/BoneFollower.cs

@@ -125,10 +125,7 @@ namespace Spine.Unity {
 			if (skeletonTransformIsParent) {
 				// Recommended setup: Use local transform properties if Spine GameObject is the immediate parent
 				thisTransform.localPosition = new Vector3(bone.worldX, bone.worldY, followZPosition ? 0f : thisTransform.localPosition.z);
-				if (followBoneRotation) {
-					var halfRotation = Mathf.Atan2(bone.c, bone.a) * 0.5f;
-					thisTransform.localRotation = new Quaternion(0, 0, Mathf.Sin(halfRotation), Mathf.Cos(halfRotation)); //thisTransform.localRotation = Quaternion.Euler(0f, 0f, bone.WorldRotationX);
-				}
+				if (followBoneRotation) thisTransform.localRotation = bone.GetQuaternion();
 			} else {
 				// For special cases: Use transform world properties if transform relationship is complicated
 				Vector3 targetWorldPosition = skeletonTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY, 0f));

+ 22 - 0
spine-unity/Assets/spine-unity/SkeletonExtensions.cs

@@ -134,6 +134,28 @@ namespace Spine.Unity {
 			return spineGameObjectTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY));
 		}
 
+		/// <summary>Gets a skeleton space UnityEngine.Quaternion representation of bone.WorldRotationX.</summary>
+		public static Quaternion GetQuaternion (this Bone bone) {
+			var halfRotation = Mathf.Atan2(bone.c, bone.a) * 0.5f;
+			return new Quaternion(0, 0, Mathf.Sin(halfRotation), Mathf.Cos(halfRotation));
+		}
+
+		/// <summary>Gets the PointAttachment's Unity World position using its Spine GameObject Transform.</summary>
+		public static Vector3 GetWorldPosition (this PointAttachment attachment, Slot slot, Transform spineGameObjectTransform) {
+			Vector3 skeletonSpacePosition;
+			skeletonSpacePosition.z = 0;
+			attachment.ComputeWorldPosition(slot.bone, out skeletonSpacePosition.x, out skeletonSpacePosition.y);
+			return spineGameObjectTransform.TransformPoint(skeletonSpacePosition);
+		}
+
+		/// <summary>Gets the PointAttachment's Unity World position using its Spine GameObject Transform.</summary>
+		public static Vector3 GetWorldPosition (this PointAttachment attachment, Bone bone, Transform spineGameObjectTransform) {
+			Vector3 skeletonSpacePosition;
+			skeletonSpacePosition.z = 0;
+			attachment.ComputeWorldPosition(bone, out skeletonSpacePosition.x, out skeletonSpacePosition.y);
+			return spineGameObjectTransform.TransformPoint(skeletonSpacePosition);
+		}
+
 		/// <summary>Gets the internal bone matrix as a Unity bonespace-to-skeletonspace transformation matrix.</summary>
 		public static Matrix4x4 GetMatrix4x4 (this Bone bone) {
 			return new Matrix4x4 {

+ 59 - 1
spine-unity/Assets/spine-unity/SpineAttributes.cs

@@ -50,11 +50,12 @@ namespace Spine.Unity {
 		/// Smart popup menu for Spine Slots
 		/// </summary>
 		/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
+		/// <param name="containsBoundingBoxes">Disables popup results that don't contain bounding box attachments when true.</param>
+		/// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
 		/// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
 		/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives).
 		/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
 		/// </param>
-		/// <param name="containsBoundingBoxes">Disables popup results that don't contain bounding box attachments when true.</param>
 		public SpineSlot(string startsWith = "", string dataField = "", bool containsBoundingBoxes = false, bool includeNone = true) {
 			this.startsWith = startsWith;
 			this.dataField = dataField;
@@ -68,6 +69,7 @@ namespace Spine.Unity {
 		/// Smart popup menu for Spine Events (Spine.EventData)
 		/// </summary>
 		/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
+		/// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
 		/// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
 		/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives).
 		/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
@@ -79,11 +81,63 @@ namespace Spine.Unity {
 		}
 	}
 
+	public class SpineIkConstraint : SpineAttributeBase {
+		/// <summary>
+		/// Smart popup menu for Spine IK Constraints (Spine.IkConstraint)
+		/// </summary>
+		/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
+		/// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
+		/// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
+		/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives).
+		/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
+		/// </param>
+		public SpineIkConstraint(string startsWith = "", string dataField = "", bool includeNone = true) {
+			this.startsWith = startsWith;
+			this.dataField = dataField;
+			this.includeNone = includeNone;
+		}
+	}
+
+	public class SpinePathConstraint : SpineAttributeBase {
+		/// <summary>
+		/// Smart popup menu for Spine Events (Spine.PathConstraint)
+		/// </summary>
+		/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
+		/// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
+		/// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
+		/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives).
+		/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
+		/// </param>
+		public SpinePathConstraint(string startsWith = "", string dataField = "", bool includeNone = true) {
+			this.startsWith = startsWith;
+			this.dataField = dataField;
+			this.includeNone = includeNone;
+		}
+	}
+
+	public class SpineTransformConstraint : SpineAttributeBase {
+		/// <summary>
+		/// Smart popup menu for Spine Transform Constraints (Spine.TransformConstraint)
+		/// </summary>
+		/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
+		/// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
+		/// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
+		/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives).
+		/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
+		/// </param>
+		public SpineTransformConstraint(string startsWith = "", string dataField = "", bool includeNone = true) {
+			this.startsWith = startsWith;
+			this.dataField = dataField;
+			this.includeNone = includeNone;
+		}
+	}
+
 	public class SpineSkin : SpineAttributeBase {
 		/// <summary>
 		/// Smart popup menu for Spine Skins
 		/// </summary>
 		/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
+		/// <param name = "includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
 		/// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
 		/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
 		/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
@@ -100,6 +154,7 @@ namespace Spine.Unity {
 		/// </summary>
 		/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
 		/// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
+		/// <param name="includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
 		/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
 		/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
 		/// </param>
@@ -124,6 +179,8 @@ namespace Spine.Unity {
 		/// <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>
 		/// <param name="placeholdersOnly">Filters popup results to exclude attachments that are not children of Skin Placeholders</param>
 		/// <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>
+		/// <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>
+		/// <param name="includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
 		/// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
 		/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
 		/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.
@@ -184,6 +241,7 @@ namespace Spine.Unity {
 		/// Smart popup menu for Spine Bones
 		/// </summary>
 		/// <param name="startsWith">Filters popup results to elements that begin with supplied string.</param>
+		/// /// <param name="includeNone">If true, the dropdown list will include a "none" option which stored as an empty string.</param>
 		/// <param name="dataField">If specified, a locally scoped field with the name supplied by in dataField will be used to fill the popup results.
 		/// Valid types are SkeletonDataAsset and SkeletonRenderer (and derivatives)
 		/// If left empty and the script the attribute is applied to is derived from Component, GetComponent<SkeletonRenderer>() will be called as a fallback.