|
|
@ -48,37 +48,37 @@ namespace Fungus |
|
|
|
ReorderableListGUI.Title("Command Sequence"); |
|
|
|
ReorderableListGUI.Title("Command Sequence"); |
|
|
|
SerializedProperty commandListProperty = serializedObject.FindProperty("commandList"); |
|
|
|
SerializedProperty commandListProperty = serializedObject.FindProperty("commandList"); |
|
|
|
CommandListAdaptor adaptor = new CommandListAdaptor(commandListProperty, 0); |
|
|
|
CommandListAdaptor adaptor = new CommandListAdaptor(commandListProperty, 0); |
|
|
|
ReorderableListControl.DrawControlFromState(adaptor, null, 0); |
|
|
|
ReorderableListControl.DrawControlFromState(adaptor, null, ReorderableListFlags.HideRemoveButtons); |
|
|
|
|
|
|
|
|
|
|
|
if (Application.isPlaying) |
|
|
|
if (!Application.isPlaying) |
|
|
|
{ |
|
|
|
{ |
|
|
|
serializedObject.ApplyModifiedProperties(); |
|
|
|
Rect copyMenuRect = GUILayoutUtility.GetLastRect(); |
|
|
|
return; |
|
|
|
copyMenuRect.y += copyMenuRect.height - 17; |
|
|
|
} |
|
|
|
copyMenuRect.width = 24; |
|
|
|
|
|
|
|
copyMenuRect.height = 18; |
|
|
|
EditorGUILayout.BeginHorizontal(); |
|
|
|
if (GUI.Button(copyMenuRect, "", new GUIStyle("DropDown"))) |
|
|
|
|
|
|
|
|
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fungusScript.copyCommand != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (GUILayout.Button("Paste")) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
fungusScript.selectedCommand = CommandEditor.PasteCommand(fungusScript.copyCommand, fungusScript.selectedSequence); |
|
|
|
ShowCopyMenu(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.EndHorizontal(); |
|
|
|
EditorGUILayout.BeginHorizontal(); |
|
|
|
|
|
|
|
|
|
|
|
if (fungusScript.selectedCommand != null) |
|
|
|
if (fungusScript.selectedCommand != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
CommandInfoAttribute infoAttr = CommandEditor.GetCommandInfo(fungusScript.selectedCommand.GetType()); |
|
|
|
CommandInfoAttribute infoAttr = CommandEditor.GetCommandInfo(fungusScript.selectedCommand.GetType()); |
|
|
|
if (infoAttr != null) |
|
|
|
if (infoAttr != null) |
|
|
|
{ |
|
|
|
{ |
|
|
|
EditorGUILayout.HelpBox(infoAttr.HelpText, MessageType.Info); |
|
|
|
EditorGUILayout.HelpBox(infoAttr.CommandName + ":\n" + infoAttr.HelpText, MessageType.Info, true); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Need to expand to fill space or else reorderable list width changes if no command is selected |
|
|
|
|
|
|
|
GUILayout.FlexibleSpace(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
EditorGUILayout.EndHorizontal(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
serializedObject.ApplyModifiedProperties(); |
|
|
|
serializedObject.ApplyModifiedProperties(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -168,6 +168,189 @@ namespace Fungus |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void ShowCopyMenu() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
bool showCut = false; |
|
|
|
|
|
|
|
bool showCopy = false; |
|
|
|
|
|
|
|
bool showDelete = false; |
|
|
|
|
|
|
|
bool showPaste = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sequence sequence = target as Sequence; |
|
|
|
|
|
|
|
foreach (Command command in sequence.commandList) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (command.selected) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
showCut = true; |
|
|
|
|
|
|
|
showCopy = true; |
|
|
|
|
|
|
|
showDelete = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommandCopyBuffer commandCopyBuffer = CommandCopyBuffer.GetInstance(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (commandCopyBuffer.HasCommands()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
showPaste = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GenericMenu commandMenu = new GenericMenu(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commandMenu.AddItem (new GUIContent ("Select All"), false, SelectAll); |
|
|
|
|
|
|
|
commandMenu.AddItem (new GUIContent ("Select None"), false, SelectNone); |
|
|
|
|
|
|
|
commandMenu.AddSeparator(""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (showCut) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
commandMenu.AddItem (new GUIContent ("Cut"), false, Cut); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
commandMenu.AddDisabledItem(new GUIContent ("Cut")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (showCopy) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
commandMenu.AddItem (new GUIContent ("Copy"), false, Copy); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
commandMenu.AddDisabledItem(new GUIContent ("Copy")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (showPaste) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
commandMenu.AddItem (new GUIContent ("Paste"), false, Paste); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
commandMenu.AddDisabledItem(new GUIContent ("Paste")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (showDelete) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
commandMenu.AddItem (new GUIContent ("Delete"), false, Delete); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
commandMenu.AddDisabledItem(new GUIContent ("Delete")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commandMenu.ShowAsContext(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void SelectAll() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Sequence sequence = target as Sequence; |
|
|
|
|
|
|
|
foreach (Command command in sequence.commandList) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Undo.RecordObject(command, "Select All"); |
|
|
|
|
|
|
|
command.selected = true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void SelectNone() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Sequence sequence = target as Sequence; |
|
|
|
|
|
|
|
FungusScript fungusScript = sequence.GetFungusScript(); |
|
|
|
|
|
|
|
if (fungusScript != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Undo.RecordObject(fungusScript, "Select None"); |
|
|
|
|
|
|
|
fungusScript.selectedCommand = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (Command command in sequence.commandList) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Undo.RecordObject(command, "Select None"); |
|
|
|
|
|
|
|
command.selected = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void Cut() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Copy(); |
|
|
|
|
|
|
|
Delete(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void Copy() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Sequence sequence = target as Sequence; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommandCopyBuffer commandCopyBuffer = CommandCopyBuffer.GetInstance(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commandCopyBuffer.Clear(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (Command command in sequence.commandList) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (command.selected) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
System.Type type = command.GetType(); |
|
|
|
|
|
|
|
Command newCommand = Undo.AddComponent(commandCopyBuffer.gameObject, type) as Command; |
|
|
|
|
|
|
|
System.Reflection.FieldInfo[] fields = type.GetFields(); |
|
|
|
|
|
|
|
foreach (System.Reflection.FieldInfo field in fields) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
field.SetValue(newCommand, field.GetValue(command)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
newCommand.selected = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void Paste() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
CommandCopyBuffer commandCopyBuffer = CommandCopyBuffer.GetInstance(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Sequence sequence = target as Sequence; |
|
|
|
|
|
|
|
FungusScript fungusScript = sequence.GetFungusScript(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Find where to paste commands in sequence (either at end or after selected command) |
|
|
|
|
|
|
|
int pasteIndex = sequence.commandList.Count; |
|
|
|
|
|
|
|
if (fungusScript.selectedCommand != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
for (int i = 0; i < sequence.commandList.Count; ++i) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Command command = sequence.commandList[i]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (fungusScript.selectedCommand == command) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
pasteIndex = i + 1; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (Command command in commandCopyBuffer.GetCommands()) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
System.Type type = command.GetType(); |
|
|
|
|
|
|
|
Command newCommand = Undo.AddComponent(sequence.gameObject, type) as Command; |
|
|
|
|
|
|
|
System.Reflection.FieldInfo[] fields = type.GetFields(); |
|
|
|
|
|
|
|
foreach (System.Reflection.FieldInfo field in fields) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
field.SetValue(newCommand, field.GetValue(command)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
newCommand.selected = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Undo.RecordObject(sequence, "Paste"); |
|
|
|
|
|
|
|
sequence.commandList.Insert(pasteIndex++, newCommand); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void Delete() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Sequence sequence = target as Sequence; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = sequence.commandList.Count - 1; i >= 0; --i) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Command command = sequence.commandList[i]; |
|
|
|
|
|
|
|
if (command != null && |
|
|
|
|
|
|
|
command.selected) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
Undo.DestroyObjectImmediate(command); |
|
|
|
|
|
|
|
Undo.RecordObject(sequence, "Delete"); |
|
|
|
|
|
|
|
sequence.commandList.RemoveAt(i); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |