public virtual void DrawBlockGUI(Flowchart flowchart) { serializedObject.Update(); // Execute any queued cut, copy, paste, etc. operations from the prevous GUI update // We need to defer applying these operations until the following update because // the ReorderableList control emits GUI errors if you clear the list in the same frame // as drawing the control (e.g. select all and then delete) if (Event.current.type == EventType.Layout) { foreach (Action action in actionList) { if (action != null) { action(); } } actionList.Clear(); } Block block = target as Block; SerializedProperty commandListProperty = serializedObject.FindProperty("commandList"); if (block == flowchart.selectedBlock) { SerializedProperty descriptionProp = serializedObject.FindProperty("description"); EditorGUILayout.PropertyField(descriptionProp); DrawEventHandlerGUI(flowchart); UpdateIndentLevels(block); // Make sure each command has a reference to its parent block foreach (Command command in block.commandList) { if (command == null) // Will be deleted from the list later on { continue; } command.parentBlock = block; } ReorderableListGUI.Title("Commands"); CommandListAdaptor adaptor = new CommandListAdaptor(commandListProperty, 0); adaptor.nodeRect = block.nodeRect; ReorderableListFlags flags = ReorderableListFlags.HideAddButton | ReorderableListFlags.HideRemoveButtons | ReorderableListFlags.DisableContextMenu; if (block.commandList.Count == 0) { EditorGUILayout.HelpBox("Press the + button below to add a command to the list.", MessageType.Info); } else { ReorderableListControl.DrawControlFromState(adaptor, null, flags); } // EventType.contextClick doesn't register since we moved the Block Editor to be inside // a GUI Area, no idea why. As a workaround we just check for right click instead. if (Event.current.type == EventType.mouseUp && Event.current.button == 1) { ShowContextMenu(); Event.current.Use(); } if (GUIUtility.keyboardControl == 0) //Only call keyboard shortcuts when not typing in a text field { Event e = Event.current; // Copy keyboard shortcut if (e.type == EventType.ValidateCommand && e.commandName == "Copy") { if (flowchart.selectedCommands.Count > 0) { e.Use(); } } if (e.type == EventType.ExecuteCommand && e.commandName == "Copy") { actionList.Add(Copy); e.Use(); } // Cut keyboard shortcut if (e.type == EventType.ValidateCommand && e.commandName == "Cut") { if (flowchart.selectedCommands.Count > 0) { e.Use(); } } if (e.type == EventType.ExecuteCommand && e.commandName == "Cut") { actionList.Add(Cut); e.Use(); } // Paste keyboard shortcut if (e.type == EventType.ValidateCommand && e.commandName == "Paste") { CommandCopyBuffer commandCopyBuffer = CommandCopyBuffer.GetInstance(); if (commandCopyBuffer.HasCommands()) { e.Use(); } } if (e.type == EventType.ExecuteCommand && e.commandName == "Paste") { actionList.Add(Paste); e.Use(); } // Duplicate keyboard shortcut if (e.type == EventType.ValidateCommand && e.commandName == "Duplicate") { if (flowchart.selectedCommands.Count > 0) { e.Use(); } } if (e.type == EventType.ExecuteCommand && e.commandName == "Duplicate") { actionList.Add(Copy); actionList.Add(Paste); e.Use(); } // Delete keyboard shortcut if (e.type == EventType.ValidateCommand && e.commandName == "Delete") { if (flowchart.selectedCommands.Count > 0) { e.Use(); } } if (e.type == EventType.ExecuteCommand && e.commandName == "Delete") { actionList.Add(Delete); e.Use(); } // SelectAll keyboard shortcut if (e.type == EventType.ValidateCommand && e.commandName == "SelectAll") { e.Use(); } if (e.type == EventType.ExecuteCommand && e.commandName == "SelectAll") { actionList.Add(SelectAll); e.Use(); } } } // Remove any null entries in the command list. // This can happen when a command class is deleted or renamed. for (int i = commandListProperty.arraySize - 1; i >= 0; --i) { SerializedProperty commandProperty = commandListProperty.GetArrayElementAtIndex(i); if (commandProperty.objectReferenceValue == null) { commandListProperty.DeleteArrayElementAtIndex(i); } } serializedObject.ApplyModifiedProperties(); }
public virtual void DrawSequenceGUI(FungusScript fungusScript) { serializedObject.Update(); Sequence sequence = target as Sequence; SerializedProperty descriptionProp = serializedObject.FindProperty("description"); EditorGUILayout.PropertyField(descriptionProp); SerializedProperty runSlowInEditorProp = serializedObject.FindProperty("runSlowInEditor"); EditorGUILayout.PropertyField(runSlowInEditorProp); DrawEventHandlerGUI(fungusScript); UpdateIndentLevels(sequence); SerializedProperty sequenceNameProperty = serializedObject.FindProperty("sequenceName"); Rect sequenceLabelRect = new Rect(45, 5, 120, 16); EditorGUI.LabelField(sequenceLabelRect, new GUIContent("Sequence Name")); Rect sequenceNameRect = new Rect(45, 21, 180, 16); EditorGUI.PropertyField(sequenceNameRect, sequenceNameProperty, new GUIContent("")); // Ensure sequence name is unique for this Fungus Script string uniqueName = fungusScript.GetUniqueSequenceKey(sequenceNameProperty.stringValue, sequence); if (uniqueName != sequence.sequenceName) { sequenceNameProperty.stringValue = uniqueName; } // Make sure each command has a reference to its parent sequence foreach (Command command in sequence.commandList) { if (command == null) // Will be deleted from the list later on { continue; } command.parentSequence = sequence; } SerializedProperty commandListProperty = serializedObject.FindProperty("commandList"); ReorderableListGUI.Title("Commands"); CommandListAdaptor adaptor = new CommandListAdaptor(commandListProperty, 0); adaptor.nodeRect = sequence.nodeRect; ReorderableListFlags flags = ReorderableListFlags.HideAddButton | ReorderableListFlags.HideRemoveButtons | ReorderableListFlags.DisableContextMenu; ReorderableListControl.DrawControlFromState(adaptor, null, flags); if (Event.current.type == EventType.ContextClick) { ShowContextMenu(); } if (sequence == fungusScript.selectedSequence) { // Show add command button { GUILayout.BeginHorizontal(); // Up Button Texture2D upIcon = Resources.Load("Icons/up") as Texture2D; if (GUILayout.Button(upIcon)) { SelectPrevious(); } // Down Button Texture2D downIcon = Resources.Load("Icons/down") as Texture2D; if (GUILayout.Button(downIcon)) { SelectNext(); } GUILayout.FlexibleSpace(); // Add Button Texture2D addIcon = Resources.Load("Icons/add") as Texture2D; if (GUILayout.Button(addIcon) || ((Event.current.type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.A))) { ShowCommandMenu(); } // Duplicate Button Texture2D duplicateIcon = Resources.Load("Icons/duplicate") as Texture2D; if (GUILayout.Button(duplicateIcon)) { Copy(); Paste(); } // Delete Button Texture2D deleteIcon = Resources.Load("Icons/delete") as Texture2D; if (GUILayout.Button(deleteIcon) || ((Event.current.type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Delete))) { Delete(); } GUILayout.EndHorizontal(); } } // Remove any null entries in the command list. // This can happen when a command class is deleted or renamed. for (int i = commandListProperty.arraySize - 1; i >= 0; --i) { SerializedProperty commandProperty = commandListProperty.GetArrayElementAtIndex(i); if (commandProperty.objectReferenceValue == null) { commandListProperty.DeleteArrayElementAtIndex(i); } } serializedObject.ApplyModifiedProperties(); }
public void DrawSequenceGUI(FungusScript fungusScript) { if (fungusScript.selectedSequence == null) { return; } serializedObject.Update(); Sequence sequence = fungusScript.selectedSequence; EditorGUI.BeginChangeCheck(); string sequenceName = EditorGUILayout.TextField(new GUIContent("Name", "Name of sequence object"), sequence.gameObject.name); if (EditorGUI.EndChangeCheck()) { Undo.RecordObject(sequence.gameObject, "Set Sequence Name"); sequence.gameObject.name = sequenceName; } EditorGUILayout.PropertyField(descriptionProp); EditorGUILayout.Separator(); UpdateIndentLevels(sequence); ReorderableListGUI.Title("Command Sequence"); SerializedProperty commandListProperty = serializedObject.FindProperty("commandList"); CommandListAdaptor adaptor = new CommandListAdaptor(commandListProperty, 0); ReorderableListControl.DrawControlFromState(adaptor, null, 0); if (Application.isPlaying) { serializedObject.ApplyModifiedProperties(); return; } EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (fungusScript.copyCommand != null) { if (GUILayout.Button("Paste")) { fungusScript.selectedCommand = CommandEditor.PasteCommand(fungusScript.copyCommand, fungusScript.selectedSequence); } } EditorGUILayout.EndHorizontal(); if (fungusScript.selectedCommand != null) { CommandInfoAttribute infoAttr = CommandEditor.GetCommandInfo(fungusScript.selectedCommand.GetType()); if (infoAttr != null) { EditorGUILayout.HelpBox(infoAttr.HelpText, MessageType.Info); } } serializedObject.ApplyModifiedProperties(); }