コード例 #1
0
        private void InitializeIfNeeded()
        {
            if (controller != null)
            {
                return;
            }

            if (eventNameStyle == null)
            {
                eventNameStyle          = GUI.skin.label;
                eventNameStyle.richText = true;
            }

            Animator ignore;

            ScrubAnimatorUtil.GetCurrentAnimatorAndController(out controller, out ignore);

            UpdateMatchingAnimatorEventList();

            CreateReorderableList("On State Enter Transition Start", 20, ref list_onStateEnterTransitionStart, serializedObject.FindProperty("onStateEnterTransitionStart"),
                                  (rect, index, isActive, isFocused) => {
                DrawCallbackField(rect, serializedObject.FindProperty("onStateEnterTransitionStart").GetArrayElementAtIndex(index));
            });
            CreateReorderableList("On State Enter Transition End", 20, ref list_onStateEnterTransitionEnd, serializedObject.FindProperty("onStateEnterTransitionEnd"),
                                  (rect, index, isActive, isFocused) => {
                DrawCallbackField(rect, serializedObject.FindProperty("onStateEnterTransitionEnd").GetArrayElementAtIndex(index));
            });
            CreateReorderableList("On State Exit Transition Start", 20, ref list_onStateExitTransitionStart, serializedObject.FindProperty("onStateExitTransitionStart"),
                                  (rect, index, isActive, isFocused) => {
                DrawCallbackField(rect, serializedObject.FindProperty("onStateExitTransitionStart").GetArrayElementAtIndex(index));
            });
            CreateReorderableList("On State Exit Transition End", 20, ref list_onStateExitTransitionEnd, serializedObject.FindProperty("onStateExitTransitionEnd"),
                                  (rect, index, isActive, isFocused) => {
                DrawCallbackField(rect, serializedObject.FindProperty("onStateExitTransitionEnd").GetArrayElementAtIndex(index));
            });
            CreateReorderableList("On State Update", 20, ref list_onStateUpdated, serializedObject.FindProperty("onStateUpdated"),
                                  (rect, index, isActive, isFocused) => {
                DrawCallbackField(rect, serializedObject.FindProperty("onStateUpdated").GetArrayElementAtIndex(index));
            });
            CreateReorderableList("On Normalized Time Reached", 60, ref list_onNormalizedTimeReached, serializedObject.FindProperty("onNormalizedTimeReached"),
                                  (rect, index, isActive, isFocused) => {
                var property = serializedObject.FindProperty("onNormalizedTimeReached").GetArrayElementAtIndex(index);

                DrawCallbackField(rect, property);

                rect.y += 20;

                ScrubAnimatorUtil.DrawScrub(rect,
                                            (StateMachineBehaviour)target,
                                            property.FindPropertyRelative("normalizedTime"),
                                            property.FindPropertyRelative("repeat"),
                                            property.FindPropertyRelative("atLeastOnce"),
                                            property.FindPropertyRelative("neverWhileExit"));
            });
        }
コード例 #2
0
        public override void OnInspectorGUI()
        {
            //serializedObject.ShowScriptInput();
            serializedObject.Update();

            var when      = serializedObject.FindProperty("when");
            var what      = serializedObject.FindProperty("what");
            var paramName = serializedObject.FindProperty("paramName");

            if (null == animatorController)
            {
                Animator ignore;
                ScrubAnimatorUtil.GetCurrentAnimatorAndController(out animatorController, out ignore);
            }
            var parameters = animatorController.parameters;

            var  currentParamName = paramName.stringValue;
            bool paramFound       = false;

            GenericMenu menu = new GenericMenu();

            foreach (AnimatorControllerParameter elem in parameters)
            {
                menu.AddItem(new GUIContent(elem.name), false, OnParameterSelected, elem);
                if (elem.name == currentParamName)
                {
                    paramFound = true;
                }
            }

            EditorGUILayout.PropertyField(when);

            GUILayout.BeginHorizontal();
            var previousColor = GUI.color;

            if (!paramFound)
            {
                GUI.color = Color.red;
            }
            EditorGUILayout.PropertyField(paramName);
            GUI.color = previousColor;
            if (EditorGUILayout.DropdownButton(GUIContent.none, FocusType.Keyboard, GUILayout.Width(16)))
            {
                menu.ShowAsContext();
            }
            GUILayout.EndHorizontal();

            foreach (var elem in parameters)
            {
                if (elem.name == paramName.stringValue)
                {
                    what.intValue = (int)elem.type;

                    if (when.intValue == (int)SetParamSMB.When.WhileUpdating)
                    {
                        EditorGUILayout.PropertyField(serializedObject.FindProperty("curve"));
                        EditorGUILayout.PropertyField(serializedObject.FindProperty("repeat"));

                        switch ((AnimatorControllerParameterType)what.intValue)
                        {
                        case AnimatorControllerParameterType.Bool:
                        case AnimatorControllerParameterType.Trigger:
                            EditorGUILayout.HelpBox("True if the value is greater than 0", MessageType.Info);
                            break;

                        case AnimatorControllerParameterType.Int:
                            EditorGUILayout.HelpBox("Rounded to the nearest integer", MessageType.Info);
                            break;
                        }
                    }
                    else
                    {
                        switch ((AnimatorControllerParameterType)what.intValue)
                        {
                        case AnimatorControllerParameterType.Bool:
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("wantedBool"));
                            break;

                        case AnimatorControllerParameterType.Trigger:
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("wantedBool"));
                            break;

                        case AnimatorControllerParameterType.Int:
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("wantedInt"));
                            break;

                        case AnimatorControllerParameterType.Float:
                            EditorGUILayout.PropertyField(serializedObject.FindProperty("wantedFloat"));
                            break;
                        }
                    }

                    break;
                }
            }

            if (when.intValue == (int)SetParamSMB.When.OnNormalizedTimeReached)
            {
                ScrubAnimatorUtil.DrawScrub(GUILayoutUtility.GetRect(0, 0, 40, 0),
                                            (StateMachineBehaviour)target,
                                            serializedObject.FindProperty("normalizedTime"),
                                            serializedObject.FindProperty("repeat"),
                                            serializedObject.FindProperty("atLeastOnce"),
                                            serializedObject.FindProperty("neverWhileExit"));
            }

            serializedObject.ApplyModifiedProperties();
        }