public static DialogueSection Load(Dictionary <string, object> JSON, DialogueSection defaults = null) { DialogueSection newObject; if (defaults == null) { newObject = new DialogueSection(); } else { newObject = defaults.MemberwiseClone() as DialogueSection; } if (JSON.ContainsKey("portraitSettings")) { newObject.portraitSettings = DialoguePortraitSettings.Load(JSON["portraitSettings"] as Dictionary <string, object>, defaults.portraitSettings); } if (JSON.ContainsKey("textSettings")) { newObject.textSettings = DialogueTextSettings.Load(JSON["textSettings"] as Dictionary <string, object>, defaults.textSettings); } if (JSON.ContainsKey("triggerAnimation")) { newObject.triggerAnimation = JSON["triggerAnimation"] as string; } if (JSON.ContainsKey("triggerEffect")) { newObject.triggerEffect = JSON["triggerEffect"] as string; } if (JSON.ContainsKey("forceIdle")) { newObject.forceIdle = bool.Parse(JSON["forceIdle"] as string); } if (JSON.ContainsKey("text")) { newObject.text = new StringBuilder(JSON["text"] as string); } if (newObject.portraitSettings == null) { Debug.LogError("portraitSettings is null in DialogueSection"); } if (newObject.textSettings == null) { Debug.LogError("textSettings is null in DialogueSection"); } return(newObject); }
// ******************************************************************** private IEnumerator DisplaySection() { Debug.Log("Dispaying section " + m_sectionIndex + " out of " + m_currentFrame.sections.Count); // Initialize stuff for new section m_currentSection = m_currentFrame.sections[m_sectionIndex]; m_displayIndex = 0; LogManager.Log("DialoguePanel: DisplaySection " + m_currentSection.text, LogCategory.UI, LogSeverity.LOG, "Dialogue", gameObject); m_currentTextSettings = new DialogueTextSettings(); m_currentTextSettings.Merge(m_currentFrame.character.textSettings); m_currentTextSettings.Merge(m_currentSection.textSettings); Dictionary <char, float> textSymbolTime = new Dictionary <char, float>(); // Get settings from character for (int i = 0; i < m_currentTextSettings.textSymbolTime.Count; ++i) { textSymbolTime[m_currentTextSettings.textSymbolTime[i].symbol] = m_currentTextSettings.textSymbolTime[i].time; } // Print text until we're done if (m_currentSection.text != null) { float textSpeed = m_defaultTextSpeed * m_currentTextSettings.textSpeed; float secondsToWait = 1.0f / textSpeed; int side = -1; string currentSpecial = ""; if (m_currentFrame.character.portrait != null) { side = (int)m_currentFrame.portraitSide; // Set portrait emotion m_characterAnimator[side].SetInteger("Emotion", (int)m_currentSection.emotion); // Set special animation triggers if (m_currentSection.triggerAnimation > 0) { currentSpecial = "Special-" + m_currentSection.triggerAnimation; m_characterAnimator[side].SetTrigger("Special-" + m_currentSection.triggerAnimation); } else { // Set portrait to talking animation ONLY if no special animation is playing. m_characterAnimator[side].SetBool("Talk", true); } } while (m_displayIndex < m_currentSection.text.Length) { char currentChar = m_currentSection.text[m_displayIndex]; float currentSecondsToWait = secondsToWait; if (textSymbolTime.ContainsKey(currentChar)) { currentSecondsToWait = textSymbolTime[currentChar]; } // if we were playing a special animation, see if it is time to start the talk animation if (!currentSpecial.NullOrEmpty()) { if (!m_characterAnimator[side].GetCurrentAnimatorStateInfo(1).IsName(currentSpecial)) { currentSpecial = ""; m_characterAnimator[side].SetBool("Talk", true); } } PrintText(); if (!m_shouldSkip) { yield return(new WaitForSeconds(currentSecondsToWait)); } } // Set portrait to idle animation if (m_currentFrame.character.portrait != null) { side = (int)m_currentFrame.portraitSide; m_characterAnimator[side].SetBool("Talk", false); } } // TODO: Wait for animation to finish if we triggered a special animation. // TODO: Some kind of manual "wait" system? (for cutscenes) // Load next section m_previousSections += m_currentSection.text; ++m_sectionIndex; if (m_sectionIndex < m_currentFrame.sections.Count) { StartCoroutine(DisplaySection()); } else { m_shouldSkip = false; if (m_currentFrame.displayChoices) { m_waitingForChoiceInput = true; List <int> validLinks = new List <int>(); for (int i = 0; i < m_currentFrame.links.Count; ++i) { if (m_currentFrame.links[i].MeetsConditions()) { validLinks.Add(i); } } //Debug.Log("Choices found for frame " + m_currentFrame.id + ": " + validLinks.Count); for (int i = 0; i < validLinks.Count; ++i) { int index = validLinks[i]; DialogueLink link = m_currentFrame.links[index]; //Debug.Log("Creating button for " + index + " link frame: " + link.linkedFrame.name); GameObject choiceButton = GameObject.Instantiate(m_choiceButtonPrototype) as GameObject; choiceButton.transform.SetParent(m_choiceRoot.transform); if (i == 0 && InputManager.controlScheme == ControlScheme.GAMEPAD) { firstSelected = choiceButton.GetComponentInChildren <Button>(); SelectButton(firstSelected); } // Setup button ButtonSetup setup = choiceButton.GetComponent <ButtonSetup>(); setup.SetText(link.text); setup.SetIcon(link.icon); if (link.animation) { setup.SetAnimation(link.animation); } AddListenerForChoice(choiceButton.transform.GetComponentInChildren <Button>(), link); m_choices.Add(choiceButton.GetComponent <Animator>()); } StartCoroutine(ShowChoices(true)); } else { LogManager.Log("DialoguePanel: Setting m_waitingForNextFrame = true for " + m_currentFrame, LogCategory.UI, LogSeverity.LOG, "Dialogue", gameObject); m_waitingForNextFrame = true; m_waitingIcon.SetActive(true); } } yield return(null); }
public static DialogueFrame Load(Dictionary <string, object> JSON, DialogueFrame defaults = null) { DialogueFrame newObject; if (defaults == null) { newObject = new DialogueFrame(); } else { newObject = defaults.MemberwiseClone() as DialogueFrame; } if (JSON.ContainsKey("id")) { newObject.id = JSON["id"] as string; } // Links if (JSON.ContainsKey("endOnThisFrame")) { newObject.endOnThisFrame = bool.Parse(JSON["endOnThisFrame"].ToString()); } if (JSON.ContainsKey("displayChoices")) { newObject.displayChoices = bool.Parse(JSON["displayChoices"].ToString()); } if (JSON.ContainsKey("links")) { newObject.links = new List <DialogueLink>(); List <object> lList = JSON["links"] as List <object>; foreach (object lEntry in lList) { DialogueLink newLink = DialogueLink.Load(lEntry as Dictionary <string, object>); newObject.links.Add(newLink); } } // Load NPC Settings if (JSON.ContainsKey("npcSettings")) { DialogueNPCSettings npcSettings = DialogueManager.FetchNPCSettings(JSON["npcSettings"] as string); if (npcSettings != null) { Debug.Log("NPC Settings fetched for: " + JSON["npcSettings"] + " - " + npcSettings); if (npcSettings.portraitSettings != null) { newObject.portraitSettings = npcSettings.portraitSettings.ShallowCopy(); } if (npcSettings.textSettings != null) { newObject.textSettings = npcSettings.textSettings.ShallowCopy(); } } else { Debug.LogError("NPC Settings NOT FOUND for: " + JSON["npcSettings"]); } } // Overrides if (JSON.ContainsKey("allowSkip")) { newObject.allowSkip = bool.Parse(JSON["allowSkip"] as string); } if (JSON.ContainsKey("waitForInput")) { newObject.waitForInput = bool.Parse(JSON["waitForInput"] as string); } if (JSON.ContainsKey("portraitSettings")) { newObject.portraitSettings = DialoguePortraitSettings.Load(JSON["portraitSettings"] as Dictionary <string, object>, newObject.portraitSettings); } if (JSON.ContainsKey("textSettings")) { newObject.textSettings = DialogueTextSettings.Load(JSON["textSettings"] as Dictionary <string, object>, newObject.textSettings); } // Sections if (JSON.ContainsKey("sections")) { newObject.sections = new List <DialogueSection>(); DialogueSection defaultSection = new DialogueSection(); defaultSection.portraitSettings = newObject.portraitSettings; defaultSection.textSettings = newObject.textSettings; List <object> sList = JSON["sections"] as List <object>; foreach (object sEntry in sList) { DialogueSection newSection = DialogueSection.Load(sEntry as Dictionary <string, object>, defaultSection); newObject.sections.Add(newSection); } Debug.Log("Frame " + newObject.id + " loaded " + newObject.sections.Count + " sections"); } if (newObject.portraitSettings == null) { Debug.LogError("portraitSettings is null in DialogueFrame"); } if (newObject.textSettings == null) { Debug.LogError("textSettings is null in DialogueFrame"); } return(newObject); }
// ******************************************************************** // Function: DisplaySection() // Purpose: Performs actions described in a section // ******************************************************************** private IEnumerator DisplaySection() { // Initialize stuff for new section m_currentSection = m_currentFrame.sections[m_sectionIndex]; m_displayIndex = 0; // Set text settings DialogueTextSettings textSettings = m_currentSection.textSettings; if (textSettings.textAudio != m_audioClipName) { m_audioClipName = textSettings.textAudio; m_audioClip = Resources.Load(m_audioClipPath + m_audioClipName) as AudioClip; m_audioSource.clip = m_audioClip; } // TODO: Set portrait settings PrintText(); // Print text until we're done if (m_currentSection.text != null) { float textSpeed = m_defaultTextSpeed * textSettings.textSpeed; float secondsToWait = 1.0f / textSpeed; while (m_displayIndex < m_currentSection.text.Length) { if (!m_shouldSkip) { yield return(new WaitForSeconds(secondsToWait)); } //yield return new WaitForSeconds(1.0f / (m_defaultTextSpeed*m_currentSection.textSettings.textSpeed)); PrintText(); } } // TODO: Trigger special animations and effects // TODO: Wait for animation to finish if we triggered a special animation. // TODO: Some kind of manual "wait" system? (for cutscenes) // Load next section ++m_sectionIndex; if (m_sectionIndex < m_currentFrame.sections.Count) { StartCoroutine(DisplaySection()); } else { // TODO: Bring up choices if applicable m_shouldSkip = false; if (m_currentFrame.displayChoices) { m_waitingForChoiceInput = true; List <int> validLinks = new List <int>(); for (int i = 0; i < m_currentFrame.links.Count; ++i) { if (m_currentFrame.links[i].MeetsRequirements(ProfileManager.profile)) { validLinks.Add(i); } } Debug.Log("Choices found for frame " + m_currentFrame.id + ": " + validLinks.Count); for (int i = 0; i < validLinks.Count; ++i) { int index = validLinks[i]; DialogueLink link = m_currentFrame.links[index]; Debug.Log("Creating button for " + index + " link conv: " + link.linkedConversation + " frame: " + link.linkedFrame); GameObject choiceButton = GameObject.Instantiate(m_choiceButtonPrototype) as GameObject; choiceButton.transform.SetParent(m_choiceRoot.transform); choiceButton.GetComponentInChildren <Text>().text = link.text; AddListenerForChoice(choiceButton.GetComponent <Button>(), index); m_choices.Add(choiceButton.GetComponent <Animator>()); } StartCoroutine(HideChoices(false)); } else { m_waitingForNextFrame = true; m_waitingIcon.SetActive(true); } } yield return(null); }
void TypeSentence(DialogueSection ds) { targetText.text = ""; currentDialog = ds; currentLetterIndex = 0; }