Exemplo n.º 1
0
 /// <summary>
 /// Called after the current node or the index of the current dialogue entry has changed.
 /// </summary>
 /// <remarks>
 /// The game state will be updated according to the current node and current dialogue index.
 /// This method will execute the action in the new current dialogue entry and informs all game state listeners
 /// Since the action inside the dialogue entry will be executed, this method should not be called twice
 /// if only one update has happen
 /// </remarks>
 private void UpdateGameState()
 {
     currentDialogueEntry = currentNode.GetDialogueEntryAt(currentIndex);
     DialogueWillChange.Invoke();
     currentDialogueEntry.ExecuteAction();
     DialogueChanged.Invoke(
         new DialogueChangedEventData(currentNode.name, currentIndex, currentDialogueEntry.text,
                                      voicesOfNextDialogue));
     voicesOfNextDialogue.Clear();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Called after the current node or the index of the current dialogue entry has changed.
        /// </summary>
        /// <remarks>
        /// The game state will be updated according to walkedThroughNodes and current dialogue index.
        /// This method will check if the game state has changed and trigger proper events
        /// </remarks>
        /// <param name="forceRefreshDialogue">refresh dialogue no matter the game state has change or not</param>
        /// <param name="forceRefreshNode">refresh the node no matter the node has changed or not</param>
        private void UpdateGameState(bool forceRefreshDialogue = false, bool forceRefreshNode = false)
        {
            Assert.IsFalse(walkedThroughNodes.Count == 0,
                           "Nova: walkedThroughNodes is empty, can not update game state.");

            // update current node
            var desiredNodeName = walkedThroughNodes.Last();
            var nodeChanged     = currentNode == null || currentNode.name != desiredNodeName;

            if (nodeChanged || forceRefreshNode)
            {
                currentNode = flowChartTree.FindNode(desiredNodeName);
                if (NodeChanged != null)
                {
                    NodeChanged.Invoke(new NodeChangedData(currentNode.name, currentNode.description));
                }
            }

            // update dialogue
            var dialogueChanged = nodeChanged || currentIndex != oldIndex;

            if (dialogueChanged || forceRefreshDialogue)
            {
                Assert.IsTrue(currentIndex >= 0 && currentIndex < currentNode.DialogueEntryCount,
                              "Nova: dialogue index out of range");
                currentDialogueEntry = currentNode.GetDialogueEntryAt(currentIndex);
                oldIndex             = currentIndex;

                if (checkpointManager.IsReached(currentNode.name, currentIndex) == null)
                {
                    // tell the checkpoint manager a new dialogue entry has been reached
                    checkpointManager.SetReached(currentNode.name, currentIndex, GetGameStateStepRestoreEntry());
                }

                if (DialogueWillChange != null)
                {
                    DialogueWillChange.Invoke();
                }

                state = State.ActionRunning;
                currentDialogueEntry.ExecuteAction();
                StartCoroutine(WaitActionEnd());
            }
        }