mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-06 10:46:53 +08:00
[unity] Some docs and minor additions to SkeletonExtensions
This commit is contained in:
parent
3ae51cb0ec
commit
4df97a8d06
@ -100,16 +100,19 @@ namespace Spine.Unity {
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Bone
|
#region Bone
|
||||||
|
/// <summary>Sets the bone's (local) X and Y according to a Vector2</summary>
|
||||||
public static void SetPosition (this Bone bone, Vector2 position) {
|
public static void SetPosition (this Bone bone, Vector2 position) {
|
||||||
bone.X = position.x;
|
bone.X = position.x;
|
||||||
bone.Y = position.y;
|
bone.Y = position.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Sets the bone's (local) X and Y according to a Vector3. The z component is ignored.</summary>
|
||||||
public static void SetPosition (this Bone bone, Vector3 position) {
|
public static void SetPosition (this Bone bone, Vector3 position) {
|
||||||
bone.X = position.x;
|
bone.X = position.x;
|
||||||
bone.Y = position.y;
|
bone.Y = position.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Gets the bone's local X and Y as a Vector2.</summary>
|
||||||
public static Vector2 GetLocalPosition (this Bone bone) {
|
public static Vector2 GetLocalPosition (this Bone bone) {
|
||||||
return new Vector2(bone.x, bone.y);
|
return new Vector2(bone.x, bone.y);
|
||||||
}
|
}
|
||||||
@ -126,10 +129,12 @@ namespace Spine.Unity {
|
|||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector3 GetWorldPosition (this Bone bone, UnityEngine.Transform parentTransform) {
|
/// <summary>Gets the bone's Unity World position using its Spine GameObject Transform. UpdateWorldTransform needs to have been called for this to return the correct, updated value.</summary>
|
||||||
return parentTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY));
|
public static Vector3 GetWorldPosition (this Bone bone, UnityEngine.Transform spineGameObjectTransform) {
|
||||||
|
return spineGameObjectTransform.TransformPoint(new Vector3(bone.worldX, bone.worldY));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>Gets the internal bone matrix as a Unity bonespace-to-skeletonspace transformation matrix.</summary>
|
||||||
public static Matrix4x4 GetMatrix4x4 (this Bone bone) {
|
public static Matrix4x4 GetMatrix4x4 (this Bone bone) {
|
||||||
return new Matrix4x4 {
|
return new Matrix4x4 {
|
||||||
m00 = bone.a, m01 = bone.b, m03 = bone.worldX,
|
m00 = bone.a, m01 = bone.b, m03 = bone.worldX,
|
||||||
@ -138,7 +143,7 @@ namespace Spine.Unity {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Outputs a 2x2 Transformation Matrix that can convert a skeleton-space position to a bone-local position.</summary>
|
/// <summary>Calculates a 2x2 Transformation Matrix that can convert a skeleton-space position to a bone-local position.</summary>
|
||||||
public static void GetWorldToLocalMatrix (this Bone bone, out float ia, out float ib, out float ic, out float id) {
|
public static void GetWorldToLocalMatrix (this Bone bone, out float ia, out float ib, out float ic, out float id) {
|
||||||
float a = bone.a, b = bone.b, c = bone.c, d = bone.d;
|
float a = bone.a, b = bone.b, c = bone.c, d = bone.d;
|
||||||
float invDet = 1 / (a * d - b * c);
|
float invDet = 1 / (a * d - b * c);
|
||||||
@ -236,6 +241,8 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace Spine {
|
namespace Spine {
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
public static class SkeletonExtensions {
|
public static class SkeletonExtensions {
|
||||||
public static bool IsWeighted (this VertexAttachment va) {
|
public static bool IsWeighted (this VertexAttachment va) {
|
||||||
return va.bones != null && va.bones.Length > 0;
|
return va.bones != null && va.bones.Length > 0;
|
||||||
@ -259,6 +266,85 @@ namespace Spine {
|
|||||||
animation.Apply(skeleton, lastTime, time, loop, events, 1f, false, false);
|
animation.Apply(skeleton, lastTime, time, loop, events, 1f, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void SetPropertyToSetupPose (this Skeleton skeleton, int propertyID) {
|
||||||
|
int tt = propertyID >> 24;
|
||||||
|
var timelineType = (TimelineType)tt;
|
||||||
|
int i = propertyID - (tt << 24);
|
||||||
|
|
||||||
|
Bone bone;
|
||||||
|
IkConstraint ikc;
|
||||||
|
PathConstraint pc;
|
||||||
|
|
||||||
|
switch (timelineType) {
|
||||||
|
// Bone
|
||||||
|
case TimelineType.Rotate:
|
||||||
|
bone = skeleton.bones.Items[i];
|
||||||
|
bone.rotation = bone.data.rotation;
|
||||||
|
break;
|
||||||
|
case TimelineType.Translate:
|
||||||
|
bone = skeleton.bones.Items[i];
|
||||||
|
bone.x = bone.data.x;
|
||||||
|
bone.y = bone.data.y;
|
||||||
|
break;
|
||||||
|
case TimelineType.Scale:
|
||||||
|
bone = skeleton.bones.Items[i];
|
||||||
|
bone.scaleX = bone.data.scaleX;
|
||||||
|
bone.scaleY = bone.data.scaleY;
|
||||||
|
break;
|
||||||
|
case TimelineType.Shear:
|
||||||
|
bone = skeleton.bones.Items[i];
|
||||||
|
bone.shearX = bone.data.shearX;
|
||||||
|
bone.shearY = bone.data.shearY;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Slot
|
||||||
|
case TimelineType.Attachment:
|
||||||
|
skeleton.SetSlotAttachmentToSetupPose(i);
|
||||||
|
break;
|
||||||
|
case TimelineType.Color:
|
||||||
|
skeleton.slots.Items[i].SetColorToSetupPose();
|
||||||
|
break;
|
||||||
|
case TimelineType.Deform:
|
||||||
|
skeleton.slots.Items[i].attachmentVertices.Clear();
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Skeleton
|
||||||
|
case TimelineType.DrawOrder:
|
||||||
|
skeleton.SetDrawOrderToSetupPose();
|
||||||
|
break;
|
||||||
|
|
||||||
|
// IK Constraint
|
||||||
|
case TimelineType.IkConstraint:
|
||||||
|
ikc = skeleton.ikConstraints.Items[i];
|
||||||
|
ikc.mix = ikc.data.mix;
|
||||||
|
ikc.bendDirection = ikc.data.bendDirection;
|
||||||
|
break;
|
||||||
|
case TimelineType.TransformConstraint:
|
||||||
|
var tc = skeleton.transformConstraints.Items[i];
|
||||||
|
var tcData = tc.data;
|
||||||
|
tc.rotateMix = tcData.rotateMix;
|
||||||
|
tc.translateMix = tcData.translateMix;
|
||||||
|
tc.scaleMix = tcData.scaleMix;
|
||||||
|
tc.shearMix = tcData.shearMix;
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Path Constraint
|
||||||
|
case TimelineType.PathConstraintPosition:
|
||||||
|
pc = skeleton.pathConstraints.Items[i];
|
||||||
|
pc.position = pc.data.position;
|
||||||
|
break;
|
||||||
|
case TimelineType.PathConstraintSpacing:
|
||||||
|
pc = skeleton.pathConstraints.Items[i];
|
||||||
|
pc.spacing = pc.data.spacing;
|
||||||
|
break;
|
||||||
|
case TimelineType.PathConstraintMix:
|
||||||
|
pc = skeleton.pathConstraints.Items[i];
|
||||||
|
pc.rotateMix = pc.data.rotateMix;
|
||||||
|
pc.translateMix = pc.data.translateMix;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>Resets the DrawOrder to the Setup Pose's draw order</summary>
|
/// <summary>Resets the DrawOrder to the Setup Pose's draw order</summary>
|
||||||
public static void SetDrawOrderToSetupPose (this Skeleton skeleton) {
|
public static void SetDrawOrderToSetupPose (this Skeleton skeleton) {
|
||||||
var slotsItems = skeleton.slots.Items;
|
var slotsItems = skeleton.slots.Items;
|
||||||
@ -315,5 +401,19 @@ namespace Spine {
|
|||||||
animation.Apply(skeleton, 0, 0, false, null, 0, true, true);
|
animation.Apply(skeleton, 0, 0, false, null, 0, true, true);
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Skins
|
||||||
|
/// <summary><see cref="Spine.Skin.FindNamesForSlot(int,List)"/></summary>
|
||||||
|
public static void FindNamesForSlot (this Skin skin, string slotName, SkeletonData skeletonData, List<string> results) {
|
||||||
|
int slotIndex = skeletonData.FindSlotIndex(slotName);
|
||||||
|
skin.FindNamesForSlot(slotIndex, results);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary><see cref="Spine.Skin.FindAttachmentsForSlot(int,List)"/></summary>
|
||||||
|
public static void FindAttachmentsForSlot (this Skin skin, string slotName, SkeletonData skeletonData, List<Attachment> results) {
|
||||||
|
int slotIndex = skeletonData.FindSlotIndex(slotName);
|
||||||
|
skin.FindAttachmentsForSlot(slotIndex, results);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user