diff --git a/spine-unity/Assets/spine-unity/SkeletonExtensions.cs b/spine-unity/Assets/spine-unity/SkeletonExtensions.cs index 7773bf8ea..8f04b0a8b 100644 --- a/spine-unity/Assets/spine-unity/SkeletonExtensions.cs +++ b/spine-unity/Assets/spine-unity/SkeletonExtensions.cs @@ -114,10 +114,12 @@ namespace Spine.Unity { return new Vector2(bone.x, bone.y); } + /// Gets the position of the bone in Skeleton-space. public static Vector2 GetSkeletonSpacePosition (this Bone bone) { return new Vector2(bone.worldX, bone.worldY); } + /// Gets a local offset from the bone and converts it into Skeleton-space. public static Vector2 GetSkeletonSpacePosition (this Bone bone, Vector2 boneLocal) { Vector2 o; bone.LocalToWorld(boneLocal.x, boneLocal.y, out o.x, out o.y); @@ -136,6 +138,7 @@ namespace Spine.Unity { }; } + /// Outputs a 2x2 Transformation Matrix that can convert a skeleton-space position to a bone-local position. 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 invDet = 1 / (a * d - b * c); @@ -144,6 +147,13 @@ namespace Spine.Unity { ic = invDet * -c; id = invDet * a; } + + /// UnityEngine.Vector2 override of Bone.WorldToLocal. This converts a skeleton-space position into a bone local position. + public static Vector2 WorldToLocal (this Bone bone, Vector2 worldPosition) { + Vector2 o; + bone.WorldToLocal(worldPosition.x, worldPosition.y, out o.x, out o.y); + return o; + } #endregion #region Attachments