Execute() public method

A coroutine method that executes all commands in the Block. Only one running instance of each Block is permitted.
public Execute ( int commandIndex, System.Action onComplete = null ) : IEnumerator
commandIndex int Index of command to start execution at
onComplete System.Action Delegate function to call when execution completes
return IEnumerator
コード例 #1
0
        protected virtual IEnumerator WaitForTimeout(float timeoutDuration, Block targetBlock)
        {
            float elapsedTime = 0;

            Slider timeoutSlider = GetComponentInChildren <Slider>();

            while (elapsedTime < timeoutDuration)
            {
                if (timeoutSlider != null)
                {
                    float t = 1f - elapsedTime / timeoutDuration;
                    timeoutSlider.value = t;
                }

                elapsedTime += Time.deltaTime;

                yield return(null);
            }

            Clear();
            gameObject.SetActive(false);

            HideSayDialog();

            if (targetBlock != null)
            {
                targetBlock.Execute();
            }
        }
コード例 #2
0
        /// <summary>
        /// Execute a child block in the flowchart.
        /// The block must be in an idle state to be executed.
        /// This version provides extra options to control how the block is executed.
        /// Returns true if the Block started execution.
        /// </summary>
        public virtual bool ExecuteBlock(Block block, int commandIndex = 0, Action onComplete = null)
        {
            if (block == null)
            {
                Debug.LogError("Block must not be null");
                return(false);
            }

            if (((Block)block).gameObject != gameObject)
            {
                Debug.LogError("Block must belong to the same gameobject as this Flowchart");
                return(false);
            }

            // Can't restart a running block, have to wait until it's idle again
            if (block.IsExecuting())
            {
                Debug.LogWarning(block.BlockName + " cannot be called/executed, it is already running.");
                return(false);
            }

            // Start executing the Block as a new coroutine
            StartCoroutine(block.Execute(commandIndex, onComplete));

            return(true);
        }
コード例 #3
0
ファイル: Call.cs プロジェクト: Johny91/Sword-of-Damocles
        public override void OnEnter()
        {
            Flowchart flowchart = GetFlowchart();

            if (targetBlock != null)
            {
                // Check if calling your own parent block
                if (targetBlock == parentBlock)
                {
                    // Just ignore the callmode in this case, and jump to first command in list
                    Continue(0);
                    return;
                }

                // Callback action for Wait Until Finished mode
                Action onComplete = null;
                if (callMode == CallMode.WaitUntilFinished)
                {
                    onComplete = delegate {
                        flowchart.selectedBlock = parentBlock;
                        Continue();
                    };
                }

                if (targetFlowchart == null ||
                    targetFlowchart == GetFlowchart())
                {
                    // If the executing block is currently selected then follow the execution
                    // onto the next block in the inspector.
                    if (flowchart.selectedBlock == parentBlock)
                    {
                        flowchart.selectedBlock = targetBlock;
                    }

                    targetBlock.Execute(onComplete);
                }
                else
                {
                    // Execute block in another Flowchart
                    targetFlowchart.ExecuteBlock(targetBlock, onComplete);
                }
            }

            if (callMode == CallMode.Stop)
            {
                Stop();
            }
            else if (callMode == CallMode.Continue)
            {
                Continue();
            }
        }
コード例 #4
0
        public virtual bool AddOption(string text, bool interactable, Block targetBlock)
        {
            bool addedOption = false;

            foreach (Button button in cachedButtons)
            {
                if (!button.gameObject.activeSelf)
                {
                    button.gameObject.SetActive(true);

                    button.interactable = interactable;

                    Text textComponent = button.GetComponentInChildren <Text>();
                    if (textComponent != null)
                    {
                        textComponent.text = text;
                    }

                    Block block = targetBlock;

                    button.onClick.AddListener(delegate {
                        StopAllCoroutines();                         // Stop timeout
                        Clear();

                        HideSayDialog();

                        if (block != null)
                        {
                                                        #if UNITY_EDITOR
                            // Select the new target block in the Flowchart window
                            Flowchart flowchart     = block.GetFlowchart();
                            flowchart.selectedBlock = block;
                                                        #endif

                            gameObject.SetActive(false);

                            block.Execute();
                        }
                    });

                    addedOption = true;
                    break;
                }
            }

            return(addedOption);
        }
