Exemple #1
0
 public override void OnInspectorGUI()
 {
     base.OnInspectorGUI();
     if (!Application.isPlaying)
     {
         ArmatureMesh am = target as ArmatureMesh;
         if (am.unityArmature != null && am.unityArmature != null &&
             am.unityArmature.parentArmature == null && GUILayout.Button("Remove Armature Mesh", GUILayout.Height(20)))
         {
             am.Remove();
             GUIUtility.ExitGUI();
         }
     }
 }
        public override void OnInspectorGUI()
        {
            Armature armature = target as Armature;

            if (armature == null)
            {
                return;
            }

            bool haveGroup = false;

                        #if UNITY_5_6_OR_NEWER
            haveGroup = armature.sortingGroup != null;
                        #endif

            if (!armature.isUGUI && !haveGroup)
            {
                selectedOption = EditorGUILayout.Popup("Sorting Layer", selectedOption, sortingLayerNames);
                if (sortingLayerNames[selectedOption] != armature.sortingLayerName)
                {
                    Undo.RecordObject(armature, "Sorting Layer");
                    armature.sortingLayerName = sortingLayerNames[selectedOption];
                    EditorUtility.SetDirty(armature);
                }

                int newSortingLayerOrder = EditorGUILayout.IntField("Order in Layer", armature.sortingOrder);
                if (newSortingLayerOrder != armature.sortingOrder)
                {
                    Undo.RecordObject(armature, "Edit Sorting Order");
                    armature.sortingOrder = newSortingLayerOrder;
                    EditorUtility.SetDirty(armature);
                }

                if (GUILayout.Button("Update All Sorting", GUILayout.Height(20)))
                {
                    armature.sortingLayerName = armature.sortingLayerName;
                    armature.sortingOrder     = armature.sortingOrder;
                    EditorUtility.SetDirty(armature);

                    foreach (Renderer render in armature.GetComponentsInChildren <Renderer>(true))
                    {
                        render.sortingLayerName = armature.sortingLayerName;
                        render.sortingOrder     = armature.sortingOrder;
                        EditorUtility.SetDirty(render);

                        SpriteFrame sf = render.GetComponent <SpriteFrame>();
                        if (sf)
                        {
                            sf.sortingLayerName = armature.sortingLayerName;
                            sf.sortingOrder     = armature.sortingOrder;
                            UnityEditor.EditorUtility.SetDirty(sf);
                        }
                        else
                        {
                            SpriteMesh sm = render.GetComponent <SpriteMesh>();
                            if (sm)
                            {
                                sm.sortingLayerName = armature.sortingLayerName;
                                sm.sortingOrder     = armature.sortingOrder;
                                UnityEditor.EditorUtility.SetDirty(sm);
                            }
                        }
                    }

                    foreach (Armature sonArmature in armature.GetComponentsInChildren <Armature>(true))
                    {
                        sonArmature.sortingLayerName = sonArmature.sortingLayerName;
                        sonArmature.sortingOrder     = sonArmature.sortingOrder;
                        EditorUtility.SetDirty(sonArmature);
                    }

                    if (!string.IsNullOrEmpty(armature.gameObject.scene.name))
                    {
                        UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                    }
                }
                EditorGUILayout.Space();
            }

            serializedObject.Update();
            EditorGUILayout.PropertyField(serializedObject.FindProperty("color"), true);
            if (!Application.isPlaying)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_FlipX"), true);
                EditorGUILayout.PropertyField(serializedObject.FindProperty("m_FlipY"), true);
            }
            EditorGUILayout.PropertyField(serializedObject.FindProperty("m_PreMultiplyAlpha"), true);

            if (!Application.isPlaying)
            {
                if (!armature.isUGUI)
                {
                                        #if UNITY_5_6_OR_NEWER
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("sortType"), true);
                                        #else
                    armature.sortType = Armature.SortType.ZSpace;
                                        #endif
                    EditorGUILayout.PropertyField(serializedObject.FindProperty("zSpace"), true);

                    if (sortType != armature.sortType)
                    {
                        sortType = armature.sortType;
                        armature.sortingOrder = armature.sortingOrder;
                    }
                }
            }
            if (armature.anims != null && armature.anims.Length > 0)
            {
                int temp = (int)armature.animIndex;
                System.Collections.Generic.List <string> animsList = new System.Collections.Generic.List <string>(armature.anims);
                animsList.Insert(0, "<None>");
                armature.animIndex = EditorGUILayout.Popup("Current Animation", temp + 1, animsList.ToArray()) - 1;
                if (armature.animIndex != temp && !Application.isPlaying)
                {
                    UnityEditor.EditorUtility.SetDirty(armature);
                    if (!Application.isPlaying && !string.IsNullOrEmpty(armature.gameObject.scene.name))
                    {
                        UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                    }
                }
            }
            EditorGUILayout.PropertyField(serializedObject.FindProperty("anims"), true);
            if (armature.skins != null && armature.skins.Length > 1)
            {
                int temp = armature.skinIndex;
                armature.skinIndex = EditorGUILayout.Popup("Skins", armature.skinIndex, armature.skins);
                if (temp != armature.skinIndex && !Application.isPlaying)
                {
                    UnityEditor.EditorUtility.SetDirty(armature);
                    if (!string.IsNullOrEmpty(armature.gameObject.scene.name))
                    {
                        UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                    }
                }
            }
            EditorGUILayout.PropertyField(serializedObject.FindProperty("slots"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("bones"), true);
            if (armature.isUGUI)
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("uiAttachments"), true);
            }
            else
            {
                EditorGUILayout.PropertyField(serializedObject.FindProperty("attachments"), true);
            }
            EditorGUILayout.PropertyField(serializedObject.FindProperty("sonArmatures"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("parentArmature"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("textureFrames"), true);
            EditorGUILayout.PropertyField(serializedObject.FindProperty("poseData"), true);
            serializedObject.ApplyModifiedProperties();

            if (!Application.isPlaying && armature.flipX != flipX)
            {
                armature.flipX = armature.flipX;
                flipX          = armature.flipX;
                if (!string.IsNullOrEmpty(armature.gameObject.scene.name))
                {
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                }
            }
            if (!Application.isPlaying && armature.flipY != flipY)
            {
                armature.flipY = armature.flipY;
                flipY          = armature.flipY;
                if (!string.IsNullOrEmpty(armature.gameObject.scene.name))
                {
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                }
            }
            if (!Application.isPlaying && armature.zSpace != zspace)
            {
                zspace = armature.zSpace;
                armature.ResetSlotZOrder();
                if (!string.IsNullOrEmpty(armature.gameObject.scene.name))
                {
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                }
            }

            if (armature.preMultiplyAlpha != preMultiplyAlpha)
            {
                preMultiplyAlpha          = armature.preMultiplyAlpha;
                armature.preMultiplyAlpha = preMultiplyAlpha;
                if (!Application.isPlaying && !string.IsNullOrEmpty(armature.gameObject.scene.name))
                {
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                }
            }
            if (!Application.isPlaying && !armature.isUGUI && armature.parentArmature == null)
            {
                ArmatureMesh am = armature.gameObject.GetComponent <ArmatureMesh>();
                if (!am)
                {
                    if (GUILayout.Button("Add Armature Mesh", GUILayout.Height(20)))
                    {
                        am = armature.gameObject.AddComponent <ArmatureMesh>();
                    }
                }
            }
            GUILayout.Space(5);
            if (GUILayout.Button("Set To Pose", GUILayout.Height(20)))
            {
                armature.SetToPose();
            }
        }