public void Duplicate(int index) { Command command = _arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue as Command; // Add the command as a new component Sequence parentSequence = command.GetComponent <Sequence>(); Command newCommand = CommandEditor.PasteCommand(command, parentSequence); _arrayProperty.InsertArrayElementAtIndex(index); _arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue = newCommand; }
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(); }