// Initializes the conversation // Returns true on success public bool initialize(AdvancedDialogue _dialog) { // Local variables DynamicScript script = null; int id = 0; // Define function: enabled if (m_funcValueStartTextID == null || m_funcValueStartTextID.Length == 0) { m_funcGetStartTextID = null; } else if (System.Int32.TryParse(m_funcValueStartTextID, out id) == true) { m_funcGetStartTextID = new System.Func <int>(() => { return(id); }); } else { // Try to get script if (_dialog.DynamicScripts.ContainsKey(m_funcValueStartTextID) == false) { return(false); } script = _dialog.DynamicScripts[m_funcValueStartTextID]; m_funcGetStartTextID = new System.Func <int>(() => { object v = null; Game.Instance.ScriptEngine.executeScript(script, ref v); return((System.Int32)v); }); } return(true); }
// Initializes the text // Returns true on success public bool initialize(AdvancedDialogue _dialog) { // Define function: show parts if (m_funcValuShowParts == null || m_funcValuShowParts.Length == 0) { m_funcShowParts = new System.Func <bool>(() => { return(true); }); } else if (m_funcValuShowParts.Equals("0") || m_funcValuShowParts.Equals("1")) { m_funcShowParts = new System.Func <bool>(() => { return(m_funcValuShowParts.Equals("0") == true ? false : true); }); } else { // Try to get script if (_dialog.DynamicScripts.ContainsKey(m_funcValuShowParts) == false) { return(false); } m_funcShowParts = new System.Func <bool>(() => { bool v = false; Game.Instance.ScriptEngine.executeScript <bool>(_dialog.DynamicScripts[m_funcValuShowParts], ref v); return(v); }); } return(true); }
// Override: FSMState::Awake() protected override void Awake() { // Call parent base.Awake(); // Text to display? if (m_textSource == null) { Debug.LogError("Invalid text FSM-state (" + gameObject.name + "). No text has been set!"); return; } // Parse dialog m_dialogue = AdvancedDialogueParser.parseDialog(m_textSource.text); if (m_dialogue == null || m_dialogue.Valid == false) { Debug.LogError("Invalid text FSM-state (" + gameObject.name + "). Text data is invalid!"); return; } }
// Initializes the choice // Returns true on success public bool initialize(AdvancedDialogue _dialog) { // Local variables DynamicScript script = null; int id = 0; // Define function: enabled if (m_funcValueEnabled == null || m_funcValueEnabled.Length == 0) { m_funcIsEnabled = new System.Func <bool>(() => { return(true); }); } else if (m_funcValueEnabled.Equals("0") || m_funcValueEnabled.Equals("1")) { m_funcIsEnabled = new System.Func <bool>(() => { return(m_funcValueEnabled.Equals("0") == true ? false : true); }); } else { // Try to get script if (_dialog.DynamicScripts.ContainsKey(m_funcValueEnabled) == false) { return(false); } m_funcIsEnabled = new System.Func <bool>(() => { bool v = false; Game.Instance.ScriptEngine.executeScript <bool>(_dialog.DynamicScripts[m_funcValueEnabled], ref v); return(v); }); } // Define function: next text ID if (m_choiceType == ChoiceType.CHOICE_NEXT_TEXT) { if (m_funcValueNextTextID == null || m_funcValueNextTextID.Length == 0) { Debug.LogError("Choice with \"next text\" identifiers need an valid ID!"); return(false); } else if (System.Int32.TryParse(m_funcValueNextTextID, out id) == true) { m_funcNextTextID = new System.Func <int>(() => { return(id); }); } else { // Try to get script if (_dialog.DynamicScripts.ContainsKey(m_funcValueNextTextID) == false) { Debug.LogError("Choice with \"next text\" identifiers need an valid ID!"); return(false); } m_funcNextTextID = new System.Func <int>(() => { object v = null; Game.Instance.ScriptEngine.executeScript(_dialog.DynamicScripts[m_funcValueNextTextID], ref v); return((System.Int32)v); }); // Set flag m_isNextTextIDFunc = true; } } // Resolve script references if (m_scriptReferences != null && m_scriptReferences.Count > 0) { // Loop through references foreach (DynamicScriptRef r in m_scriptReferences) { // Get script if (_dialog.DynamicScripts.ContainsKey(r.ScriptName) == false) { Debug.LogError("Referenced script(" + r.ScriptName + ") is not available!"); continue; } script = _dialog.DynamicScripts[r.ScriptName]; // Choose run-time if (r.Runtime.Equals("onClick") == true) { m_scriptListOnClick.Add(script); } else { Debug.LogError("Unsupported run-time(" + r.Runtime + ") for the script reference in a choice!"); continue; } } } return(true); }
// Parses an input stream in form of a string public static AdvancedDialogue parseDialog(string _text) { // Local variables AdvancedDialogue dialogue = null; XmlDocument xmlDoc = null; XmlNode xmlNode = null; XmlNode xmlNodeAtt = null; string overrideStartConversationID = ""; Conversation conv = null; DynamicScript dynscript = null; List <Conversation> convList = new List <Conversation>(); List <DynamicScript> dynscriptList = new List <DynamicScript>(); // Check parameter if (_text == null || _text.Length == 0) { Debug.LogError("Empty input!"); return(null); } // Open XML document xmlDoc = new XmlDocument(); xmlDoc.LoadXml(_text); // Get first node (bw) xmlNode = xmlDoc.SelectSingleNode("bw"); if (xmlNode == null) { Debug.LogError("Invalid XML format!"); return(null); } // Get attribute: override start conversation ID xmlNodeAtt = xmlNode.Attributes.GetNamedItem("overrideStartConversationID"); if (xmlNodeAtt != null) { overrideStartConversationID = xmlNodeAtt.Value; } // Find first conversation or dynamic code node xmlNode = xmlNode.FirstChild; if (xmlNode == null) { Debug.LogError("No conversations or dynamic scripts has been found!"); return(null); } // Parse all conversations do { // Skipable? if (isNodeSkipable(xmlNode) == false) { // Dynamic scripts? if (xmlNode.Name.Equals("dynscript") == true) { // Parse dynscript = parseDynamicScript(xmlNode); if (dynscript == null) { return(null); } // Add to list dynscriptList.Add(dynscript); } // Conversation? else if (xmlNode.Name.Equals("conversation") == true) { // Parse conv = parseConversation(xmlNode); if (conv == null) { return(null); } // Add to list convList.Add(conv); } } // Next sibling xmlNode = xmlNode.NextSibling; }while (xmlNode != null); // Create dialogue dialogue = new AdvancedDialogue(dynscriptList, convList, overrideStartConversationID); return(dialogue); }