From 6c784ec0cd17a232146e2b9092ea8250e15b3c7a Mon Sep 17 00:00:00 2001 From: John Dy Date: Mon, 27 May 2013 16:45:40 +0800 Subject: [PATCH] Added bone inherit rotation and scale in csharp Just mimicked the changes in spine-libgdx and your code pattern in c#. Working fine in Unity. --- spine-csharp/src/Bone.cs | 15 ++++++++++++--- spine-csharp/src/BoneData.cs | 2 ++ spine-csharp/src/SkeletonJson.cs | 8 ++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/spine-csharp/src/Bone.cs b/spine-csharp/src/Bone.cs index c69a7d9a4..41f1a9ef3 100644 --- a/spine-csharp/src/Bone.cs +++ b/spine-csharp/src/Bone.cs @@ -61,10 +61,19 @@ namespace Spine { if (parent != null) { WorldX = X * parent.M00 + Y * parent.M01 + parent.WorldX; WorldY = X * parent.M10 + Y * parent.M11 + parent.WorldY; - WorldScaleX = parent.WorldScaleX * ScaleX; - WorldScaleY = parent.WorldScaleY * ScaleY; - WorldRotation = parent.WorldRotation + Rotation; + + if(Data.inheritScale) { + WorldScaleX = parent.WorldScaleX * ScaleX; + WorldScaleY = parent.WorldScaleY * ScaleY; + } else { + WorldScaleX = ScaleX; + WorldScaleY = ScaleY; + } + + WorldRotation = Data.inheritRotation ? parent.WorldRotation + Rotation : Rotation; + } else { + WorldX = X; WorldY = Y; WorldScaleX = ScaleX; diff --git a/spine-csharp/src/BoneData.cs b/spine-csharp/src/BoneData.cs index 784f5087c..260b04b47 100644 --- a/spine-csharp/src/BoneData.cs +++ b/spine-csharp/src/BoneData.cs @@ -36,6 +36,8 @@ namespace Spine { public float Rotation { get; set; } public float ScaleX { get; set; } public float ScaleY { get; set; } + public bool inheritScale { get; set; } + public bool inheritRotation { get; set; } /** @param parent May be null. */ public BoneData (String name, BoneData parent) { diff --git a/spine-csharp/src/SkeletonJson.cs b/spine-csharp/src/SkeletonJson.cs index af7b31594..0756bbb42 100644 --- a/spine-csharp/src/SkeletonJson.cs +++ b/spine-csharp/src/SkeletonJson.cs @@ -83,6 +83,8 @@ namespace Spine { boneData.Rotation = GetFloat(boneMap, "rotation", 0); boneData.ScaleX = GetFloat(boneMap, "scaleX", 1); boneData.ScaleY = GetFloat(boneMap, "scaleY", 1); + boneData.inheritScale = GetBoolean (boneMap, "inheritScale", true); + boneData.inheritRotation = GetBoolean (boneMap, "inheritRotation", true); skeletonData.AddBone(boneData); } @@ -174,6 +176,12 @@ namespace Spine { return (float)defaultValue; return (float)map[name]; } + + private bool GetBoolean (Dictionary map, String name, bool defaultValue) { + if (!map.ContainsKey(name)) + return (bool)defaultValue; + return (bool)map[name]; + } public static float ToColor (String hexString, int colorIndex) { if (hexString.Length != 8)