[unity] SkeletonUtility replace flip with scale.

This commit is contained in:
pharan 2018-09-08 21:14:52 +08:00
parent 7b631b2961
commit 1d0221e44d
2 changed files with 26 additions and 15 deletions

View File

@ -98,6 +98,27 @@ namespace Spine.Unity {
}
#endregion
#region Skeleton
/// <summary>Sets the Skeleton's local scale using a UnityEngine.Vector2. If only individual components need to be set, set Skeleton.ScaleX or Skeleton.ScaleY.</summary>
public static void SetLocalScale (this Skeleton skeleton, Vector2 scale) {
skeleton.scaleX = scale.x;
skeleton.scaleY = scale.y;
}
/// <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 {
m00 = bone.a,
m01 = bone.b,
m03 = bone.worldX,
m10 = bone.c,
m11 = bone.d,
m13 = bone.worldY,
m33 = 1
};
}
#endregion
#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) {
@ -149,13 +170,9 @@ namespace Spine.Unity {
return new Quaternion(0, 0, Mathf.Sin(halfRotation), Mathf.Cos(halfRotation));
}
/// <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 {
m00 = bone.a, m01 = bone.b, m03 = bone.worldX,
m10 = bone.c, m11 = bone.d, m13 = bone.worldY,
m33 = 1
};
/// <summary>Returns the Skeleton's local scale as a UnityEngine.Vector2. If only individual components are needed, use Skeleton.ScaleX or Skeleton.ScaleY.</summary>
public static Vector2 GetLocalScale (this Skeleton skeleton) {
return new Vector2(skeleton.scaleX, skeleton.scaleY);
}
/// <summary>Calculates a 2x2 Transformation Matrix that can convert a skeleton-space position to a bone-local position.</summary>

View File

@ -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);
}
}