/// <summary>
        /// Display the state selection menu.
        /// </summary>
        public void DisplayMenu(BaseInteractiveElement instance)
        {
            if (GUILayout.Button(SelectStateButtonLabel))
            {
                GenericMenu menu = new GenericMenu();

                CreateStateSelectionMenu(instance, menu);

                menu.ShowAsContext();
            }
        }
        protected virtual void OnEnable()
        {
            instance = (BaseInteractiveElement)target;

            active = serializedObject.FindProperty("active");
            states = serializedObject.FindProperty("states");

            RemoveStateButtonLabel = new GUIContent(InspectorUIUtility.Minus, removeStateLabel);

            previousActiveStatus = active.boolValue;

            stateSelectionMenu = ScriptableObject.CreateInstance <StateSelectionMenu>();

            isCompressableButton = instance.GetType() == typeof(CompressableButton);
        }
Ejemplo n.º 3
0
        void Start()
        {
            interactiveElement = GetComponent <InteractiveElement>();

            if (interactiveElement != null)
            {
                keyboardState = interactiveElement.GetState("Keyboard");

                if (keyboardState != null)
                {
                    KeyboardEvents keyboardEvents = interactiveElement.GetStateEvents <KeyboardEvents>("Keyboard");

                    // Add listener to the new custom state
                    keyboardEvents.OnKKeyPressed.AddListener(() =>
                    {
                        Debug.Log("K Key has been pressed");
                    });
                }
            }
        }
        /// <summary>
        /// Add state menu items and sort them by interaction type (Near, Far, Both).
        /// </summary>
        public void CreateStateSelectionMenu(BaseInteractiveElement instance, GenericMenu statesMenu)
        {
            List <string> coreInteractionStateNames = Enum.GetNames(typeof(CoreInteractionState)).ToList();

            // If the state is already being tracked then do not display the state name as an option to add
            foreach (string coreState in coreInteractionStateNames.ToList())
            {
                if (instance.IsStatePresentEditMode(coreState))
                {
                    coreInteractionStateNames.Remove(coreState);
                }
            }

            // Sort the states in the menu based on name
            foreach (var stateName in coreInteractionStateNames)
            {
                // Add special case for touch because it is a near interaction state that does not contain "Near" in the name
                if (stateName.Contains(Near) || stateName == touchStateName)
                {
                    // Near Interaction States
                    AddStateToMenu(statesMenu, Near + "/" + stateName, stateName);
                }
                else if (stateName.Contains(Far))
                {
                    // Far Interaction States
                    AddStateToMenu(statesMenu, Far + "/" + stateName, stateName);
                }
                else if (stateName == focusStateName)
                {
                    // Focus is a special case state because it supports both near and far interaction
                    AddStateToMenu(statesMenu, NearAndFar + "/" + stateName, stateName);
                }
                else
                {
                    AddStateToMenu(statesMenu, Other + "/" + stateName, stateName);
                }
            }
        }
        private void RenderStateContainers()
        {
            InspectorUIUtility.DrawTitle("State Animations");

            for (int i = 0; i < stateContainers.arraySize; i++)
            {
                SerializedProperty stateContainer              = stateContainers.GetArrayElementAtIndex(i);
                SerializedProperty stateContainerName          = stateContainer.FindPropertyRelative("stateName");
                SerializedProperty animationTargetsList        = stateContainer.FindPropertyRelative("animationTargets");
                SerializedProperty stateContainerAnimationClip = stateContainer.FindPropertyRelative("animationClip");
                SerializedProperty animationTransitionDuration = stateContainer.FindPropertyRelative("animationTransitionDuration");

                Color previousGUIColor = GUI.color;

                using (new EditorGUILayout.HorizontalScope())
                {
                    string stateFoldoutID = stateContainerName.stringValue + "StateContainer" + "_" + target.name;

                    if (inPlayMode)
                    {
                        BaseInteractiveElement baseInteractiveElement = interactiveElement.objectReferenceValue as BaseInteractiveElement;

                        if (baseInteractiveElement.isActiveAndEnabled)
                        {
                            if (baseInteractiveElement.IsStateActive(stateContainerName.stringValue))
                            {
                                GUI.color = Color.cyan;
                            }
                        }
                    }

                    using (new EditorGUILayout.VerticalScope(EditorStyles.helpBox))
                    {
                        EditorGUILayout.Space();

                        if (InspectorUIUtility.DrawSectionFoldoutWithKey(stateContainerName.stringValue, stateFoldoutID, MixedRealityStylesUtility.TitleFoldoutStyle, false))
                        {
                            using (new EditorGUI.IndentLevelScope())
                            {
                                using (var check = new EditorGUI.ChangeCheckScope())
                                {
                                    EditorGUILayout.PropertyField(stateContainerAnimationClip);
                                    EditorGUILayout.PropertyField(animationTransitionDuration);

                                    if (check.changed)
                                    {
                                        instance.SetAnimationTransitionDuration(stateContainerName.stringValue, animationTransitionDuration.floatValue);
                                        instance.SetAnimationClip(stateContainerName.stringValue, stateContainerAnimationClip.objectReferenceValue as AnimationClip);
                                    }
                                }

                                RenderAnimationTargetList(animationTargetsList, stateContainerName);
                            }
                        }

                        EditorGUILayout.Space();
                    }

                    GUI.color = previousGUIColor;

                    if (!inPlayMode)
                    {
                        if (InspectorUIUtility.SmallButton(RemoveButtonLabel))
                        {
                            instance.RemoveAnimatorState(instance.RootStateMachine, stateContainerName.stringValue);
                            stateContainers.DeleteArrayElementAtIndex(i);
                            break;
                        }
                    }
                }
            }
        }