Exemple #1
0
        public virtual void ExecuteCommand(int commandIndex)
        {
            if (activeCommand == null)
            {
                previousActiveCommandIndex = -1;
            }
            else
            {
                previousActiveCommandIndex = activeCommand.commandIndex;
            }

            if (commandIndex >= commandList.Count)
            {
                Stop();
                return;
            }

            if (commandIndex == 0)
            {
                executionCount++;
            }

            FungusScript fungusScript = GetFungusScript();

            // Skip disabled commands, comments and labels
            while (commandIndex < commandList.Count &&
                   (!commandList[commandIndex].enabled ||
                    commandList[commandIndex].GetType() == typeof(Comment) ||
                    commandList[commandIndex].GetType() == typeof(Label)))
            {
                commandIndex = commandList[commandIndex].commandIndex + 1;
            }

            if (commandIndex >= commandList.Count)
            {
                Stop();
                return;
            }

            Command nextCommand = commandList[commandIndex];

            activeCommand      = null;
            executingIconTimer = 0.5f;

            if (nextCommand == null)
            {
                Stop();
            }
            else
            {
                if (fungusScript.gameObject.activeInHierarchy)
                {
                    // Auto select a command in some situations
                    if ((fungusScript.selectedCommands.Count == 0 && commandIndex == 0) ||
                        (fungusScript.selectedCommands.Count == 1 && fungusScript.selectedCommands[0].commandIndex == previousActiveCommandIndex))
                    {
                        fungusScript.ClearSelectedCommands();
                        fungusScript.AddSelectedCommand(nextCommand);
                    }

                    if (runSlowInEditor &&
                        nextCommand.RunSlowInEditor())
                    {
                        StartCoroutine(ExecuteAfterDelay(nextCommand, fungusScript.runSlowDuration));
                    }
                    else
                    {
                        activeCommand = nextCommand;
                        nextCommand.Execute();
                    }
                }
            }
        }