diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs index 99e1a353c..613d4740b 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/Editor/SkeletonUtilityBoneInspector.cs @@ -12,7 +12,9 @@ using Spine; [CustomEditor(typeof(SkeletonUtilityBone)), CanEditMultipleObjects] public class SkeletonUtilityBoneInspector : Editor { - SerializedProperty mode, boneName, zPosition, position, rotation, scale, overrideAlpha, parentReference, flip, flipX; + SerializedProperty mode, boneName, zPosition, position, rotation, scale, overrideAlpha, parentReference; + // MITCH +// SerializedProperty flip, flipX; //multi selected flags bool containsFollows, containsOverrides, multiObject; @@ -34,8 +36,10 @@ public class SkeletonUtilityBoneInspector : Editor { scale = this.serializedObject.FindProperty("scale"); overrideAlpha = this.serializedObject.FindProperty("overrideAlpha"); parentReference = this.serializedObject.FindProperty("parentReference"); - flip = this.serializedObject.FindProperty("flip"); - flipX = this.serializedObject.FindProperty("flipX"); + + // MITCH +// flip = this.serializedObject.FindProperty("flip"); +// flipX = this.serializedObject.FindProperty("flipX"); EvaluateFlags(); @@ -144,22 +148,24 @@ public class SkeletonUtilityBoneInspector : Editor { EditorGUILayout.PropertyField(position); EditorGUILayout.PropertyField(rotation); EditorGUILayout.PropertyField(scale); - EditorGUILayout.PropertyField(flip); + // MITCH +// EditorGUILayout.PropertyField(flip); EditorGUI.BeginDisabledGroup(containsFollows); { EditorGUILayout.PropertyField(overrideAlpha); EditorGUILayout.PropertyField(parentReference); - EditorGUI.BeginDisabledGroup(multiObject || !flip.boolValue); - { - EditorGUI.BeginChangeCheck(); - EditorGUILayout.PropertyField(flipX); - if (EditorGUI.EndChangeCheck()) { - FlipX(flipX.boolValue); - } - } - EditorGUI.EndDisabledGroup(); + // MITCH +// EditorGUI.BeginDisabledGroup(multiObject || !flip.boolValue); +// { +// EditorGUI.BeginChangeCheck(); +// EditorGUILayout.PropertyField(flipX); +// if (EditorGUI.EndChangeCheck()) { +// FlipX(flipX.boolValue); +// } +// } +// EditorGUI.EndDisabledGroup(); } EditorGUI.EndDisabledGroup(); @@ -226,12 +232,13 @@ public class SkeletonUtilityBoneInspector : Editor { serializedObject.ApplyModifiedProperties(); } - void FlipX (bool state) { - utilityBone.FlipX(state); - if (Application.isPlaying == false) { - skeletonUtility.skeletonAnimation.LateUpdate(); - } - } + // MITCH +// void FlipX (bool state) { +// utilityBone.FlipX(state); +// if (Application.isPlaying == false) { +// skeletonUtility.skeletonAnimation.LateUpdate(); +// } +// } void BoneSelectorContextMenu (string current, ExposedList bones, string topValue, GenericMenu.MenuFunction2 callback) { GenericMenu menu = new GenericMenu(); @@ -329,7 +336,7 @@ public class SkeletonUtilityBoneInspector : Editor { } } - void AttachRigidbody (SkeletonUtilityBone utilBone) { + static void AttachRigidbody (SkeletonUtilityBone utilBone) { if (utilBone.GetComponent() == null) { if (utilBone.bone.Data.Length == 0) { SphereCollider sphere = utilBone.gameObject.AddComponent(); diff --git a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityBone.cs b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityBone.cs index b4aff99ad..0a9f3cd4b 100644 --- a/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityBone.cs +++ b/spine-unity/Assets/spine-unity/SkeletonUtility/SkeletonUtilityBone.cs @@ -32,6 +32,8 @@ public class SkeletonUtilityBone : MonoBehaviour { public bool position; public bool rotation; public bool scale; + // MITCH : remove flipX + // Kept these fields public to retain serialization. Probably remove eventually? public bool flip; public bool flipX; [Range(0f, 1f)] @@ -40,18 +42,23 @@ public class SkeletonUtilityBone : MonoBehaviour { /// If a bone isn't set, boneName is used to find the bone. public String boneName; public Transform parentReference; - [HideInInspector] + + [System.NonSerialized] public bool transformLerpComplete; + protected Transform cachedTransform; protected Transform skeletonTransform; - public bool NonUniformScaleWarning { - get { - return nonUniformScaleWarning; - } - } + // MITCH : nonuniform scale +// private bool nonUniformScaleWarning; +// public bool NonUniformScaleWarning { +// get { return nonUniformScaleWarning; } +// } - private bool nonUniformScaleWarning; + private bool disableInheritScaleWarning; + public bool DisableInheritScaleWarning { + get { return disableInheritScaleWarning; } + } public void Reset () { bone = null; @@ -60,10 +67,8 @@ public class SkeletonUtilityBone : MonoBehaviour { if (!valid) return; skeletonTransform = skeletonUtility.transform; - skeletonUtility.OnReset -= HandleOnReset; skeletonUtility.OnReset += HandleOnReset; - DoUpdate(); } @@ -74,7 +79,6 @@ public class SkeletonUtilityBone : MonoBehaviour { return; skeletonUtility.RegisterBone(this); - skeletonUtility.OnReset += HandleOnReset; } @@ -85,13 +89,11 @@ public class SkeletonUtilityBone : MonoBehaviour { void OnDisable () { if (skeletonUtility != null) { skeletonUtility.OnReset -= HandleOnReset; - skeletonUtility.UnregisterBone(this); } } public void DoUpdate () { - if (!valid) { Reset(); return; @@ -102,39 +104,34 @@ public class SkeletonUtilityBone : MonoBehaviour { if (bone == null) { if (boneName == null || boneName.Length == 0) return; + bone = skeleton.FindBone(boneName); + if (bone == null) { Debug.LogError("Bone not found: " + boneName, this); return; } } - - float skeletonFlipRotation = (skeleton.flipX ^ skeleton.flipY) ? -1f : 1f; - float flipCompensation = 0; - - // MITCH - //if (flip && (flipX || (flipX != bone.flipX)) && bone.parent != null) { - // flipCompensation = bone.parent.WorldRotation * -2; - //} + // MITCH : remove flipX +// float flipCompensation = 0; +// if (flip && (flipX || (flipX != bone.flipX)) && bone.parent != null) { +// flipCompensation = bone.parent.WorldRotation * -2; +// } if (mode == Mode.Follow) { - if (flip) { - // MITCH - //flipX = bone.flipX; - } - - - if (position) { + // MITCH : remove flipX +// if (flip) +// flipX = bone.flipX; + + if (position) cachedTransform.localPosition = new Vector3(bone.x, bone.y, 0); - } if (rotation) { - if (bone.Data.InheritRotation) { - // MITCH + // MITCH : remove flipX //if (bone.FlipX) { // cachedTransform.localRotation = Quaternion.Euler(0, 180, bone.rotationIK - flipCompensation); //} else { @@ -142,21 +139,18 @@ public class SkeletonUtilityBone : MonoBehaviour { //} } else { Vector3 euler = skeletonTransform.rotation.eulerAngles; - cachedTransform.rotation = Quaternion.Euler(euler.x, euler.y, skeletonTransform.rotation.eulerAngles.z + (bone.WorldRotationX * skeletonFlipRotation)); + cachedTransform.rotation = Quaternion.Euler(euler.x, euler.y, euler.z + (bone.WorldRotationX * skeletonFlipRotation)); } - } if (scale) { cachedTransform.localScale = new Vector3(bone.scaleX, bone.scaleY, bone.WorldSignX); - - nonUniformScaleWarning = (bone.scaleX != bone.scaleY); + // MITCH : nonuniform scale + //nonUniformScaleWarning = (bone.scaleX != bone.scaleY); + disableInheritScaleWarning = !bone.data.inheritScale; } } else if (mode == Mode.Override) { - - - if (transformLerpComplete) return; @@ -167,21 +161,22 @@ public class SkeletonUtilityBone : MonoBehaviour { } if (rotation) { - float angle = Mathf.LerpAngle(bone.Rotation, cachedTransform.localRotation.eulerAngles.z, overrideAlpha) + flipCompensation; - - if (flip) { - // MITCH - //if ((!flipX && bone.flipX)) { - // angle -= flipCompensation; - //} - - //TODO fix this... - if (angle >= 360) - angle -= 360; - else if (angle <= -360) - angle += 360; - } + float angle = Mathf.LerpAngle(bone.Rotation, cachedTransform.localRotation.eulerAngles.z, overrideAlpha); + // MITCH : remove flipX +// float angle = Mathf.LerpAngle(bone.Rotation, cachedTransform.localRotation.eulerAngles.z, overrideAlpha) + flipCompensation; +// if (flip) { +// +// if ((!flipX && bone.flipX)) { +// angle -= flipCompensation; +// } +// +// //TODO fix this... +// if (angle >= 360) +// angle -= 360; +// else if (angle <= -360) +// angle += 360; +// } bone.Rotation = angle; bone.AppliedRotation = angle; } @@ -189,16 +184,14 @@ public class SkeletonUtilityBone : MonoBehaviour { if (scale) { bone.scaleX = Mathf.Lerp(bone.scaleX, cachedTransform.localScale.x, overrideAlpha); bone.scaleY = Mathf.Lerp(bone.scaleY, cachedTransform.localScale.y, overrideAlpha); - - nonUniformScaleWarning = (bone.scaleX != bone.scaleY); + // MITCH : nonuniform scale + //nonUniformScaleWarning = (bone.scaleX != bone.scaleY); } - // MITCH - //if (flip) { + // MITCH : remove flipX + //if (flip) // bone.flipX = flipX; - //} } else { - if (transformLerpComplete) return; @@ -208,74 +201,84 @@ public class SkeletonUtilityBone : MonoBehaviour { bone.y = Mathf.Lerp(bone.y, pos.y, overrideAlpha); } + // MITCH if (rotation) { - float angle = Mathf.LerpAngle(bone.Rotation, Quaternion.LookRotation(flipX ? Vector3.forward * -1 : Vector3.forward, parentReference.InverseTransformDirection(cachedTransform.up)).eulerAngles.z, overrideAlpha) + flipCompensation; - - if (flip) { - // MITCH - //if ((!flipX && bone.flipX)) { - // angle -= flipCompensation; - //} - - //TODO fix this... - if (angle >= 360) - angle -= 360; - else if (angle <= -360) - angle += 360; - } + float angle = Mathf.LerpAngle(bone.Rotation, Quaternion.LookRotation(flipX ? Vector3.forward * -1 : Vector3.forward, parentReference.InverseTransformDirection(cachedTransform.up)).eulerAngles.z, overrideAlpha); + // MITCH : remove flipX +// float angle = Mathf.LerpAngle(bone.Rotation, Quaternion.LookRotation(flipX ? Vector3.forward * -1 : Vector3.forward, parentReference.InverseTransformDirection(cachedTransform.up)).eulerAngles.z, overrideAlpha) + flipCompensation; +// if (flip) { +// +// if ((!flipX && bone.flipX)) { +// angle -= flipCompensation; +// } +// +// //TODO fix this... +// if (angle >= 360) +// angle -= 360; +// else if (angle <= -360) +// angle += 360; +// } bone.Rotation = angle; bone.AppliedRotation = angle; } - - //TODO: Something about this + if (scale) { bone.scaleX = Mathf.Lerp(bone.scaleX, cachedTransform.localScale.x, overrideAlpha); bone.scaleY = Mathf.Lerp(bone.scaleY, cachedTransform.localScale.y, overrideAlpha); - - nonUniformScaleWarning = (bone.scaleX != bone.scaleY); + // MITCH : nonuniform scale + //nonUniformScaleWarning = (bone.scaleX != bone.scaleY); } - // MITCH - //if (flip) { + disableInheritScaleWarning = !bone.data.inheritScale; + + // MITCH : remove flipX + //if (flip) // bone.flipX = flipX; - //} } transformLerpComplete = true; } } - public void FlipX (bool state) { - if (state != flipX) { - flipX = state; - if (flipX && Mathf.Abs(transform.localRotation.eulerAngles.y) > 90) { - skeletonUtility.skeletonAnimation.LateUpdate(); - return; - } else if (!flipX && Mathf.Abs(transform.localRotation.eulerAngles.y) < 90) { - skeletonUtility.skeletonAnimation.LateUpdate(); - return; - } - } - - // MITCH - //bone.FlipX = state; - transform.RotateAround(transform.position, skeletonUtility.transform.up, 180); - Vector3 euler = transform.localRotation.eulerAngles; - euler.x = 0; - // MITCH - //euler.y = bone.FlipX ? 180 : 0; - euler.y = 0; - transform.localRotation = Quaternion.Euler(euler); - } + // MITCH : remove flipX +// public void FlipX (bool state) { +// if (state != flipX) { +// flipX = state; +// if (flipX && Mathf.Abs(transform.localRotation.eulerAngles.y) > 90) { +// skeletonUtility.skeletonAnimation.LateUpdate(); +// return; +// } else if (!flipX && Mathf.Abs(transform.localRotation.eulerAngles.y) < 90) { +// skeletonUtility.skeletonAnimation.LateUpdate(); +// return; +// } +// } +// +// +// bone.FlipX = state; +// transform.RotateAround(transform.position, skeletonUtility.transform.up, 180); +// Vector3 euler = transform.localRotation.eulerAngles; +// euler.x = 0; +// +// euler.y = bone.FlipX ? 180 : 0; +// euler.y = 0; +// transform.localRotation = Quaternion.Euler(euler); +// } public void AddBoundingBox (string skinName, string slotName, string attachmentName) { SkeletonUtility.AddBoundingBox(bone.skeleton, skinName, slotName, attachmentName, transform); } + + #if UNITY_EDITOR void OnDrawGizmos () { - if (NonUniformScaleWarning) { - Gizmos.DrawIcon(transform.position + new Vector3(0, 0.128f, 0), "icon-warning"); - } + // MITCH : nonuniform scale +// if (NonUniformScaleWarning) { +// Gizmos.DrawIcon(transform.position + new Vector3(0, 0.128f, 0), "icon-warning"); +// } + + if (DisableInheritScaleWarning) + Gizmos.DrawIcon(transform.position + new Vector3(0, 0.128f, 0), "icon-warning"); } + #endif } \ No newline at end of file