コード例 #5
0
        /**
         * Start executing a specific child block in the flowchart.
         * The block must be in an idle state to be executed.
         * Returns true if the Block started execution.
         */
        public virtual bool ExecuteBlock(Block block, Action onComplete = null)
        {
            // Block must be a component of the Flowchart game object
            if (block == null ||
                block.gameObject != gameObject)
            {
                return(false);
            }

            // Can't restart a running block, have to wait until it's idle again
            if (block.IsExecuting())
            {
                return(false);
            }

            // Execute the first command in the command list
            block.Execute(onComplete);

            return(true);
        }
コード例 #6
0
        public override void OnEnter()
        {
            var flowchart = GetFlowchart();

            if (targetBlock != null)
            {
                // Check if calling your own parent block
                if (ParentBlock != null && ParentBlock.Equals(targetBlock))
                {
                    // Just ignore the callmode in this case, and jump to first command in list
                    Continue(0);
                    return;
                }

                if (targetBlock.IsExecuting())
                {
                    Debug.LogWarning(targetBlock.BlockName + " cannot be called/executed, it is already running.");
                    Continue();
                    return;
                }

                // Callback action for Wait Until Finished mode
                Action onComplete = null;
                if (callMode == CallMode.WaitUntilFinished)
                {
                    onComplete = delegate {
                        Continue();
                    };
                }

                // Find the command index to start execution at
                int index = startIndex;
                if (startLabel.Value != "")
                {
                    int labelIndex = targetBlock.GetLabelIndex(startLabel.Value);
                    if (labelIndex != -1)
                    {
                        index = labelIndex;
                    }
                }

                if (targetFlowchart == null ||
                    targetFlowchart.Equals(GetFlowchart()))
                {
                    if (callMode == CallMode.StopThenCall)
                    {
                        StopParentBlock();
                    }
                    StartCoroutine(targetBlock.Execute(index, onComplete));
                }
                else
                {
                    if (callMode == CallMode.StopThenCall)
                    {
                        StopParentBlock();
                    }
                    // Execute block in another Flowchart
                    targetFlowchart.ExecuteBlock(targetBlock, index, onComplete);
                }
            }

            if (callMode == CallMode.Stop)
            {
                StopParentBlock();
            }
            else if (callMode == CallMode.Continue)
            {
                Continue();
            }
        }
コード例 #7
0
ファイル: Call.cs プロジェクト: JelleDekkers/ProjectContext
        public override void OnEnter()
        {
            var flowchart = GetFlowchart();

            if (targetBlock != null)
            {
                // Check if calling your own parent block
                if (ParentBlock != null && ParentBlock.Equals(targetBlock))
                {
                    // Just ignore the callmode in this case, and jump to first command in list
                    Continue(0);
                    return;
                }

                // Callback action for Wait Until Finished mode
                Action onComplete = null;
                if (callMode == CallMode.WaitUntilFinished)
                {
                    onComplete = delegate {
                        flowchart.SelectedBlock = ParentBlock;
                        Continue();
                    };
                }

                // Find the command index to start execution at
                int index = startIndex;
                if (startLabel.Value != "")
                {
                    int labelIndex = targetBlock.GetLabelIndex(startLabel.Value);
                    if (labelIndex != -1)
                    {
                        index = labelIndex;
                    }
                }

                if (targetFlowchart == null ||
                    targetFlowchart.Equals(GetFlowchart()))
                {
                    // If the executing block is currently selected then follow the execution
                    // onto the next block in the inspector.
                    if (flowchart.SelectedBlock == ParentBlock)
                    {
                        flowchart.SelectedBlock = targetBlock;
                    }

                    //targetBlock.Execute(index, onComplete);
                    StartCoroutine(targetBlock.Execute(index, onComplete));
                }
                else
                {
                    // Execute block in another Flowchart
                    targetFlowchart.ExecuteBlock(targetBlock, index, onComplete);
                }
            }

            if (callMode == CallMode.Stop)
            {
                StopParentBlock();
            }
            else if (callMode == CallMode.Continue)
            {
                Continue();
            }
        }
