bool TryGetValue(string key, out DialogueInstance value) { value = null; if (key.StartsWith(DefaultChar)) { return(manager.defaultMap.TryGetValue(key.Substring(1), out value)); } return(_instances.TryGetValue(key, out value)); }
void Set(string key, DialogueInstance value) { if (key.StartsWith(DefaultChar)) { manager.defaultMap.Set(key.Substring(1), value); } else { _instances[key] = value; } }
/// <summary> /// Load the Characters XML Node from the Dialogue Script /// </summary> public void LoadCharacters(XmlNode _node, DialogueInstance _dialogueInstance) { foreach (XmlNode characterNode in _node.ChildNodes) { if (characterNode.Name == "DialogueCharacter") { //Load Values string id = characterNode.Attributes["id"].Value; CharacterItem characterItem = new CharacterItem(id); if (customStringSavingManager != null) { characterItem.printName = customStringSavingManager.FixString(characterNode.Attributes["name"].Value); } else { characterItem.printName = characterNode.Attributes["name"].Value; } if (characterNode.Attributes["resource"] != null) { characterItem.prefabResource = characterNode.Attributes["resource"].Value; } if (characterNode.Attributes["gibber"] != null) { characterItem.gibberResource = characterNode.Attributes["gibber"].Value; } //Load Resources if (characterItem.prefabResource != "") { characterItem.prefab = Resources.Load <GameObject>("Dialogue/CharacterPrefabs/" + characterItem.prefabResource); } if (characterItem.gibberResource != "") { characterItem.gibberNoise = Resources.Load <AudioClip>("Dialogue/SFX/" + characterItem.gibberResource); } _dialogueInstance.currentCharacters.Add(id, characterItem); //Debug string logPrint = "Loaded " + characterItem.printName; logPrint += ": " + ((characterItem.prefab != null) ? characterItem.prefabResource : "{NO PREFAB}"); logPrint += ": " + ((characterItem.gibberNoise != null) ? characterItem.gibberResource : "{NO GIBBER}"); Debug.Log(logPrint); } } }
public bool HasDialogueFlag(DialogueInstance instance) { return(usedMap.Contains(instance)); }
public void StoreDialogueFlag(DialogueInstance instance) { usedMap.Add(instance); }
public static void ActivateDialogue(DialogueInstance instance) { ActiveInstance = instance; instance.StartDialogue(); GroupManager.main.activeGroup = GroupManager.main.group["Dialogue"]; }
/// <summary> /// Load the a Dialogue Script from an XML File /// </summary> public DialogueInstance LoadDialogue(string _fileName) { TextAsset textAsset = Resources.Load <TextAsset>("Dialogue/" + _fileName); if (textAsset == null) { throw new Exception("Dialogue file \"Dialogue/" + _fileName + "\" dosen't exist."); } XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(textAsset.text); DialogueInstance dialogueInstance = new DialogueInstance(); saveDataManager = FindObjectOfType <SaveDataManager>(); customStringSavingManager = FindObjectOfType <CustomStringSavingManager>(); float startTime = Time.realtimeSinceStartup; Debug.Log("Started loading " + _fileName); //Setup inital variables bool loadedCharacters = false, loadedDialogue = false; foreach (XmlNode xmlNode in xmldoc.DocumentElement.ChildNodes) { //Load the Main Groups (i.e. Characters / Dialogue) switch (xmlNode.Name) { case "Characters": { Debug.Log("Loading Group: " + xmlNode.Name); if (!loadedCharacters) { loadedCharacters = true; LoadCharacters(xmlNode, dialogueInstance); } else { throw new Exception("Characters have already been loaded!"); } break; } case "Dialogue": { Debug.Log("Loading Group: " + xmlNode.Name); if (!loadedDialogue) { loadedDialogue = true; LoadDialogue(xmlNode, dialogueInstance); } else { throw new Exception("Dialogue has already been loaded!"); } break; } } } Debug.Log("Finished loading " + _fileName + " in " + (Time.realtimeSinceStartup - startTime).ToString() + " seconds."); return(dialogueInstance); }
/// <summary> /// Load the Dialogue XML Node from the Dialogue Script /// </summary> public void LoadDialogue(XmlNode _node, DialogueInstance _dialogueInstance) { foreach (XmlNode dialogueNode in _node.ChildNodes) { if (dialogueNode.Name == "Item") { if (!_dialogueInstance.currentDialogue.ContainsKey((_dialogueInstance.defaultDialogueCount + 1).ToString())) { //Load Speech SpeechItem speechItem = new SpeechItem(_dialogueInstance.defaultDialogueCount++); speechItem.characterID = dialogueNode.Attributes["speaker"].Value; if (dialogueNode.Attributes["audio"] != null) { speechItem.audioPrefabName = dialogueNode.Attributes["audio"].Value; speechItem.audioPrefab = Resources.Load <AudioClip>("Dialogue/SFX/" + speechItem.audioPrefabName); } if (dialogueNode.Attributes["music"] != null) { speechItem.musicClipName = dialogueNode.Attributes["music"].Value; speechItem.musicClip = Resources.Load <AudioClip>("Dialogue/Music/" + speechItem.musicClipName); } if (dialogueNode.Attributes["speed"] != null) { speechItem.customSpeed = float.Parse(dialogueNode.Attributes["speed"].Value); } else { speechItem.customSpeed = 1f; } if (dialogueNode.Attributes["size"] != null) { speechItem.customSize = float.Parse(dialogueNode.Attributes["size"].Value); //Debug.Log("Loading #" + id + ": Size Parameter " + speechItem.customSize); } else { speechItem.customSize = 1f; } if (dialogueNode.Attributes["requireinput"] != null) { speechItem.requiresInput = bool.Parse(dialogueNode.Attributes["requireinput"].Value); } else { speechItem.requiresInput = true; } if (dialogueNode.Attributes["animation"] != null) { string[] animationParamStrings = dialogueNode.Attributes["animation"].Value.Split(':'); string animationName = animationParamStrings[0]; List <object> parameters = new List <object>(); if (animationParamStrings.Length > 1) { for (int j = 1; j < animationParamStrings.Length; j++) { string paramToParse = animationParamStrings[j]; List <string> readIn = new List <string>(); string current = ""; for (int i = 0; i < paramToParse.Length; i++) { if (paramToParse[i] == '(' || paramToParse[i] == ')' || paramToParse[i] == ',') { readIn.Add(current); current = ""; } else { current += paramToParse[i]; } } switch (readIn[0]) { case "int": parameters.Add(int.Parse(readIn[1])); break; case "float": parameters.Add(float.Parse(readIn[1])); break; case "vec2": parameters.Add(new Vector2(float.Parse(readIn[1]), float.Parse(readIn[2]))); break; case "vec3": parameters.Add(new Vector3(float.Parse(readIn[1]), float.Parse(readIn[2]), float.Parse(readIn[3]))); break; default: Debug.LogError("Dialogue #" + (_dialogueInstance.defaultDialogueCount + 1).ToString() + " has a broken animation param"); continue; } } } speechItem.animationName = animationName; speechItem.animationParams = parameters.Count > 0 ? parameters.ToArray() : null; } else { speechItem.animationName = null; } //Read in Text if (dialogueNode.Attributes["text"] != null) { //TO DO //- Run through Translation Manager string originalText = dialogueNode.Attributes["text"].Value.Replace("\\n", "\n"); if (customStringSavingManager != null) { originalText = customStringSavingManager.FixString(originalText); } string finalFormattedText = ""; string finalReadText = ""; List <Dictionary <Effect.EffectType, Effect> > effects = new List <Dictionary <Effect.EffectType, Effect> >(); Dictionary <Effect.EffectType, Effect> currentEffectStack = new Dictionary <Effect.EffectType, Effect>(); if (!ReadInString(originalText, 0, currentEffectStack, ref effects, ref finalFormattedText, ref finalReadText)) { Debug.LogError("Dialogue #" + (_dialogueInstance.defaultDialogueCount + 1).ToString()); continue; } speechItem.skipText = false; speechItem.finalFormattedText = finalFormattedText; speechItem.finalReadText = finalReadText; //Send Effects to Speech Item speechItem.textEffects = effects; } else { speechItem.skipText = true; } _dialogueInstance.currentDialogue.Add(speechItem.id.ToString(), speechItem); } else { Debug.LogError("Dialogue #" + (_dialogueInstance.defaultDialogueCount + 1).ToString() + "has already been declared"); } } } }