public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Starting Entry"); NameIDListPair popupLists = SerializedConversationUtility.GetEntryNameAndID(serializedObject, true); startingID.intValue = EditorGUILayout.IntPopup(startingID.intValue, popupLists.Names.ToArray(), popupLists.IDs.ToArray()); EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(serializedObject.FindProperty("Speakers"), true); EditorGUILayout.Separator(); EditorGUILayout.LabelField("Dialogue Entries"); // popup to select start dialogue entrySelectedIndex = DialogueEntryPopup(entrySelectedIndex); // add/remove entries buttons EditorGUILayout.BeginHorizontal(); bool addEntry = false, removeEntry = false; addEntry = GUILayout.Button("Add Entry"); using (new EditorGUI.DisabledScope(entrySelectedIndex >= entries.arraySize)) //disable if index out of range { removeEntry = GUILayout.Button("Remove Entry"); } EditorGUILayout.EndHorizontal(); if (addEntry) { SerializedConversationUtility.AddEntry(serializedObject); } else if (removeEntry) { if (entrySelectedIndex < entries.arraySize) { entries.DeleteArrayElementAtIndex(entrySelectedIndex); entrySelectedIndex = Mathf.Clamp(entrySelectedIndex, 0, entries.arraySize - 1); } } // Show selected entry if (entries.arraySize != 0 && entrySelectedIndex < entries.arraySize) { selectedEntry = entries.GetArrayElementAtIndex(entrySelectedIndex); EditorGUILayout.PropertyField(selectedEntry, GUIContent.none, true); } else { EditorGUILayout.LabelField("No Entries"); } serializedObject.ApplyModifiedProperties(); }
public static NameIDListPair GetEntryNameAndID(SerializedObject serialConversation, bool prependID = false) { NameIDListPair listPair = new NameIDListPair(); listPair.Names = new List <string>(); listPair.IDs = new List <int>(); Conversation conversation = serialConversation.targetObject as Conversation; foreach (DialogueEntry entry in conversation.Entries) { listPair.Names.Add(entry.Name(prependID)); listPair.IDs.Add(entry.ID); } return(listPair); }
private void DrawEditPanel() { // Begins GUI layout area for edit panel editPanel = new Rect((position.width * nodePanelWidth) + 5, 0, position.width * (1 - nodePanelWidth) - (RESIZER_WIDTH * 0.5f), position.height); GUILayout.BeginArea(editPanel); // Begins a Scroll View area. This takes the current scroll position and returns the new position scrolled to editScrollPosition = GUILayout.BeginScrollView(editScrollPosition); // HACK display conversation selected some other way EditorGUILayout.ObjectField("Conversation", conversation, typeof(Conversation), false); if (conversation == null) { //todo maybe say something? } else { // Draws the property for the selected node // As with custom inspectors, the SerializedObject representing the Conversation needs to be updated and modified serializedConversation.Update(); SerializedProperty startingID = serializedConversation.FindProperty("startingID"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("Starting Entry"); NameIDListPair popupLists = SerializedConversationUtility.GetEntryNameAndID(serializedConversation, true); startingID.intValue = EditorGUILayout.IntPopup(startingID.intValue, popupLists.Names.ToArray(), popupLists.IDs.ToArray()); EditorGUILayout.EndHorizontal(); EditorGUILayout.PropertyField(serializedConversation.FindProperty("Speakers"), true); EditorGUILayout.Separator(); // Get the property from the serializedConversation corresponding to the selected node SerializedProperty selectedProperty = null; if (selectedNode != null) { selectedProperty = selectedNode.ContentsAsProperty(serializedConversation); } if (selectedProperty != null) { // Displays the selected property using the appropriate custom drawer EditorGUILayout.PropertyField(selectedProperty); } // End by applying any modifications to the SerializedObject serializedConversation.ApplyModifiedProperties(); } // Close ScrollView and Area GUILayout.EndScrollView(); GUILayout.EndArea(); }