/** * Directly loads the data into the data fields in the current tab */ private void LoadXMLData() { Transform[] allChildren = transform.gameObject.GetComponentsInChildren <Transform>(true); XmlNode node = xmlDoc.FirstChild; while (node.Value == null && !node.InnerText.Equals("")) { //Debug.Log (node.Name); if (node.Name.Equals("EntryData")) { if (node.NextSibling != null) { node = node.NextSibling; } else { while (node.ParentNode.NextSibling == null) { node = node.ParentNode; } node = node.ParentNode.NextSibling; if (node == xmlDoc.DocumentElement.LastChild) { return; } } } node = AdvNode(node); if (node == null) { Debug.Log("No Data to load."); return; } } //Assign values in spaces bool addDialogue = false; bool addQuiz = false; bool addFlag = false; bool addEvent = false; foreach (Transform child in allChildren) { //Debug.Log("CHILD: " + child.name); if (node != null && (child.name.Equals(node.ParentNode.Name) || (child.name.Equals(node.Name) && node.InnerXml.Equals("")))) { try { if (node.Value != null) { if (child.gameObject.GetComponent <InputField>() != null) { child.gameObject.GetComponent <InputField>().text = UnityWebRequest.UnEscapeURL(node.Value); } else if (child.gameObject.GetComponent <Text>() != null) { child.gameObject.GetComponent <Text>().text = UnityWebRequest.UnEscapeURL(node.Value); } else if (child.gameObject.GetComponent <Dropdown>() != null) { int indexValue = 0; foreach (Dropdown.OptionData myOptionData in child.gameObject.GetComponent <Dropdown>().options) { if (myOptionData.text.Equals(UnityWebRequest.UnEscapeURL(node.Value))) { break; } indexValue++; } child.gameObject.GetComponent <Dropdown>().value = indexValue; } else if (child.gameObject.GetComponent <Toggle>() != null) { child.gameObject.GetComponent <Toggle>().isOn = bool.Parse(node.Value); //child.gameObject.GetComponent<Text>().text = WWW.UnEscapeURL(node.Value); } else if (child.gameObject.GetComponent <Text>() != null) { child.gameObject.GetComponent <Text>().text = UnityWebRequest.UnEscapeURL(node.Value); } } node = AdvNode(node); while (node != null && node.Value == null && !node.InnerText.Equals("")) { if (Regex.IsMatch(node.Name.ToLower(), "tab[0-9]*$")) { break; } if (node.Name.Equals("EntryData") || node.Name.Equals("DialoguePin") || node.Name.Equals("QuizPin") || node.Name.Equals("FlagPin") || (node.Name.Equals("EventPin"))) { findUID(node); // Find uid node and use it as the key if (node.Name.Equals("DialoguePin")) { addDialogue = true; ds.AddDialogue(uid, node.OuterXml); } if (node.Name.Equals("QuizPin")) { addQuiz = true; XmlNode tempNode = node; while (!tempNode.Name.Equals("Parent")) { tempNode = AdvNode(tempNode); } ds.AddQuiz(tempNode.InnerText, node.InnerXml); } if (node.Name.Equals("FlagPin")) { addFlag = true; ds.AddFlag(uid, node.OuterXml); } if (node.Name.Equals("EventPin")) { addEvent = true; } if (node.NextSibling != null) { node = node.NextSibling; } else { if (node == null) { break; } if (node == xmlDoc.DocumentElement.LastChild) { break; } node = node.ParentNode.NextSibling; } } else { node = AdvNode(node); } } } catch (Exception e) { Debug.Log(e.Message); } } if (child.name.Equals("PinArea")) { if (addDialogue) { GameObject pinObj = Resources.Load(GlobalData.resourcePath + "/Prefabs/DialoguePinIcon") as GameObject; pinObj = Instantiate(pinObj, child); Button b = pinObj.AddComponent <Button>(); b.onClick.AddListener(delegate { /*b.onClick.AddListener(delegate {*/ ButtonListenerFunctionsScript.OpenDialogueEditor(b); //}); //b.onClick.AddListener(delegate { ButtonListenerFunctionsScript.OpenDialogueEditor(b, instantiatePanel("DialogueEditorBG")); }); }); pinObj.tag = "Value"; pinObj.name = "Dialogue" + "Pin"; addDialogue = false; } if (addQuiz) { GameObject pinObj = Resources.Load(GlobalData.resourcePath + "/Prefabs/QuizPinIcon") as GameObject; pinObj = Instantiate(pinObj, child); Button b = pinObj.AddComponent <Button>(); b.onClick.AddListener(delegate { //ButtonListenerFunctionsScript.OpenQuizEditor(b); //Delegate d = b.onClick.GetPersistentEventCount(); //d.GetInvocationList(); /*b.onClick.AddListener(delegate { */ ButtonListenerFunctionsScript.OpenQuizEditor(b, instantiatePanel("QuizEditorBG")); //}); }); pinObj.tag = "Value"; pinObj.name = "Quiz" + "Pin"; addQuiz = false; } if (addFlag) { GameObject pinObj = Resources.Load(GlobalData.resourcePath + "/Prefabs/FlagPinIcon") as GameObject; pinObj = Instantiate(pinObj, child); Button b = pinObj.AddComponent <Button>(); b.onClick.AddListener(delegate { //ButtonListenerFunctionsScript.OpenFlagEditor(b); b.onClick.AddListener(delegate { ButtonListenerFunctionsScript.OpenFlagEditor(b, instantiatePanel("FlagEventEditorBG")); }); }); pinObj.tag = "Value"; pinObj.name = "Flag" + "Pin"; addFlag = false; } if (addEvent) { GameObject pinObj = Resources.Load(GlobalData.resourcePath + "/Prefabs/EventPinIcon") as GameObject; pinObj = Instantiate(pinObj, child); Button b = pinObj.AddComponent <Button>(); b.onClick.AddListener(delegate { ButtonListenerFunctionsScript.OpenEventEditor(b, instantiatePanel("EventEditorBG")); }); pinObj.tag = "Value"; pinObj.name = "Event" + "Pin"; addEvent = false; } } } }
/** * Adds the active tab to the dictionary */ public void AddToDictionary() { //GetSectionImages (); //If another tab has specified another AddToDictionary method, use that one if (MethodToCall != null) { MethodToCall(); if (!sameTab) { MethodToCall = null; } return; } else { if (currentTab == null) { return; } string xml = "<data>"; string imageData = "<images>"; int imgCount = 0; //string customName = ds.GetData (currentSection).getTabInfo (currentTab.name + currentTab.GetComponent<Text>().text).customName; //xml += "<customName>" + customName + "</customName><data>"; //Sets up the XML string to be passed into the dictionary allChildren = currentTab.GetComponentsInChildren <Transform>(); Transform nextChild = null; string UID = ""; foreach (Transform child in allChildren) { //Debug.Log(child.name); if (child != null) { if (child.tag.Equals("Image")) //Handle images { Sprite img = child.GetComponent <Image>().sprite; imageData += "<image" + imgCount + ">"; UID = child.GetComponent <OpenImageUploadPanelScript>().GetGuid(); imageData += "<key>" + UID + "</key>"; //imageData += "<key>" + currentSection + currentTab.transform.Find ("TabButtonLinkToText").GetComponent<Text>().text + "</key>"; string imgRef; if ((imgRef = ds.GetImage(currentSection + currentTab.transform.Find("TabButtonLinkToText").GetComponent <TextMeshProUGUI>().text).referenceName) != null) { imageData += imgRef; } else { imageData += "<width>" + img.texture.width + "</width><height>" + img.texture.height + "</height>"; Texture2D dictTexture = img.texture; Texture2D newTexture = new Texture2D(dictTexture.width, dictTexture.height, TextureFormat.ARGB32, false); newTexture.SetPixels(0, 0, dictTexture.width, dictTexture.height, dictTexture.GetPixels()); newTexture.Apply(); byte[] bytes = newTexture.EncodeToPNG(); string base64Data = Convert.ToBase64String(bytes); imageData += "<data>" + base64Data + "</data>"; } imageData += "</image" + imgCount + ">"; imgCount++; } else if (child.GetComponent <HistoryFieldManagerScript>() != null) { xml += child.GetComponent <HistoryFieldManagerScript>().getData(); Transform tempChild = child; while (nextChild == null) { if (tempChild.GetSiblingIndex() + 1 == tempChild.parent.childCount) { tempChild = tempChild.parent; } else { nextChild = tempChild.parent.GetChild(tempChild.GetSiblingIndex() + 1); } } } else if (nextChild == null && (child.name.ToLower().EndsWith("value") || child.name.ToLower().EndsWith("toggle") || child.tag.Equals("Value"))) //Input object/field { if (child.gameObject.GetComponent <Toggle>() != null) { if (true) // || child.gameObject.GetComponent<Toggle> ().isOn) { //Leaving as true for now. May change later { xml += "<" + child.name + ">"; xml += child.gameObject.GetComponent <Toggle>().isOn; xml += "</" + child.name + ">"; } } else if (child.name.ToLower().EndsWith("toggle") || child.name.ToLower().EndsWith("radio")) { continue; } else { xml += "<" + child.name + ">"; //Handle reading the child if (child.gameObject.GetComponent <InputField>() != null) { xml += UnityWebRequest.EscapeURL(child.gameObject.GetComponent <InputField>().text); } else if (child.gameObject.GetComponent <Text>() != null) { xml += UnityWebRequest.EscapeURL(child.gameObject.GetComponent <Text>().text); } else if (child.gameObject.GetComponent <Dropdown>() != null) { xml += UnityWebRequest.EscapeURL(child.gameObject.GetComponent <Dropdown>().captionText.text); } else if (child.name.Equals("DialoguePin") || child.name.Equals("QuizPin") || child.name.Equals("FlagPin") || child.name.Equals("EventPin")) { Transform uniqueParent = child; string path = ""; while (uniqueParent.parent != null && !uniqueParent.parent.name.Equals("Content")) { uniqueParent = uniqueParent.parent; } path = uniqueParent.name; while (!uniqueParent.name.EndsWith("Tab")) //Once you hit the Tab container { uniqueParent = uniqueParent.parent; path = uniqueParent.name + "/" + path; } path = getCurrentSection() + "/" + path; //If the dialogue entry has been moved, adjust the dictionary accordingly if (child.name.Equals("DialoguePin") && ds.GetDialogues().ContainsKey(path)) { string dialogueXML = ds.GetDialogues()[path]; //Dialogue data ds.AddDialogue(path, dialogueXML); xml += dialogueXML; } else if (child.name.Equals("DialoguePin")) { xml = xml.Substring(0, xml.Length - ("<" + child.name + ">").Length); continue; } //If the quiz entry has been moved, adjust the dictionary accordingly if (child.name.Equals("QuizPin") && ds.GetQuizes().ContainsKey(path)) { string quizXML = ds.GetQuizes()[path]; //Quiz data ds.AddQuiz(path, quizXML); xml += quizXML; } else if (child.name.Equals("QuizPin")) { xml = xml.Substring(0, xml.Length - ("<" + child.name + ">").Length); continue; } if (child.name.Equals("FlagPin") && ds.GetFlags().ContainsKey(path)) { string flagXML = ds.GetFlags()[path]; //Dialogue data ds.AddFlag(path, flagXML); xml += flagXML; } else if (child.name.Equals("FlagPin")) { xml = xml.Substring(0, xml.Length - ("<" + child.name + ">").Length); continue; } } xml += "</" + child.name + ">"; } } if (child == nextChild) { nextChild = null; } } } imageData += "</images>"; xml += "</data>"; //Add the current Tab to the Dictionary. Replace any existing tab if it exists if (ds == null) { ds = GameObject.Find("GaudyBG").GetComponentInChildren <DataScript>(); } //ds.AddData (currentSection, tabName, xml); ds.AddData(currentSection, currentTab.name.Substring(0, currentTab.name.Length - 3), xml); Debug.Log("Saved value: " + xml); } }