コード例 #8
0
        public override void OnEnter()
        {
            showBasicGUI = false;
            if (chooseDialog == null)
            {
                if (chooseDialog == null)
                {
                    // Try to get any ChooseDialog in the scene
                    chooseDialog = GameObject.FindObjectOfType <ChooseDialog>();
                }

                if (chooseDialog == null)
                {
                    showBasicGUI = true;
                    return;
                }
            }

            if (options.Count == 0)
            {
                Continue();
            }
            else
            {
                Flowchart flowchart = GetFlowchart();

                chooseDialog.ShowDialog(true);
                chooseDialog.SetCharacter(character, flowchart);
                chooseDialog.SetCharacterImage(portrait);

                List <ChooseDialog.Option> dialogOptions = new List <ChooseDialog.Option>();
                foreach (Option option in options)
                {
                    ChooseDialog.Option dialogOption = new ChooseDialog.Option();

                    // Store these in local variables so they get closed over correctly by the delegate call
                    dialogOption.text = option.optionText;
                    dialogOption.text = flowchart.SubstituteVariables(dialogOption.text);
                    Block  onSelectBlock = option.targetBlock;
                    Action optionAction  = option.action;

                    dialogOption.onSelect = delegate {
                        if (optionAction != null)
                        {
                            optionAction();
                        }

                        chooseDialog.ShowDialog(false);

                        if (onSelectBlock == null)
                        {
                            Continue();
                        }
                        else
                        {
                            Stop();
                            onSelectBlock.Execute();
                        }
                    };

                    dialogOptions.Add(dialogOption);
                }

                options.Clear();

                if (voiceOverClip != null)
                {
                    chooseDialog.PlayVoiceOver(voiceOverClip);
                }

                string subbedText = flowchart.SubstituteVariables(chooseText);

                chooseDialog.Choose(subbedText, dialogOptions, timeoutDuration, delegate {
                    chooseDialog.ShowDialog(false);
                    Continue();
                });
            }
        }
コード例 #9
0
		protected virtual IEnumerator WaitForTimeout(float timeoutDuration, Block targetBlock)
		{
			float elapsedTime = 0;
			
			Slider timeoutSlider = GetComponentInChildren<Slider>();
			
			while (elapsedTime < timeoutDuration)
			{
				if (timeoutSlider != null)
				{
					float t = 1f - elapsedTime / timeoutDuration;
					timeoutSlider.value = t;
				}
				
				elapsedTime += Time.deltaTime;
				
				yield return null;
			}
			
			Clear();
			gameObject.SetActive(false);

			HideSayDialog();

			if (targetBlock != null)
			{
				targetBlock.Execute();
			}
		}
