public void StartDialogue(string startChatId, List <DialogueNode> loadedNodes, List <DialogueWrapper> loadedConversations) { if (loadedNodes.Count == 0) { throw new UnityException(GlobalConsts.LIST_WAS_EMPTY + transform.name); } dialogueService.Reload(); conversations = new List <DialogueWrapper>(loadedConversations); dialogueIterator = new DialogueIterator(loadedNodes); OnConversationStarted?.Invoke(); IsActive = true; DialogueBox.SetActive(true); Next(startChatId); }
public void Next(string nodeId = null, string findIn = null) { if (WaitingForChoices || !IsActive) { return; } if (ExitScheduled) { OnChatComplete(); return; } ClearButtons(); if (findIn != null) { var switchTo = conversations.Find(x => x.Id == findIn); dialogueIterator = new DialogueIterator(switchTo.Nodes); Debug.Log("Switched to conversation: " + findIn); } DialogueNode node = dialogueIterator.GoToNext(nodeId); if (node == null) { Debug.LogError("Chat quit unexpectedly. Couldn't find a node to display."); OnChatComplete(); return; } Log(node.Text); DialogueField.text = node.Text; ExitScheduled = node.IsLast; /* Connection parsing */ if (node.HasConnection) { dialogueIterator.PushNext(node.To); } /* Route parsing */ if (node.HasRoute) { bool outcome = false; /* Note: Route actions make no sense when queued, so don't bother. Also * not a huge fan of doing this to detect an item existing, but for * now it's all we've got. I'll figure a way to get this working * via a delegate instead at some point. */ switch (node.Route.RouteBool.method) { case DialogueConsts.CHECK_FOR_ITEM: outcome = GameObject .FindGameObjectWithTag(GlobalConsts.CONTEXT_TAG) .GetComponent <PlayerInventory>() .HasItem(node.Route.RouteBool.value); break; } string outcomeId = outcome ? node.Route.PositiveId : node.Route.NegativeId; dialogueIterator.PushNext(outcomeId); } /* Action parsing & events */ if (node.HasActions) { List <DialogueAction> postActions = node.Actions .Where(x => x.waitForFinish) .ToList(); PostActionQueue.AddRange(postActions); List <DialogueAction> immediateActions = node.Actions .Where(x => !x.waitForFinish) .ToList(); TriggerActions(immediateActions); } OnNext?.Invoke(node); /* Begin output of text */ StopAllCoroutines(); StartCoroutine(TypeSentence(node)); }