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 Duplicate(int index) { Command command = _arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue as Command; // Add the command as a new component Sequence parentSequence = command.GetComponent <Sequence>(); System.Type type = command.GetType(); Command newCommand = Undo.AddComponent(parentSequence.gameObject, type) as Command; System.Reflection.FieldInfo[] fields = type.GetFields(); foreach (System.Reflection.FieldInfo field in fields) { field.SetValue(newCommand, field.GetValue(command)); } _arrayProperty.InsertArrayElementAtIndex(index); _arrayProperty.GetArrayElementAtIndex(index).objectReferenceValue = newCommand; }