public void SetConversation(NPCConversation npcConversation) { if (npcConversation != null) { this.npcConversation = this.npcConversationOld = npcConversation; } }
public void OnBeginInteraction() { npc.npcEventHandler.NPCSelection += DialogueSelectionHandler; InfoSignAnim.Play(InfoSignAnimHash.EMPTY); DialogueBoxAnim.Play(DialogueBoxAnimHash.IDLE); initBox(); if (npcConversation == null) { npcConversation = npcConversationOld; } if (npcConversation != null) { npcConversation.ResetIndex(); getNextSentence(); resetTotalTime(); _currentConverseStatus = ConversationStatus.CONVERSE; } else { OnEndInteraction(); } }
// ---- DELEGATE HANDLER ----------------------------------- public void OnEnterInteractionArea() { InfoSignAnim.Play(InfoSignAnimHash.INTRO); selectionBox.gameObject.SetActive(false); npcConversation = npcConversationOld; }
public void SetNewQuiz(NPCConversation newDialogue) { if (queuedConversations.Contains(newDialogue)) { return; } queuedConversations.Enqueue(newDialogue); needForDeserialization.Enqueue(false); }
public void UpdateCurrentDialogue() { if (queuedConversations.Count > 0) { currentDialogue = queuedConversations.Dequeue(); } else { currentDialogue = defaultConversation; } }
private void SayQuizConversationNext() { DialogueManager dialogue = GameManager.Instance.m_dialogueManager; // If there is a current quiz conversation, then destroy it if (currentQuizConversation) { Destroy(currentQuizConversation); } // Set the current quiz conversation currentQuizConversation = Create(dialogue); // Tell the dialogue manager to say the quiz conversation after the currently running conversation dialogue.SetNewQuiz(currentQuizConversation); }
public void StartConversation() { if (hasTalked) { //_currentConversation = GameAssets.Instance.alreadyTalkedConversation; // bo w aktualnej wersji chcemy żeby można było rozmawiać kilka razy _currentConversation = alreadyTalkedConversation; } if (!ConversationManager.Instance.IsConversationActive) { ConversationManager.Instance.StartConversation(_currentConversation); hasTalked = true; } }
void Awake() { npc = GetComponentInParent <NPC>(); player = GameObject.Find("Player").GetComponent <Player>(); pFontLoader = new PFontLoader(pFontInfo); OP = new ObjectPool(); charOrigin = DialogueBoxAnim.gameObject.transform.GetChild(0); selectionBox = DialogueBoxAnim.gameObject.transform.GetChild(1); recycleObject = new List <GameObject>(); nextSentence = new Queue <char>(); wordObject = new List <CharInfoWrapper>(); npcSelections = new List <NPCSelection>(); npcConversationOld = npcConversation; }
public static void OnConversationEnded(this NPCConversation conversation, UnityAction action) { // Deserialize the conversation for modification EditableConversation editableConversation = conversation.DeserializeForEditor(); // Filter all speech nodes that have no speech node after and have no options after IEnumerable <EditableSpeechNode> leaves = editableConversation.SpeechNodes .Where(node => node.SpeechUID == EditableConversation.INVALID_UID && (node.OptionUIDs == null || node.OptionUIDs.Count <= 0)); // For each event associated with the leaf, make that leaf end the conversation when finished foreach (EditableSpeechNode leaf in leaves) { NodeEventHolder eventHolder = conversation.GetNodeData(leaf.ID); eventHolder.Event.AddListener(action); } }
public void SayEndingConversation() { if (isQuiz) { // The quiz conversation won't work unless it is instantiated, // because the conversation might modify the object it is on, // which Unity cannot allow for a prefab activeQuizConversation = Object.Instantiate(quizConversation); activeQuizConversation.Setup(); } else { // This is used so that the game over controller can dynamically add // game over events to a non-prefab instance of the NPCConversation activeConversation = normalConversation.InstantiateAndSay(); } }
// Use this for initialization void Start() { TipsButton = GameObject.Find("TipsButton").GetComponent <Button>(); HealButton = GameObject.Find("HealButton").GetComponent <Button>(); ObjectsButton = GameObject.Find("ObjectsButton").GetComponent <Button>(); ByePopeButton = GameObject.Find("ByePopeButton").GetComponent <Button>(); TipsButton.onClick.AddListener(() => pope.StartButtonConversation("Tips")); HealButton.onClick.AddListener(() => pope.StartButtonConversation("Heal")); ObjectsButton.onClick.AddListener(() => pope.StartButtonConversation("Objects")); ByePopeButton.onClick.AddListener(() => pope.StartButtonConversation("ByePope")); //dialogue = GameObject.Find("Gameplay").GetComponent<DialogueLists>(); TipsButton.gameObject.SetActive(false); HealButton.gameObject.SetActive(false); ObjectsButton.gameObject.SetActive(false); ByePopeButton.gameObject.SetActive(false); pope = GameObject.Find("Pope").GetComponent <NPCConversation>(); }
public virtual void OnBeginInteraction() { if (player && MiscData.conversationIndex.ContainsKey(GetComponent <GulchGUID>().ID)) { currentConversationIndex = MiscData.conversationIndex[GetComponent <GulchGUID>().ID]; } else if (player) { currentConversationIndex = 0; MiscData.conversationIndex.Add(GetComponent <GulchGUID>().ID, 0); } if (npcConversations.Count() > 0) { npcConversation = npcConversations[currentConversationIndex]; } npc.npcEventHandler.NPCSelection += DialogueSelectionHandler; InfoSignAnim?.Play(InfoSignAnimHash.EMPTY); DialogueBoxAnim.Play(DialogueBoxAnimHash.IDLE); initBox(); selectionBox.gameObject.SetActive(false); ResetTotalTime(); if (npcConversation != null) { if (npcConversation.isRandomConversation) { nextSentence = new Queue <char>(npcConversation.GetRandomSentence()); } else { npcConversation.ResetIndex(); getNextSentence(); } } else { nextSentence = new Queue <char>("..."); } _currentConverseStatus = ConversationStatus.CONVERSE; }
private void OnGameOver() { if (mainObjectivesCompleted) { OpenWindow(objectiveFinishedWindow, LevelPassedConversation); } else { // Instantiate a copy of the restart conversation and say it GameManager gameManager = GameManager.Instance; NPCConversation restartConversation = gameManager.LevelData.RestartConversation.InstantiateAndSay(); gameManager.m_dialogueManager.StartInteractiveConversation(); // When the conversation ends then show the fail window restartConversation.OnConversationEnded(() => { OpenWindow(failWindow, () => LevelDataLoader.ReloadLevel(), () => SceneManager.LoadScene("LevelMenu")); }); } }
public static NPCConversation InstantiateAndSay(this NPCConversation conversation) { NPCConversation copyConversation = Object.Instantiate(conversation); // If instantiation is successful then try to say the conversation if (copyConversation) { // Try to get the game manager GameManager gameManager = GameManager.Instance; // If game manager exists then try to get the dialogue manager if (gameManager) { DialogueManager dialogueManager = gameManager.m_dialogueManager; // If dialogue manager exists then say the copied conversation if (dialogueManager) { dialogueManager.SetNewDialogue(copyConversation); } else { Debug.Log($"Cannot say conversation {copyConversation} " + $"because instance of {nameof(GameManager)} " + $"has no {nameof(DialogueManager)}"); } } else { Debug.Log($"Cannot say conversation {copyConversation} " + $"because no instance of {nameof(GameManager)} could be found"); } return(copyConversation); } else { Debug.Log($"Failed to instantiate conversation {conversation}"); return(null); } }
private void confirmSelection() { if (_currentConverseStatus != ConversationStatus.SELECTION) { return; } NPCSelection selection = npcSelections[currentSelection]; npcConversation = selection.conversation; if (npcConversation != null) { npcConversation.ResetIndex(); } selectionBox.gameObject.SetActive(false); _currentConverseStatus = ConversationStatus.EMPTY; OnInteraction(); }
private EditableSpeechNode CreateSpeechNode(NPCConversation conversation, EditableConversation editableConversation, string text, float xPos, float yPos, bool isRoot, UnityAction callback) { // Create a new speech node EditableSpeechNode speechNode = new EditableSpeechNode() { Text = text, Name = npcName, Icon = npcIcon, TMPFont = npcFont, ID = conversation.CurrentIDCounter, EditorInfo = new EditableConversationNode.EditorArgs() { xPos = xPos, yPos = yPos, isRoot = isRoot } }; // Setup the node event. NodeEventHolder nodeEvent = conversation.GetNodeData(conversation.CurrentIDCounter); nodeEvent.Icon = npcIcon; nodeEvent.TMPFont = npcFont; // If the callback is not null that add it to the event if (callback != null) { nodeEvent.Event.AddListener(callback); } // Add this to the list of speech nodes editableConversation.SpeechNodes.Add(speechNode); // Update the counter conversation.CurrentIDCounter++; // Return the speech node return(speechNode); }
private EditableOptionNode CreateOptionNode(NPCConversation conversation, EditableConversation editableConversation, string text, float xPos, float yPos) { // Create a new option node with the same label as the quiz option EditableOptionNode optionNode = new EditableOptionNode() { Text = text, TMPFont = npcFont, ID = conversation.CurrentIDCounter, EditorInfo = new EditableConversationNode.EditorArgs() { xPos = xPos, yPos = yPos } }; // Add this option node to the editable conversation editableConversation.Options.Add(optionNode); // Update the current id conversation.CurrentIDCounter++; // Return the new node return(optionNode); }
/// <summary> /// Initialize stuffs here /// </summary> public void Initialize() { startingConversation = GameManager.Instance.LevelData.StartingConversation; defaultConversation = GameManager.Instance.LevelData.DefaultConversation; ConversationManager.OnConversationEnded += ConversationEnded; if (this.startingConversation != null) { currentDialogue = this.startingConversation; } else { UpdateCurrentDialogue(); } if (ConversationManager.Instance != null && !skipOpeningConversation) { StartNewConversation(); currentDialogue.OnConversationEnded(IntroFinished); //Allow for conversation skipping if intro has already been finished if(SaveData.LatestLevelIntroFinished >= LevelID.Current()) { ConversationManager.Instance.SetSkipConversationButton(true); } } }
protected void SetConvoTasks(NPCConversation convo) { _tasksToDo.Clear(); CheckWithinDistanceOfEachOther(); CheckWaitForPlayer(); foreach (Dialogue textToSay in convo.dialogueList) { if (textToSay._npc == 1) { chatInfo = new ChatInfo(_toManage, textToSay._TextToSay); chatInfoList = new List<ChatInfo>(); chatInfoList.Add(chatInfo); chatToPerform = new NPCChat(chatInfoList); Add(new ConvoTask(new Task(new NPCConvoState((Character)_toManage, (Character)_npcTwo, chatToPerform)), new Task(new IdleState(_npcTwo)))); } else { chatInfo = new ChatInfo(_npcTwo, textToSay._TextToSay); chatInfoList = new List<ChatInfo>(); chatInfoList.Add(chatInfo); chatToPerform = new NPCChat(chatInfoList); Add(new ConvoTask(new Task(new IdleState(_toManage)), new Task(new NPCConvoState((Character)_npcTwo, (Character)_toManage, chatToPerform)))); } } }
public NPCConversation Create(DialogueManager dialogueManager) { // Build a new quiz. This will result in regenerating new questions from any randomized pools GenerateQuizInstance(); // Create the callback that is called after any option is answered UnityAction OptionSelectedFunctor(int questionIndex, int optionIndex) { return(() => currentQuiz.AnswerQuestion(questionIndex, optionIndex)); } // Say the conversation that corresponds to the grade that the player got on the quiz void SayResponse() { // Destroy any previous response if (currentResponse) { Destroy(currentResponse); } // Instantiate a new response currentResponse = response.Get(CurrentQuiz.Grade).InstantiateAndSay(); // If we should requiz when we fail, then we must say the quiz after the response if (requizOnFail && CurrentQuiz.Grade != QuizGrade.Excellent) { SayQuizConversationNext(); } // If we will not requiz, then invoke my conversation ended event when this conversation is done else { // Set the quiz on the reports data to the quiz that we just finished GameManager.Instance.NotebookUI.Data.Reports.SetQuiz(LevelID.Current(), currentQuiz); // Invoke the quiz conversation ended event when the response is over currentResponse.OnConversationEnded(onConversationEnded.Invoke); } } // Try to get an npc conversation. If it exists, destroy it and add a new one NPCConversation conversation = gameObject.GetComponent <NPCConversation>(); if (conversation) { #if UNITY_EDITOR DestroyImmediate(conversation); #else Destroy(conversation); #endif } conversation = gameObject.AddComponent <NPCConversation>(); // Create the conversation to be edited here in the code EditableConversation editableConversation = new EditableConversation(); EditableSpeechNode previousSpeechNode = null; // A list of all nodes added to the conversation List <EditableConversationNode> nodes = new List <EditableConversationNode>(); // Loop over every question and add speech and option nodes for each for (int i = 0; i < currentQuiz.RuntimeTemplate.Questions.Length; i++) { // Cache the current question QuizQuestion question = currentQuiz.RuntimeTemplate.Questions[i]; // Create a new speech node EditableSpeechNode currentSpeechNode = CreateSpeechNode(conversation, editableConversation, question.Question, 0, i * 300, i == 0, null); nodes.Add(currentSpeechNode); // If a previous speech node exists, then make the options on the previous node // point to the speech on the current node if (previousSpeechNode != null) { foreach (EditableOptionNode option in previousSpeechNode.Options) { option.Speech.SetSpeech(currentSpeechNode); } } // Add an option node for each quiz option for (int j = 0; j < question.Options.Length; j++) { // Get the current option QuizOption option = question.Options[j]; // Create a new option node with the same label as the quiz option EditableOptionNode optionNode = CreateOptionNode(conversation, editableConversation, option.Label, j * 220, (i * 300) + 100); currentSpeechNode.AddOption(optionNode); nodes.Add(optionNode); // Create a dummy node. It is used to invoke events UnityAction optionCallback = OptionSelectedFunctor(i, j); EditableSpeechNode dummyNode = CreateSpeechNode(conversation, editableConversation, string.Empty, j * 220, (i * 300) + 200, false, optionCallback); nodes.Add(dummyNode); // Make the dummy node advance immediately dummyNode.AdvanceDialogueAutomatically = true; dummyNode.AutoAdvanceShouldDisplayOption = false; dummyNode.TimeUntilAdvance = 0f; // Make the option node point to the dummy node optionNode.SetSpeech(dummyNode); } // Update previous speech node to current before resuming previousSpeechNode = currentSpeechNode; } // Create the end of quiz node EditableSpeechNode endOfQuiz = CreateSpeechNode(conversation, editableConversation, endOfQuizText, 0, currentQuiz.RuntimeTemplate.Questions.Length * 300, false, SayResponse); nodes.Add(endOfQuiz); // If a previous speech node exists, // then make its options point to the end of quiz node if (previousSpeechNode != null) { foreach (EditableOptionNode option in previousSpeechNode.Options) { option.Speech.SetSpeech(endOfQuiz); } } // Have all the nodes register their UIDs (whatever the frick THAT means) foreach (EditableConversationNode node in nodes) { node.RegisterUIDs(); } // Serialize the editable conversation back into the NPCConversation and return the result conversation.RuntimeSave(editableConversation); return(conversation); }
public NPCConvoSchedule(NPC npcOne, NPC npcTwo, NPCConversation conversation) : base(npcOne) { Init(npcOne, npcTwo, conversation, Schedule.priorityEnum.Low); }
public NPCConvoSchedule(NPC npcOne, NPC npcTwo, NPCConversation conversation, bool dontWaitForPlayer) : base(npcOne) { Init(npcOne, npcTwo, conversation, Schedule.priorityEnum.Low); _waitForPlayer = (!dontWaitForPlayer); }
/// <summary> /// Inheriting members should use this method to end conversations /// </summary> /// <param name="conversation"></param> protected void EndConversation() { CurrentConversation = null; ConversationManager.Instance.EndConversation(); }
/// <summary> /// Inheriting members should use this method to start a conversation /// </summary> /// <param name="conversation"></param> protected void StartConversation(NPCConversation conversation) { CurrentConversation = conversation; ConversationManager.Instance.transform.position = transform.position + DialogBoxOffset; ConversationManager.Instance.StartConversation(conversation); }
public NPCConvoSchedule(NPC npcOne, NPC npcTwo, NPCConversation conversation, Enum priority) : base(npcOne, priority) { Init(npcOne, npcTwo, conversation, priority); }
public NPCConvoSchedule(NPC npcOne, NPC npcTwo, NPCConversation conversation, Enum priority, bool dontWaitForPlayer) : base(npcOne, priority) { _waitForPlayer = (!dontWaitForPlayer); Init(npcOne, npcTwo, conversation, priority); }
public void OnValidate() { if (text == null || !tryParseConversation) { return; } tryParseConversation = false; // try parsing once GameObject gameObject = new GameObject("New Conversation"); gameObject.transform.parent = transform; NPCConversation NPCConversation = gameObject.AddComponent <NPCConversation>(); // Load in id and icon info Dictionary <string, Sprite> idToIconDictionary = new Dictionary <string, Sprite>(); if (iconIDInput.Length > 0) { foreach (var pair in iconIDInput) { idToIconDictionary.Add(pair.id, pair.icon); } } // Preprocess string toParse = text.text; EditableConversation conversation = new EditableConversation(); string[] nodeTexts = toParse.Split('\n'); // Initialize root node EditableSpeechNode root = new EditableSpeechNode(); root.Text = nodeTexts[0].Substring(nodeTexts[0].IndexOf(':', 1) + 1).Trim(); root.Name = defaultName; root.Icon = defaultIcon; string iconID = nodeTexts[0].Substring(1, nodeTexts[0].IndexOf(':', 1) - 1); if (idToIconDictionary.ContainsKey(iconID)) { root.Icon = idToIconDictionary[iconID]; NPCConversation.GetNodeData(NPCConversation.CurrentIDCounter).Icon = root.Icon; } root.ID = NPCConversation.CurrentIDCounter++; root.TMPFont = defaultFont; root.EditorInfo.isRoot = true; conversation.SpeechNodes.Add(root); bool previousNodeIsSpeech = true; EditableSpeechNode previousSpeech = root; List <EditableOptionNode> previousOptions = new List <EditableOptionNode>(); List <EditableConversationNode> nodes = new List <EditableConversationNode>(); nodes.Add(root); for (int i = 1; i < nodeTexts.Length; i++) { string currentText = nodeTexts[i]; if (currentText.Length == 0) { continue; } EditableConversationNode node; // First char is a colon, this is a speech if (currentText[0] == ':') { EditableSpeechNode speechNode = new EditableSpeechNode(); speechNode.Name = defaultName; // text enclosed by colons is id of the icon iconID = currentText.Substring(1, currentText.IndexOf(':', 1) - 1); if (idToIconDictionary.ContainsKey(iconID)) { speechNode.Icon = idToIconDictionary[iconID]; NPCConversation.GetNodeData(NPCConversation.CurrentIDCounter).Icon = speechNode.Icon; } else { // unknown id speechNode.Icon = defaultIcon; } // connect previous nodes to speech if (previousNodeIsSpeech) { speechNode.parents.Add(previousSpeech); previousSpeech.SetSpeech(speechNode); } else { // Connect previous immediate options to node foreach (var option in previousOptions) { speechNode.parents.Add(option); option.SetSpeech(speechNode); } previousOptions.Clear(); } previousNodeIsSpeech = true; previousSpeech = speechNode; conversation.SpeechNodes.Add(speechNode); node = speechNode; } else { EditableOptionNode optionNode = new EditableOptionNode(); optionNode.parents.Add(previousSpeech); previousSpeech.AddOption(optionNode); previousNodeIsSpeech = false; previousOptions.Add(optionNode); conversation.Options.Add(optionNode); node = optionNode; } // Common info node.EditorInfo.yPos = 100 * i; node.Text = currentText.Substring(currentText.IndexOf(':', 1) + 1).Trim(); node.TMPFont = defaultFont; node.ID = NPCConversation.CurrentIDCounter++; nodes.Add(node); } foreach (EditableConversationNode node in nodes) { node.RegisterUIDs(); } NPCConversation.Serialize(conversation); }
protected override void Start() { base.Start(); _currentConversation = conversation; alreadyTalkedConversation.DefaultName = conversation.DefaultName; }
protected void Init(NPC npcOne, NPC npcTwo, NPCConversation conversation, Enum priority) { convoTasksToDo = new Queue<ConvoTask>(); _npcTwo = npcTwo; SetConvoTasks(conversation); }