Skip to content

Commit

Permalink
[unity] BoneFollower.followSkeletonFlip
Browse files Browse the repository at this point in the history
  • Loading branch information
pharan committed Jul 15, 2016
1 parent 7e5aa7d commit 0e883f3
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 10 additions & 1 deletion spine-unity/Assets/spine-unity/BoneFollower.cs
Original file line number Diff line number Diff line change
@@ -47,12 +47,16 @@ public SkeletonRenderer SkeletonRenderer {
}
}

/// <summary>If a bone isn't set, boneName is used to find the bone.</summary>
/// <summary>If a bone isn't set in code, boneName is used to find the bone.</summary>
[SpineBone(dataField: "skeletonRenderer")]
public String boneName;

public bool followZPosition = true;
public bool followBoneRotation = true;

[Tooltip("Follows the skeleton's flip state by controlling this Transform's local scale.")]
public bool followSkeletonFlip = false;

[UnityEngine.Serialization.FormerlySerializedAs("resetOnAwake")]
public bool initializeOnAwake = true;
#endregion
@@ -122,6 +126,11 @@ public void LateUpdate () {
thisTransform.rotation = Quaternion.Euler(worldRotation.x, worldRotation.y, skeletonTransform.rotation.eulerAngles.z + bone.WorldRotationX);
}
}

if (followSkeletonFlip) {
float flipScaleY = bone.skeleton.flipX ^ bone.skeleton.flipY ? -1f : 1f;
thisTransform.localScale = new Vector3(1f, flipScaleY, 1f);
}
}
}

Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@
namespace Spine.Unity.Editor {
[CustomEditor(typeof(BoneFollower))]
public class BoneFollowerInspector : UnityEditor.Editor {
SerializedProperty boneName, skeletonRenderer, followZPosition, followBoneRotation;
SerializedProperty boneName, skeletonRenderer, followZPosition, followBoneRotation, followSkeletonFlip;
BoneFollower targetBoneFollower;
bool needsReset;

@@ -44,6 +44,7 @@ void OnEnable () {
boneName = serializedObject.FindProperty("boneName");
followBoneRotation = serializedObject.FindProperty("followBoneRotation");
followZPosition = serializedObject.FindProperty("followZPosition");
followSkeletonFlip = serializedObject.FindProperty("followSkeletonFlip");

targetBoneFollower = (BoneFollower)target;
if (targetBoneFollower.SkeletonRenderer != null)
@@ -80,6 +81,7 @@ override public void OnInspectorGUI () {
}
EditorGUILayout.PropertyField(followBoneRotation);
EditorGUILayout.PropertyField(followZPosition);
EditorGUILayout.PropertyField(followSkeletonFlip);
} else {
var boneFollowerSkeletonRenderer = targetBoneFollower.skeletonRenderer;
if (boneFollowerSkeletonRenderer == null) {

0 comments on commit 0e883f3

Please sign in to comment.