From 1d0221e44d8b1285b652d2c7322a096917f12c97 Mon Sep 17 00:00:00 2001 From: pharan Date: Sat, 8 Sep 2018 21:14:52 +0800 Subject: [PATCH] [unity] SkeletonUtility replace flip with scale. --- .../Runtime/spine-unity/SkeletonExtensions.cs | 31 ++++++++++++++----- .../SkeletonUtility/SkeletonUtility.cs | 10 ++---- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonExtensions.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonExtensions.cs index 864593ae2..567aa07ca 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonExtensions.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonExtensions.cs @@ -98,6 +98,27 @@ namespace Spine.Unity { } #endregion + #region Skeleton + /// Sets the Skeleton's local scale using a UnityEngine.Vector2. If only individual components need to be set, set Skeleton.ScaleX or Skeleton.ScaleY. + public static void SetLocalScale (this Skeleton skeleton, Vector2 scale) { + skeleton.scaleX = scale.x; + skeleton.scaleY = scale.y; + } + + /// Gets the internal bone matrix as a Unity bonespace-to-skeletonspace transformation matrix. + public static Matrix4x4 GetMatrix4x4 (this Bone bone) { + return new Matrix4x4 { + m00 = bone.a, + m01 = bone.b, + m03 = bone.worldX, + m10 = bone.c, + m11 = bone.d, + m13 = bone.worldY, + m33 = 1 + }; + } + #endregion + #region Bone /// Sets the bone's (local) X and Y according to a Vector2 public static void SetPosition (this Bone bone, Vector2 position) { @@ -149,13 +170,9 @@ namespace Spine.Unity { return new Quaternion(0, 0, Mathf.Sin(halfRotation), Mathf.Cos(halfRotation)); } - /// Gets the internal bone matrix as a Unity bonespace-to-skeletonspace transformation matrix. - public static Matrix4x4 GetMatrix4x4 (this Bone bone) { - return new Matrix4x4 { - m00 = bone.a, m01 = bone.b, m03 = bone.worldX, - m10 = bone.c, m11 = bone.d, m13 = bone.worldY, - m33 = 1 - }; + /// Returns the Skeleton's local scale as a UnityEngine.Vector2. If only individual components are needed, use Skeleton.ScaleX or Skeleton.ScaleY. + public static Vector2 GetLocalScale (this Skeleton skeleton) { + return new Vector2(skeleton.scaleX, skeleton.scaleY); } /// Calculates a 2x2 Transformation Matrix that can convert a skeleton-space position to a bone-local position. diff --git a/spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonUtility/SkeletonUtility.cs b/spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonUtility/SkeletonUtility.cs index d48234ffd..f580f86f5 100644 --- a/spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonUtility/SkeletonUtility.cs +++ b/spine-unity/Assets/Spine/Runtime/spine-unity/SkeletonUtility/SkeletonUtility.cs @@ -103,6 +103,7 @@ namespace Spine.Unity { int floatCount = floats.Length; Bounds bounds = new Bounds(); + bounds.center = new Vector3(floats[0], floats[1], 0); for (int i = 2; i < floatCount; i += 2) bounds.Encapsulate(new Vector3(floats[i], floats[i + 1], 0)); @@ -122,14 +123,7 @@ namespace Spine.Unity { void Update () { var skeleton = skeletonRenderer.skeleton; if (boneRoot != null && skeleton != null) { - Vector3 flipScale = Vector3.one; - if (skeleton.scaleX < 0) - flipScale.x = -1; - - if (skeleton.scaleY < 0) - flipScale.y = -1; - - boneRoot.localScale = flipScale; + boneRoot.localScale = new Vector3(skeleton.scaleX, skeleton.scaleY, 1f); } }