예제 #1
0
            /// <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);
            }
예제 #2
0
 private void Start()
 {
     customStringSavingManager = FindObjectOfType <CustomStringSavingManager>();
     saveDataManager           = FindObjectOfType <SaveDataManager>();
 }