diff --git a/spine-unity/Assets/spine-unity/Editor/BoneFollowerInspector.cs b/spine-unity/Assets/spine-unity/Editor/BoneFollowerInspector.cs index 68944d170..f81af9955 100644 --- a/spine-unity/Assets/spine-unity/Editor/BoneFollowerInspector.cs +++ b/spine-unity/Assets/spine-unity/Editor/BoneFollowerInspector.cs @@ -29,13 +29,10 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *****************************************************************************/ -using System; using UnityEditor; using UnityEngine; - -namespace Spine.Unity.Editor { - +namespace Spine.Unity.Editor { [CustomEditor(typeof(BoneFollower))] public class BoneFollowerInspector : UnityEditor.Editor { SerializedProperty boneName, skeletonRenderer, followZPosition, followBoneRotation; @@ -47,8 +44,10 @@ namespace Spine.Unity.Editor { boneName = serializedObject.FindProperty("boneName"); followBoneRotation = serializedObject.FindProperty("followBoneRotation"); followZPosition = serializedObject.FindProperty("followZPosition"); + component = (BoneFollower)target; - component.skeletonRenderer.Initialize(false); + if (component.SkeletonRenderer != null) + component.SkeletonRenderer.Initialize(false); } override public void OnInspectorGUI () { @@ -62,10 +61,11 @@ namespace Spine.Unity.Editor { // FindRenderer() if (skeletonRenderer.objectReferenceValue == null) { - SkeletonRenderer parentRenderer = SkeletonUtility.GetInParent(component.transform); + SkeletonRenderer parentRenderer = BoneFollowerInspector.GetInParent(component.transform); if (parentRenderer != null) { - skeletonRenderer.objectReferenceValue = (UnityEngine.Object)parentRenderer; + Debug.Log("Inspector automatically assigned BoneFollower.SkeletonRenderer"); + skeletonRenderer.objectReferenceValue = parentRenderer; } } @@ -92,6 +92,21 @@ namespace Spine.Unity.Editor { component.Reset(); } } + + public static T GetInParent (Transform origin) where T : Component { + #if UNITY_4_3 + Transform parent = origin.parent; + while(parent.GetComponent() == null){ + parent = parent.parent; + if(parent == null) + return default(T); + } + + return parent.GetComponent(); + #else + return origin.GetComponentInParent(); + #endif + } } }