/// <summary>
        /// Draw a custom editor for AnimatorControllerActions to make them easier to edit
        /// </summary>
        protected override void DrawCustomFooter()
        {
            CompoundButtonAnim acb      = (CompoundButtonAnim)target;
            Animator           animator = acb.TargetAnimator;

            AnimatorControllerParameter[] animParams = null;

            // Validate the AnimButton controls - make sure there's one control for each button state
            ButtonStateEnum[] buttonStates = (ButtonStateEnum[])System.Enum.GetValues(typeof(ButtonStateEnum));
            if (acb.AnimActions == null || acb.AnimActions.Length != buttonStates.Length)
            {
                acb.AnimActions = new AnimatorControllerAction[buttonStates.Length];
            }

            // Don't allow user to change setup during play mode
            if (!Application.isPlaying && !string.IsNullOrEmpty(acb.gameObject.scene.name))
            {
                // Get the available animation parameters
                animParams = animator.parameters;

                for (int i = 0; i < buttonStates.Length; i++)
                {
                    acb.AnimActions[i].ButtonState = buttonStates[i];
                }

                // Now make sure all animation parameters are found
                for (int i = 0; i < acb.AnimActions.Length; i++)
                {
                    if (!string.IsNullOrEmpty(acb.AnimActions[i].ParamName))
                    {
                        bool invalidParam = true;
                        foreach (AnimatorControllerParameter animParam in animParams)
                        {
                            if (acb.AnimActions[i].ParamName == animParam.name)
                            {
                                // Update the type while we're here
                                invalidParam = false;
                                acb.AnimActions[i].ParamType = animParam.type;
                                break;
                            }
                        }

                        // If we didn't find it, mark it as invalid
                        acb.AnimActions[i].InvalidParam = invalidParam;
                    }
                }
            }

            UnityEditor.EditorGUILayout.BeginVertical(UnityEditor.EditorStyles.helpBox);
            UnityEditor.EditorGUILayout.LabelField("Animation states:", UnityEditor.EditorStyles.miniBoldLabel);

            // Draw the editor for all the animation actions
            for (int i = 0; i < acb.AnimActions.Length; i++)
            {
                acb.AnimActions[i] = DrawAnimActionEditor(acb.AnimActions[i], animParams);
            }

            UnityEditor.EditorGUILayout.EndVertical();
        }
Exemplo n.º 2
0
        public override void OnInspectorGUI()
        {
            DrawDefaultInspector();

            CompoundButtonAnim acb = (CompoundButtonAnim)target;

            acb.TargetAnimator = HUXEditorUtils.DropDownComponentField <Animator>("Target animator", acb.TargetAnimator, acb.transform);

            if (acb.TargetAnimator == null)
            {
                GUI.color = HUXEditorUtils.ErrorColor;
                EditorGUILayout.LabelField("You must chooes a target animator.");
                HUXEditorUtils.SaveChanges(target);
                return;
            }

            Animator animator = acb.TargetAnimator;

            AnimatorControllerParameter[] animParams = null;

            if (!animator.isInitialized)
            {
                HUXEditorUtils.SaveChanges(target);
                return;
            }

            // Validate the AnimButton controls - make sure there's one control for each button state
            Button.ButtonStateEnum[] buttonStates = (Button.ButtonStateEnum[])System.Enum.GetValues(typeof(Button.ButtonStateEnum));
            if (acb.AnimActions == null || acb.AnimActions.Length != buttonStates.Length)
            {
                acb.AnimActions = new CompoundButtonAnim.AnimatorControllerAction[buttonStates.Length];
            }

            // Don't allow user to change setup during play mode
            if (!Application.isPlaying)
            {
                // Get the available animation parameters
                animParams = animator.parameters;

                for (int i = 0; i < buttonStates.Length; i++)
                {
                    acb.AnimActions[i].ButtonState = buttonStates[i];
                }

                // Now make sure all animation parameters are found
                for (int i = 0; i < acb.AnimActions.Length; i++)
                {
                    if (!string.IsNullOrEmpty(acb.AnimActions[i].ParamName))
                    {
                        bool invalidParam = true;
                        foreach (AnimatorControllerParameter animParam in animParams)
                        {
                            if (acb.AnimActions[i].ParamName == animParam.name)
                            {
                                // Update the type while we're here
                                invalidParam = false;
                                acb.AnimActions[i].ParamType = animParam.type;
                                break;
                            }
                        }

                        // If we didn't find it, mark it as invalid
                        acb.AnimActions[i].InvalidParam = invalidParam;
                    }
                }
            }

            if (!acb.gameObject.activeInHierarchy)
            {
                //GUI.color = HUX.Editor.EditorStyles.ColorWarning;
                EditorGUILayout.LabelField("(Gameobject must be active to view animation actions)");
                HUXEditorUtils.SaveChanges(target);
                return;
            }

            // Draw the editor for all the anim actions
            HUXEditorUtils.BeginSectionBox("Animation actions");
            for (int i = 0; i < acb.AnimActions.Length; i++)
            {
                acb.AnimActions[i] = DrawAnimActionEditor(acb.AnimActions[i], animParams);
            }
            HUXEditorUtils.EndSectionBox();

            HUXEditorUtils.SaveChanges(target);
        }