示例#1
0
    public GameObject addCommand(Command newCommand)
    {
        panelHelp.SetActive(false);
        newCommand.resetRepetitionCounter();
        if(commandsDrawn.Count < maxCommands - newCommand.indentLevel && !startedSimulation) {
            int nestLevel = 0;
            ArrayList commandList = getProgramFromPanel();
            for(int index = 0; index < commandsDrawn.Count; index++) {
                Command command = (Command) commandList[index];
                if (command.indentLevel != 0)
                    nestLevel = nestLevel + command.indentLevel;
            }

            GameObject box = instantiateCommandBox(newCommand, commandsDrawn.Count, nestLevel);
            if(newCommand.indentLevel == -1) {
                GameObject scopedBox = (GameObject) scopedBeginning.Pop();
                FlowCommandBox scopedCommand = scopedBox.GetComponent<FlowCommandBox>();
                scopedCommand.setEndOfScopeAsChild(box.GetComponent<CommandBox>());
            } else if(scopedBeginning.Count > 0) {
                GameObject scopedBox = (GameObject) scopedBeginning.Peek();
                box.transform.SetParent(scopedBox.transform);
                box.transform.localScale = new Vector2(1, 1);
            }
            if(newCommand.indentLevel == 1)
                scopedBeginning.Push(box);

            commandsDrawn.Add(box);

            return box;
        }

        return null;
    }