Exemple #1
0
        protected void Paste()
        {
            Sequence     sequence     = target as Sequence;
            FungusScript fungusScript = sequence.GetFungusScript();

            if (fungusScript == null ||
                fungusScript.selectedSequence == null)
            {
                return;
            }

            CommandCopyBuffer commandCopyBuffer = CommandCopyBuffer.GetInstance();

            // Find where to paste commands in sequence (either at end or after last selected command)
            int pasteIndex = fungusScript.selectedSequence.commandList.Count;

            if (fungusScript.selectedCommands.Count > 0)
            {
                for (int i = 0; i < fungusScript.selectedSequence.commandList.Count; ++i)
                {
                    Command command = fungusScript.selectedSequence.commandList[i];

                    foreach (Command selectedCommand in fungusScript.selectedCommands)
                    {
                        if (command == selectedCommand)
                        {
                            pasteIndex = i + 1;
                        }
                    }
                }
            }

            foreach (Command command in commandCopyBuffer.GetCommands())
            {
                // Using the Editor copy / paste functionality instead instead of reflection
                // because this does a deep copy of the command properties.
                if (ComponentUtility.CopyComponent(command))
                {
                    if (ComponentUtility.PasteComponentAsNew(fungusScript.gameObject))
                    {
                        Command[] commands      = fungusScript.GetComponents <Command>();
                        Command   pastedCommand = commands.Last <Command>();
                        if (pastedCommand != null)
                        {
                            fungusScript.selectedSequence.commandList.Insert(pasteIndex++, pastedCommand);
                        }
                    }

                    // This stops the user pasting the command manually into another game object.
                    ComponentUtility.CopyComponent(fungusScript.transform);
                }
            }

            Repaint();
        }