Ejemplo n.º 1
0
        public override void HandleFluentNode(FluentNode fluentNode)
        {
            pause = (PauseNode)fluentNode;

            // Start pause
            StartCoroutine("StartPause");
        }
        public override void HandleFluentNode(FluentNode fluentNode)
        {
            continueWhen = (ContinueWhenNode)fluentNode;

            // Start pause
            StartCoroutine("RunTest");
        }
Ejemplo n.º 3
0
 private void RootDone(FluentNode node)
 {
     OnFinish();
     if (Done != null)
     {
         Done(this);
     }
 }
Ejemplo n.º 4
0
        public WhileNode(GameObject gameObject, Func <bool> test, FluentNode node)
            : base(gameObject)
        {
            // The children are defined as a node chain
            Children = node.UnravelFromBack();

            this.test = test;
        }
Ejemplo n.º 5
0
        public override void Interrupt(FluentNode fluentNode)
        {
            GameObject fluentPlayer = SoundPlayers.Find(x => x.GetComponent <SoundPlayer>().soundNode == fluentNode);

            SoundPlayer sp = fluentPlayer.GetComponent <SoundPlayer>();

            sp.StopPlaying();
            FinishSoundPlayer(sp);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Child nodes tell us when they are interrupted so that we can interrupt the other parallel children
        /// eg. Write might be interrupted by being clicked on, we then also need to stop any sounds from playing
        /// </summary>
        /// <param name="node"></param>
        private void ParallelChildInterrupted(FluentNode node)
        {
            // Interrupt all the other children
            FluentNode[] childrenToInterrupt = childNodesNotDone.ToArray();

            foreach (FluentNode childToInterrupt in childrenToInterrupt)
            {
                childToInterrupt.Interrupt();
            }
        }
Ejemplo n.º 7
0
        private void HandleNextNode()
        {
            if (childQueue.Count == 0)
            {
                Done();
                return;
            }

            FluentNode firstNode = childQueue.Dequeue();

            firstNode.SetDoneCallback(SequentialChildCompleted);
            firstNode.Execute();
        }
Ejemplo n.º 8
0
        protected override FluentNode Join(FluentNode rightNode)
        {
            // If the right node is an option, chain them
            if (rightNode is OptionNode)
            {
                return(base.Join(rightNode));
            }

            // Otherwise we add the node as a child node to option and return the option
            // so that we can add other nodes to the same option
            Children.Add(rightNode);
            return(this);
        }
Ejemplo n.º 9
0
        public FluentNode GetFirst()
        {
            FluentNode currentNode = this;

            while (true)
            {
                if (currentNode.Previous == null)
                {
                    return(currentNode);
                }
                currentNode = currentNode.Previous;
            }
        }
Ejemplo n.º 10
0
        private IEnumerator StartYell()
        {
            // Create an instance of a yell canvas
            if (YellUI == null)
            {
                Debug.LogError("Your Yell Handler does not have a yell dialog UI specified. Add a canvas that has a Text component as a child to this object", gameObject);
                yield break;
            }

            // Show the yell UI
            YellUI.SetActive(true);

            // Called now to orientate the yell to the camera otherwise there is a stutter
            Update();

            // Set the yell canvas text
            TextMeshProUGUI text = YellUI.GetComponentInChildren <TextMeshProUGUI>();

            //
            if (text == null)
            {
                throw new UnityException("Could not find a Text UI component in the specified Yell UI");
            }

            //
            ConnectClickCallback(text.gameObject);

            foreach (FluentString str in CurrentNode.Sentences)
            {
                text.text = str;

                // Wait for the specified amount of seconds
                float elapsedTime = -1f;
                while (elapsedTime < CurrentNode.SecondsToPause && !interrupt)
                {
                    elapsedTime += Time.deltaTime;
                    yield return(null);
                }
                interrupt = false;
            }

            //
            FluentNode tempCurrentNode = CurrentNode;

            // Close the canvas
            CloseCanvas();

            //
            CurrentNode = null;
            tempCurrentNode.Done();
        }
Ejemplo n.º 11
0
        private void OptionCompleted(FluentNode fluentNode)
        {
            OptionNode completedOptionNode = fluentNode as OptionNode;

            // Check to see if the selected option wants us to go back
            if (completedOptionNode.GoesBack)
            {
                currentOptionsNode.Done();
                return;
            }

            // The completed option does not go back, just redisplay these options
            currentOptionsNode.Execute();
        }
Ejemplo n.º 12
0
        public override void HandleFluentNode(FluentNode fluentNode)
        {
            soundNode = (SoundNode)fluentNode;

            // Create the sound player
            GameObject  soundPlayerGameObject = SoundPlayer.CreateSoundPlayer(soundNode);
            SoundPlayer soundPlayer           = soundPlayerGameObject.GetComponent <SoundPlayer>();

            soundPlayer.DonePlaying += soundPlayer_DonePlaying;

            // Make the game object the parent
            soundPlayer.transform.parent = soundNode.GameObject.transform;

            SoundPlayers.Add(soundPlayerGameObject);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Start at the back and reconstruct a FluentNode chain.
        /// FluentNodes are constructed by chaining them with the * operator.
        /// Most of the times we want to turn that chain into a list.
        /// Will also remove the previous and next pointers from each node, they are only used internally
        /// </summary>
        /// <returns></returns>
        public List <FluentNode> UnravelFromBack()
        {
            List <FluentNode> nodeList    = new List <FluentNode>();
            FluentNode        currentNode = this;

            while (currentNode != null)
            {
                nodeList.Insert(0, currentNode);
                FluentNode prevNode = currentNode;
                currentNode       = currentNode.Previous;
                prevNode.Next     = null;
                prevNode.Previous = null;
            }
            return(nodeList);
        }
Ejemplo n.º 14
0
        public void End()
        {
            // Find the highest level Options node
            FluentNode highestOptionsNode = currentOptionsNode;

            while (highestOptionsNode.Parent is OptionsNode || highestOptionsNode.Parent is OptionNode)
            {
                highestOptionsNode = highestOptionsNode.Parent;
            }

            // Hide
            Hide();

            // Call done on it
            highestOptionsNode.Done();
        }
Ejemplo n.º 15
0
        private void HandleNextNode()
        {
            // Check if all the nodes have been handled
            if (childQueue.Count == 0)
            {
                // Start the options presenter
                optionsPresenter.SetupOptions(this);
                return;
            }


            FluentNode firstNode = childQueue.Dequeue();

            firstNode.SetDoneCallback(SequentialChildCompleted);
            firstNode.Execute();
        }
Ejemplo n.º 16
0
        private void ParallelChildCompleted(FluentNode node)
        {
            // It is possible that a child node completes via normal means before the interruption is triggered
            // Make sure we don't remove it twice, which would also make parallel's done be called twice
            if (!childNodesNotDone.Contains(node))
            {
                return;
            }

            // Remove the node
            childNodesNotDone.Remove(node);

            // If all the child nodes have been completed
            // Notify whoever that this parallel node is complete
            if (childNodesNotDone.Count == 0)
            {
                DoneDelegate(this);
            }
        }
Ejemplo n.º 17
0
        private IEnumerator StartYell()
        {
            // Create an instance of a yell canvas
            if (YellUI == null)
            {
                Debug.LogError("Your Yell Handler does not have a yell dialog UI specified. Add a canvas that has a Text component as a child to this object", gameObject);
                yield break;
            }

            // Show the yell UI
            YellUI.SetActive(true);

            // Called now to orientate the yell to the camera otherwise there is a hak
            Update();

            // Set the yell canvas text
            Text text = YellUI.GetComponentInChildren <Text>();

            //
            ConnectClickCallback(text.gameObject);

            if (text == null)
            {
                throw new UnityException("Could not find a Text UI component in the specified Yell UI");
            }

            text.text = CurrentNode.Text;

            // Show the canvas for x seconds
            yield return(new WaitForSeconds(CurrentNode.SecondsToPause));

            //
            FluentNode tempCurrentNode = CurrentNode;

            // Close the canvas
            CloseCanvas();

            //
            CurrentNode = null;
            tempCurrentNode.Done();
        }
Ejemplo n.º 18
0
        void ConnectClickCallback(GameObject go)
        {
            if (go.GetComponentInChildren <Button>() == null)
            {
                go.AddComponent <Button>();
            }

            // Add the button listener so that text can be skipped
            go.GetComponentInChildren <Button>().onClick.RemoveAllListeners();
            go.GetComponentInChildren <Button>().onClick.AddListener(new UnityEngine.Events.UnityAction(() =>
            {
                StopCoroutine("StartYell");
                CloseCanvas();
                FluentNode savedCurrentNode = CurrentNode;
                CurrentNode = null;
                savedCurrentNode.Done();
            }));

            // Focus the button so that keypresses work
            EventSystem.current.SetSelectedGameObject(go);
        }
Ejemplo n.º 19
0
        private void HandleNextNode()
        {
            // Check if we handled all the children
            if (childQueue.Count == 0)
            {
                // Lets see if we should restart the while
                if (!test())
                {
                    Done();
                    return;
                }

                // Add all the children again
                Children.ForEach(n => childQueue.Enqueue(n));
            }

            FluentNode firstNode = childQueue.Dequeue();

            firstNode.SetDoneCallback(ChildCompleted);
            firstNode.Execute();
        }
Ejemplo n.º 20
0
        private void HandleNextNode()
        {
            if (childrenLeftToExecute.Count == 0)
            {
                // Ugh, think about cleanup
                if (GoesBack && (Parent is OptionsNode) && (Parent.Parent is OptionNode) && (Parent.Parent.Parent is OptionsNode))
                {
                    Parent.Parent.Parent.Execute();
                }
                else
                {
                    HasBeenChosen = true;
                    Done();
                }

                return;
            }

            FluentNode firstNode = childrenLeftToExecute.Dequeue();

            firstNode.SetDoneCallback(OptionChildCompleted);
            firstNode.Execute();
        }
Ejemplo n.º 21
0
        public override void HandleFluentNode(FluentNode fluentNode)
        {
            // We can only have one yell response for a given handler
            if (CurrentNode != null)
            {
                // Stop the current yell
                StopCoroutine("StartYell");

                // Make sure it tells whoever is interested that it completed
                CurrentNode.Done();
            }

            // Save parameters
            CurrentNode = fluentNode as YellNode;

            if (CurrentNode == null)
            {
                Debug.Log("CurrentNode is null");
            }

            // Start yell
            StartCoroutine("StartYell");
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Call this to start the FluentScript
        /// </summary>
        public virtual void Run()
        {
            //
            OnStart();

            // Create the fluent script
            FluentNode firstNode = SequentialNode(Create());

            // Do a couple of things to the tree before execution starts
            firstNode.Visit((n) =>
            {
                // Tell all the children who the parent is
                n.Children.ForEach(c => c.Parent = n);

                // Run their before execute methods
                n.BeforeExecute();
            });

            //
            firstNode.SetDoneCallback(RootDone);

            //
            firstNode.Execute();
        }
Ejemplo n.º 23
0
 public override void Interrupt(FluentNode fluentNode)
 {
     StopCoroutine("StartYell");
     CloseCanvas();
     CurrentNode = null;
 }
Ejemplo n.º 24
0
 /// <summary>
 /// The default join behaviour for two nodes is to chain them with Next and Previous and return the right node
 /// </summary>
 /// <param name="rightNode"></param>
 /// <returns></returns>
 protected virtual FluentNode Join(FluentNode rightNode)
 {
     Next = rightNode;
     rightNode.Previous = this;
     return(rightNode);
 }
Ejemplo n.º 25
0
        public override void HandleFluentNode(FluentNode fluentNode)
        {
            // Store current node
            currentNode = fluentNode as WriteNode;

            // Check if the UI element is defined on the
            if (currentNode.TextUIElement != null)
            {
                currentTextUI = currentNode.TextUIElement.gameObject;
            }
            else
            {
                currentTextUI = TextUI;
            }

            // Get the text component we are using to write the text
            Text textTextUI = currentTextUI.GetComponent <Text>();

            if (!(currentTextUI).activeSelf)
            {
                Debug.LogError("Did you forget to call Show() before Write() in your node chain ? The Write Node needs the element on to which text is written to be visible", this);
                return;
            }

            // Add a button to the text if it doent have one
            if (currentTextUI.GetComponentInChildren <Button>() == null)
            {
                currentTextUI.AddComponent <Button>();
            }

            // Add the button listener so that text can be skipped
            currentTextUI.GetComponentInChildren <Button>().onClick.RemoveAllListeners();
            currentTextUI.GetComponentInChildren <Button>().onClick.AddListener(new UnityEngine.Events.UnityAction(() =>
            {
                // Do cleanup
                isTyping = false;
                StopCoroutine("TypeText");
                StopCoroutine("Pause");
                currentTextUI.GetComponent <Text>().text = currentNode.Text;
                RemoveSkipListener();

                // Write's that require a button press to continue cannot be interrupted
                if (currentNode.WaitForButtonPress)
                {
                    ShowButton();
                    return;
                }

                FluentNode prevNode = currentNode;
                currentNode.Done();
                prevNode.IWasInterrupted();
            }));

            // Set the text component to be the selected component
            EventSystem.current.SetSelectedGameObject(textTextUI.gameObject);

            // Check if this is an instant write
            if (CharacterPauseSeconds == 0)
            {
                currentTextUI.GetComponent <Text>().text = currentNode.Text;
                if (currentNode.SecondsToPause != 0)
                {
                    StartCoroutine("Pause");
                }
                else
                {
                    currentNode.Done();
                }

                return;
            }

            StartCoroutine("TypeText");
        }
 public abstract void HandleFluentNode(FluentNode fluentNode);
Ejemplo n.º 27
0
 public FluentNode While(Func <bool> test, FluentNode node)
 {
     return(new WhileNode(gameObject, test, node));
 }
Ejemplo n.º 28
0
 public override void Interrupt(FluentNode fluentNode)
 {
     StopCoroutine("StartPause");
 }
Ejemplo n.º 29
0
 public override void Interrupt(FluentNode fluentNode)
 {
     Debug.Log("Interrupt write");
     //
 }
 /// <summary>
 /// Interrupt should interrupt the execution of the handler
 /// and call Done() for the fluentNode that was passed as parameter
 /// </summary>
 /// <param name="fluentNode"></param>
 public virtual void Interrupt(FluentNode fluentNode)
 {
 }