Browse Source

Fixed Command properties not copied when copying commands #546

master
Christopher 8 years ago
parent
commit
227e79c20b
  1. 21
      Assets/Fungus/Scripts/Editor/BlockEditor.cs

21
Assets/Fungus/Scripts/Editor/BlockEditor.cs

@ -906,12 +906,25 @@ namespace Fungus.EditorUtils
{ {
if (flowchart.SelectedCommands.Contains(command)) if (flowchart.SelectedCommands.Contains(command))
{ {
System.Type type = command.GetType(); var type = command.GetType();
Command newCommand = Undo.AddComponent(commandCopyBuffer.gameObject, type) as Command; Command newCommand = Undo.AddComponent(commandCopyBuffer.gameObject, type) as Command;
System.Reflection.FieldInfo[] fields = type.GetFields(); var fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);
foreach (System.Reflection.FieldInfo field in fields) foreach (var field in fields)
{ {
field.SetValue(newCommand, field.GetValue(command)); // Copy all public fields
bool copy = field.IsPublic;
// Copy non-public fields that have the SerializeField attribute
var attributes = field.GetCustomAttributes(typeof(SerializeField), true);
if (attributes.Length > 0)
{
copy = true;
}
if (copy)
{
field.SetValue(newCommand, field.GetValue(command));
}
} }
} }
} }

Loading…
Cancel
Save