diff --git a/Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs b/Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs index b1643b9f..6765c646 100644 --- a/Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs +++ b/Assets/Fungus/FungusScript/Editor/FungusCommandListAdaptor.cs @@ -49,18 +49,56 @@ namespace Fungus.Script } public void Add() { + FungusCommand newCommand = AddNewCommand(); + if (newCommand == null) + { + return; + } + int newIndex = _arrayProperty.arraySize; ++_arrayProperty.arraySize; - ResetValue(_arrayProperty.GetArrayElementAtIndex(newIndex)); + _arrayProperty.GetArrayElementAtIndex(newIndex).objectReferenceValue = newCommand; } public void Insert(int index) { + FungusCommand newCommand = AddNewCommand(); + if (newCommand == null) + { + return; + } + _arrayProperty.InsertArrayElementAtIndex(index); - ResetValue(_arrayProperty.GetArrayElementAtIndex(index)); + _arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue = newCommand; + } + + FungusCommand AddNewCommand() + { + FungusScript fungusScript = FungusScriptWindow.GetFungusScript(); + if (fungusScript == null || + fungusScript.selectedAddCommandType == null) + { + return null; + } + + Sequence sequence = fungusScript.selectedSequence; + if (sequence == null) + { + return null; + } + + return sequence.gameObject.AddComponent(fungusScript.selectedAddCommandType) as FungusCommand; } public void Duplicate(int index) { + + FungusCommand command = _arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue as FungusCommand; + + // Add the command as a new component + Sequence parentSequence = command.GetComponent(); + FungusCommand newCommand = FungusCommandEditor.PasteCommand(command, parentSequence); + _arrayProperty.InsertArrayElementAtIndex(index); + _arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue = newCommand; } public void Remove(int index) { @@ -130,15 +168,21 @@ namespace Fungus.Script buttonRect.y -= 2; buttonRect.height += 5; + GUI.Box(buttonRect, commandName, commandStyle); + Rect summaryRect = position; summaryRect.x += buttonWidth + 5; summaryRect.width -= (buttonWidth + 5); - if (GUI.Button(buttonRect, commandName, commandStyle) && !Application.isPlaying) + if (!Application.isPlaying && + Event.current.type == EventType.MouseDown && + Event.current.button == 0 && + position.Contains(Event.current.mousePosition)) { fungusScript.selectedCommand = command; GUIUtility.keyboardControl = 0; // Fix for textarea not refeshing (change focus) } + GUI.backgroundColor = Color.white; GUIStyle labelStyle = new GUIStyle(EditorStyles.miniLabel); diff --git a/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs b/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs index a679adac..a3e44720 100644 --- a/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs +++ b/Assets/Fungus/FungusScript/Editor/SequenceEditor.cs @@ -47,7 +47,7 @@ namespace Fungus.Script SerializedProperty commandListProperty = serializedObject.FindProperty("commandList"); FungusCommandListAdaptor adaptor = new FungusCommandListAdaptor(commandListProperty, 0); - ReorderableListControl.DrawControlFromState(adaptor, null, ReorderableListFlags.DisableDuplicateCommand | ReorderableListFlags.HideAddButton); + ReorderableListControl.DrawControlFromState(adaptor, null, 0); if (Application.isPlaying) { @@ -129,18 +129,12 @@ namespace Fungus.Script return; } + fungusScript.selectedAddCommandType = selectedType; + EditorGUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); - - if (GUILayout.Button(new GUIContent("Add Command", "Add the selected command to the sequence"))) - { - FungusCommand newCommand = Undo.AddComponent(fungusScript.selectedSequence.gameObject, selectedType) as FungusCommand; - Undo.RecordObject(fungusScript, "Add Command"); - fungusScript.selectedSequence.commandList.Add(newCommand); - fungusScript.selectedCommand = newCommand; - } - + if (fungusScript.copyCommand != null) { if (GUILayout.Button("Paste")) diff --git a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs index ab827202..75b3f95f 100644 --- a/Assets/Fungus/FungusScript/Scripts/FungusScript.cs +++ b/Assets/Fungus/FungusScript/Scripts/FungusScript.cs @@ -18,6 +18,9 @@ namespace Fungus.Script [HideInInspector] public int selectedAddCommandIndex; + [HideInInspector] + public System.Type selectedAddCommandType; + [HideInInspector] public int selectedCommandCategoryIndex; diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index f600f545..71783e35 100644 Binary files a/Assets/Shuttle/ShuttleGame.unity and b/Assets/Shuttle/ShuttleGame.unity differ