コード例 #10
0
        public override void OnEnter()
        {
            //Randomiser
            int randomWeightTotal = 0;

            foreach (WeightedBlockCallClass block in targetBlocks)
            {
                randomWeightTotal += block.bias;
            }
            int randomWeight = UnityEngine.Random.Range(0, randomWeightTotal);

            int curBlockIndex = 0;

            foreach (WeightedBlockCallClass block in targetBlocks)
            {
                if (randomWeight - block.bias <= 0)
                {
                    targetBlock = block.targetBlock;
                }
                else
                {
                    randomWeightTotal -= block.bias;
                }
            }
            if (targetBlock == null)
            {
                Debug.LogError("Issue with the randomising system");
            }
            //

            var flowchart = GetFlowchart();

            if (targetBlock != null)
            {
                // Check if calling your own parent block
                if (ParentBlock != null && ParentBlock.Equals(targetBlock))
                {
                    // Just ignore the callmode in this case, and jump to first command in list
                    Continue(0);
                    return;
                }

                if (targetBlock.IsExecuting())
                {
                    Debug.LogWarning(targetBlock.BlockName + " cannot be called/executed, it is already running.");
                    Continue();
                    return;
                }

                // Callback action for Wait Until Finished mode
                Action onComplete = null;
                if (callMode == CallMode.WaitUntilFinished)
                {
                    onComplete = delegate {
                        flowchart.SelectedBlock = ParentBlock;
                        Continue();
                    };
                }

                // Find the command index to start execution at
                int index = startIndex;
                if (startLabel.Value != "")
                {
                    int labelIndex = targetBlock.GetLabelIndex(startLabel.Value);
                    if (labelIndex != -1)
                    {
                        index = labelIndex;
                    }
                }

                if (targetFlowchart == null ||
                    targetFlowchart.Equals(GetFlowchart()))
                {
                    // If the executing block is currently selected then follow the execution
                    // onto the next block in the inspector.
                    if (flowchart.SelectedBlock == ParentBlock)
                    {
                        flowchart.SelectedBlock = targetBlock;
                    }

                    if (callMode == CallMode.StopThenCall)
                    {
                        StopParentBlock();
                    }
                    StartCoroutine(targetBlock.Execute(index, onComplete));
                }
                else
                {
                    if (callMode == CallMode.StopThenCall)
                    {
                        StopParentBlock();
                    }
                    // Execute block in another Flowchart
                    targetFlowchart.ExecuteBlock(targetBlock, index, onComplete);
                }
            }

            if (callMode == CallMode.Stop)
            {
                StopParentBlock();
            }
            else if (callMode == CallMode.Continue)
            {
                Continue();
            }
        }
コード例 #11
0
ファイル: Call.cs プロジェクト: 1194451658/fungus
        public override void OnEnter()
        {
            var flowchart = GetFlowchart();

            if (targetBlock != null)
            {
                // 如果目标block,是自己
                //  * 则,从命令0,开始重头执行
                // Check if calling your own parent block
                if (ParentBlock != null && ParentBlock.Equals(targetBlock))
                {
                    // Just ignore the callmode in this case, and jump to first command in list
                    Continue(0);
                    return;
                }

                // target block如果已经执行中
                //  * 报warning错!
                if (targetBlock.IsExecuting())
                {
                    Debug.LogWarning(targetBlock.BlockName + " cannot be called/executed, it is already running.");
                    Continue();
                    return;
                }

                // Callback action for Wait Until Finished mode
                Action onComplete = null;

                // 等待命令执行完成,并继续的模式
                if (callMode == CallMode.WaitUntilFinished)
                {
                    onComplete = delegate {
                        // 选中当前命令的block
                        flowchart.SelectedBlock = ParentBlock;
                        // 并继续播放
                        Continue();
                    };
                }

                // Find the command index to start execution at
                int index = startIndex;
                if (startLabel.Value != "")
                {
                    int labelIndex = targetBlock.GetLabelIndex(startLabel.Value);
                    if (labelIndex != -1)
                    {
                        index = labelIndex;
                    }
                }

                if (targetFlowchart == null ||
                    targetFlowchart.Equals(GetFlowchart()))
                {
                    // If the executing block is currently selected then follow the execution
                    // onto the next block in the inspector.
                    if (flowchart.SelectedBlock == ParentBlock)
                    {
                        flowchart.SelectedBlock = targetBlock;
                    }

                    if (callMode == CallMode.StopThenCall)
                    {
                        StopParentBlock();
                    }
                    StartCoroutine(targetBlock.Execute(index, onComplete));
                }
                else
                {
                    if (callMode == CallMode.StopThenCall)
                    {
                        StopParentBlock();
                    }
                    // Execute block in another Flowchart
                    targetFlowchart.ExecuteBlock(targetBlock, index, onComplete);
                }
            }

            if (callMode == CallMode.Stop)
            {
                StopParentBlock();
            }
            else if (callMode == CallMode.Continue)
            {
                Continue();
            }
        }