/// <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); } } }
// Prompt the user with a text field in the inspector to allow naming of their new state private void SetUserDefinedState(SerializedProperty stateName) { using (new EditorGUILayout.HorizontalScope()) { newStateName = EditorGUILayout.TextField("New State Name", newStateName); if (GUILayout.Button(setStateNameLabel)) { if (newStateName != string.Empty && !instance.IsStatePresentEditMode(newStateName) && newStateName != "New State Name") { stateName.stringValue = newStateName; serializedObject.ApplyModifiedProperties(); instance.SetEventConfigurationInstance(stateName.stringValue); } else { // Display dialog telling the user to change the state name entered EditorUtility.DisplayDialog("Change State Name", "The state name entered is empty or this state name is already taken, please add characters to the state name or choose another name.", "OK"); } } } }