Ejemplo n.º 1
0
        protected virtual IEnumerator WaitForTimeout(float timeoutDuration, Sequence targetSequence)
        {
            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);

            if (targetSequence != null)
            {
                targetSequence.ExecuteCommand(0);
            }
        }
Ejemplo n.º 2
0
 public virtual void Continue(int nextCommandIndex)
 {
     OnExit();
     if (parentSequence != null)
     {
         parentSequence.ExecuteCommand(nextCommandIndex);
     }
 }
Ejemplo n.º 3
0
        public virtual bool AddOption(string text, Sequence targetSequence)
        {
            gameObject.SetActive(true);

            bool addedOption = false;

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

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

                    Sequence sequence = targetSequence;

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

                        // Hide the active Say dialog in case it's still being displayed
                        SayDialog activeSayDialog = SetSayDialog.GetActiveSayDialog();
                        if (activeSayDialog != null)
                        {
                            activeSayDialog.ShowDialog(false);
                        }

                        if (sequence != null)
                        {
                                                        #if UNITY_EDITOR
                            // Select the new target sequence in the Fungus Script window
                            FungusScript fungusScript     = sequence.GetFungusScript();
                            fungusScript.selectedSequence = sequence;
                                                        #endif

                            sequence.ExecuteCommand(0);
                        }
                    });

                    addedOption = true;
                    break;
                }
            }

            return(addedOption);
        }
Ejemplo n.º 4
0
        /**
         * Start running another Fungus Script by executing a specific child sequence.
         * The sequence must be in an idle state to be executed.
         * Returns true if the Sequence started execution.
         */
        public virtual bool ExecuteSequence(Sequence sequence)
        {
            // Sequence must be a component of the Fungus Script game object
            if (sequence == null ||
                sequence.gameObject != gameObject)
            {
                return(false);
            }

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

            // Execute the first command in the command list
            sequence.ExecuteCommand(0);

            return(true);
        }