Example #1
0
    public override void OnInspectorGUI()
    {
        //specify type
        SimpleAnimationsManager simpleAnimationsManager = target as SimpleAnimationsManager;

        if (simpleAnimationsManager == null)
        {
            return;
        }

        EditorGUILayout.BeginHorizontal();
        if (implementations != null)
        {
            EditorGUILayout.LabelField($"Found {implementations.Count()} implementations");
        }
        if (implementations == null || GUILayout.Button("Search implementations"))
        {
            //find all implementations of ISimpleAnimation using System.Reflection.Module
            implementations = GetImplementations <ISimpleAnimation>().Where(impl => !impl.IsSubclassOf(typeof(UnityEngine.Object))).ToArray();
        }
        EditorGUILayout.EndHorizontal();

        // Draw horizontal line
        EditorGUILayout.Space(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.Space();

        //select an implementation from all found using an editor popup
        selectedImplementationIndex = EditorGUILayout.Popup(new GUIContent("Implementation"),
                                                            selectedImplementationIndex, implementations.Select(impl => impl.FullName).ToArray());

        ISimpleAnimation newAnimation = null;

        if (GUILayout.Button("Create animation"))
        {
            //Create a new animation of the selected type
            newAnimation = (ISimpleAnimation)Activator.CreateInstance(implementations[selectedImplementationIndex]);
        }

        //If a new animation has been created...
        if (newAnimation != null)
        {
            //record the gameObject state to enable undo and prevent from exiting the scene without saving
            Undo.RegisterCompleteObjectUndo(target, "Added new animation");
            //add the new animation to the animation's list
            simpleAnimationsManager.animations.Add(newAnimation);
        }

        // Draw horizontal line
        EditorGUILayout.Space(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.Space();

        base.OnInspectorGUI();
    }
Example #2
0
        public override void OnInspectorGUI()
        {
            // Update the serializedProperty - always do this in the beginning of OnInspectorGUI.
            serializedObject.Update();



            //specify type
            simpleAnimationsManager = target as SimpleAnimationsManager;
            if (simpleAnimationsManager == null)
            {
                return;
            }

            //find all implementations of ISimpleAnimation using System.Reflection.Module
            if (implementations == null)
            {
                implementations = Utils.GetTypeImplementationsNotUnityObject <ISimpleAnimation>();
            }

            EditorGUILayout.Space();

            //select an implementation from all found using an editor popup
            selectedImplementationIndex = EditorGUILayout.Popup(new GUIContent("Animation type"),
                                                                selectedImplementationIndex, implementations.Select(impl => impl.Name).ToArray());

            ISimpleAnimation newAnimation = null;

            if (GUILayout.Button("Create animation"))
            {
                //Create a new animation of the selected type
                newAnimation = (ISimpleAnimation)Activator.CreateInstance(implementations[selectedImplementationIndex]);
            }

            //If a new animation has been created...
            if (newAnimation != null)
            {
                //record the gameObject state to enable undo and prevent from exiting the scene without saving
                Undo.RegisterCompleteObjectUndo(target, "Added new animation");
                //add the new animation to the animation's list
                if (simpleAnimationsManager.animations == null)
                {
                    simpleAnimationsManager.animations = new List <ISimpleAnimation>();
                }
                simpleAnimationsManager.animations.Add(newAnimation);
            }

            // Draw horizontal line
            EditorGUILayout.Space(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.Space();

            if (simpleAnimationsManager.animations != null)
            {
                for (int a = 0; a < simpleAnimationsManager.animations.Count; a++)
                {
                    if (simpleAnimationsManager.animations[a] == null)
                    {
                        EditorGUILayout.HelpBox("The animation with index " + a + " is null.\nRecommended to delete the array element by right clicking on it.", MessageType.Warning);
                    }

                    if (simpleAnimationsManager.animations.Count() != simpleAnimationsManager.animations.Distinct().Count())
                    {
                        for (int d = a + 1; d < simpleAnimationsManager.animations.Count; d++)
                        {
                            if (simpleAnimationsManager.animations[a] != null && (simpleAnimationsManager.animations[a] == simpleAnimationsManager.animations[d]))
                            {
                                EditorGUILayout.HelpBox("The animations with index " + a + " and " + d + " are the same object.", MessageType.Warning);
                            }
                        }
                    }
                }
            }

            EditorGUI.indentLevel += 1;
            EditorGUILayout.Space();
            GUILayout.Label("Animations Configuration", EditorStyles.boldLabel);
            ShowAnimationsArray(serializedObject.FindProperty("animations"));

            EditorGUI.indentLevel -= 1;

            // Draw horizontal line
            EditorGUILayout.Space(); EditorGUILayout.Space();
            EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);

            // Implementations search
            EditorGUILayout.BeginHorizontal();
            if (implementations != null)
            {
                EditorGUILayout.LabelField($"Found {implementations.Count()} implementations", EditorStyles.helpBox);
            }
            if (implementations == null || GUILayout.Button("Search implementations"))
            {
                //find all implementations of ISimpleAnimation using System.Reflection.Module
                implementations = Utils.GetTypeImplementationsNotUnityObject <ISimpleAnimation>();
            }
            EditorGUILayout.EndHorizontal();



            // Apply changes to the serializedProperty - always do this in the end of OnInspectorGUI.
            serializedObject.ApplyModifiedProperties();
        }
Example #3
0
    public override void OnInspectorGUI()
    {
        //specify type
        SimpleAnimationsManager simpleAnimationsManager = target as SimpleAnimationsManager;

        if (simpleAnimationsManager == null)
        {
            return;
        }

        EditorGUILayout.BeginHorizontal();
        if (implementations != null)
        {
            EditorGUILayout.LabelField($"Found {implementations.Count()} implementations");
        }
        if (implementations == null || GUILayout.Button("Search implementations"))
        {
            //find all implementations of ISimpleAnimation using System.Reflection.Module
            implementations = GetImplementations <ISimpleAnimation>().Where(impl => !impl.IsSubclassOf(typeof(UnityEngine.Object))).ToArray();
        }
        EditorGUILayout.EndHorizontal();

        // Draw horizontal line
        EditorGUILayout.Space(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.Space();

        //select an implementation from all found using an editor popup
        selectedImplementationIndex = EditorGUILayout.Popup(new GUIContent("Implementation"),
                                                            selectedImplementationIndex, implementations.Select(impl => impl.FullName).ToArray());

        ISimpleAnimation newAnimation = null;

        if (GUILayout.Button("Create animation"))
        {
            //Create a new animation of the selected type
            newAnimation = (ISimpleAnimation)Activator.CreateInstance(implementations[selectedImplementationIndex]);
        }

        //If a new animation has been created...
        if (newAnimation != null)
        {
            //record the gameObject state to enable undo and prevent from exiting the scene without saving
            Undo.RegisterCompleteObjectUndo(target, "Added new animation");
            //add the new animation to the animation's list
            if (simpleAnimationsManager.animations == null)
            {
                simpleAnimationsManager.animations = new List <ISimpleAnimation>();
            }
            simpleAnimationsManager.animations.Add(newAnimation);
        }

        // Draw horizontal line
        EditorGUILayout.Space(); EditorGUILayout.LabelField("", GUI.skin.horizontalSlider); EditorGUILayout.Space();

        if (simpleAnimationsManager.animations != null)
        {
            for (int a = 0; a < simpleAnimationsManager.animations.Count; a++)
            {
                if (simpleAnimationsManager.animations[a] == null)
                {
                    EditorGUILayout.HelpBox("The animation with index " + a + " is null.", MessageType.Warning);
                }

                if (simpleAnimationsManager.animations.Count() != simpleAnimationsManager.animations.Distinct().Count())
                {
                    for (int d = a + 1; d < simpleAnimationsManager.animations.Count; d++)
                    {
                        if (simpleAnimationsManager.animations[a] != null && (simpleAnimationsManager.animations[a] == simpleAnimationsManager.animations[d]))
                        {
                            EditorGUILayout.HelpBox("The animations with index " + a + " and " + d + " are the same object.", MessageType.Warning);
                        }
                    }
                }
            }
        }

        EditorGUI.indentLevel = 1;
        EditorGUILayout.Space();
        GUILayout.Label("Animations Configuration", EditorStyles.boldLabel);
        using (new GUILayout.VerticalScope(EditorStyles.helpBox))
        {
            base.OnInspectorGUI();
        }
    }