コード例 #1
0
        Command AddNewCommand()
        {
            Flowchart flowchart = FlowchartWindow.GetFlowchart();

            if (flowchart == null)
            {
                return(null);
            }

            var block = flowchart.SelectedBlock;

            if (block == null)
            {
                return(null);
            }

            var newCommand = Undo.AddComponent <Comment>(block.gameObject) as Command;

            newCommand.ItemId = flowchart.NextItemId();
            flowchart.ClearSelectedCommands();
            flowchart.AddSelectedCommand(newCommand);

            return(newCommand);
        }
コード例 #2
0
            internal Block PasteBlock(Flowchart flowchart)
            {
                var newBlock = FlowchartWindow.CreateBlock(flowchart, Vector2.zero);

                // Copy all command serialized properties
                // Copy references to match duplication behavior
                foreach (var command in commands)
                {
                    var newCommand = Undo.AddComponent(flowchart.gameObject, command.type) as Command;
                    CopyProperties(command.serializedObject, newCommand);
                    newCommand.ItemId = flowchart.NextItemId();
                    newBlock.CommandList.Add(newCommand);
                }

                // Copy event handler
                if (eventHandler != null)
                {
                    var newEventHandler = Undo.AddComponent(flowchart.gameObject, eventHandler.type) as EventHandler;
                    CopyProperties(eventHandler.serializedObject, newEventHandler);
                    newEventHandler.ParentBlock = newBlock;
                    newBlock._EventHandler = newEventHandler;     
                }

                // Copy block properties, but do not copy references because those were just assigned
                CopyProperties(
                    block,
                    newBlock,
                    SerializedPropertyType.ObjectReference,
                    SerializedPropertyType.Generic,
                    SerializedPropertyType.ArraySize
                );

                newBlock.BlockName = flowchart.GetUniqueBlockKey(block.FindProperty("blockName").stringValue + " (Copy)");

                return newBlock;
            }