/** * Pass in the Display Text */ private void AddTab(string tabName) { string prefabName = tabName + " Tab"; string tabCustomName = tabName; string xmlTabName = tabName.Replace(" ", "_") + "Tab"; string xml = "<data></data>"; //Debug.Log (gData.resourcesPath + "Prefabs/Tabs/" + prefabName + "/" + prefabName.Replace (" ", string.Empty)); GameObject test = Resources.Load(gData.resourcesPath + "/Prefabs/Tabs/" + prefabName + "/" + prefabName.Replace(" ", string.Empty)) as GameObject; if (test == null) { Debug.Log("Cannot load tab prefab"); return; } ds.AddData(tm.getCurrentSection(), xmlTabName, tabCustomName, xml); GameObject newTab = Resources.Load(gData.resourcesPath + "/Prefabs/TabButton") as GameObject; TextMeshProUGUI[] children = newTab.GetComponentsInChildren <TextMeshProUGUI> (); foreach (TextMeshProUGUI child in children) { if (child.name.Equals("TabButtonLinkToText")) //Where the button links to { child.text = xmlTabName; } else if (child.name.Equals("TabButtonDisplayText")) //What the button displays { child.text = tabCustomName; } } //The button's position newTab = Instantiate(newTab, tm.TabButtonContentPar.transform); newTab.name = tabCustomName.Replace(" ", "_") + "Button"; if (tabName.Equals("Background Info")) { newTab.transform.SetSiblingIndex(0); UpdateTabPos(); } }
/** * Adds a tab from the TabSelectorBG * Pass in the display name */ public void addTab(TextMeshProUGUI tabName) { /* * tabCustomName = tabName * xmlTabName = tabType * tabName.text = displayed name */ if (!ds.IsValidName(tabName.text, "Tab")) { //ds.ShowMessage("Tab name not valid. Cannot use:\n*, &, <, >, or //", true); ds.ShowMessage("Name not valid: Please rename your tab", true); throw new System.Exception("Name not valid: Please rename your tab"); } var tabTemplate = FindSelected(); if (tabTemplate == null) { ds.ShowMessage("A tab template must be selected.", true); throw new System.Exception("A tab template must be selected"); } string tabCustomName; List <string> tempTabList = ds.GetData(tm.getCurrentSection()).GetTabList(); //Do not remove last compare below. It's looking for a zero width space (unicode 8203 / Alt+200B) if (tabName.text == null || tabName.text.Equals("") || tabName.text.ToCharArray()[0].Equals(GlobalData.EMPTY_WIDTH_SPACE)) { tabCustomName = tabTemplate.text;//.Replace(" ", "_") + "Tab"; } else { if (tabToSpawn != null) { tabName.text = tabToSpawn.text; } tabCustomName = tabName.text;//.Replace(" ", "_") + "Tab"; } tabCustomName = tabCustomName.Replace(GlobalData.EMPTY_WIDTH_SPACE + "", ""); //Debug.Log(tabCustomName + "--------------"); //tabName = "Test History"; if (tempTabList.Contains(tabCustomName)) { ds.ShowMessage("Cannot name two tabs the same in one step!", true); throw new System.Exception("Cannot name two tabs the same in one step!"); } string selected = tabTemplate.text; string prefabName = selected; print("Selected: " + selected); System.IO.StreamReader reader = new System.IO.StreamReader(Application.streamingAssetsPath + "/Instructions/" + tabsFileName); string[] split; split = reader.ReadLine().Split(splitChar); //Skip the first line while (!reader.EndOfStream) { split = reader.ReadLine().Split(splitChar); if (split.Length < 3) { continue; } //print ("split 1: " + split[DISPLAY]); if (split[DISPLAY].Equals(selected)) { //print ("split 2: " + split[PREFAB]); prefabName = split[PREFAB]; break; } } reader.Close(); string xmlTabName = prefabName;//.Replace (" ", "_") + "Tab"; string xml = "<data></data>"; //Debug.Log (GlobalData.resourcePath + "Prefabs/Tabs/" + prefabName + " Tab" + "/" + prefabName.Replace (" ", string.Empty) + "Tab"); GameObject test = Resources.Load(GlobalData.resourcePath + "/Prefabs/Tabs/" + prefabName + " Tab" + "/" + prefabName.Replace(" ", string.Empty) + "Tab") as GameObject; if (test == null) { Debug.Log("Cannot load tab prefab " + prefabName); Debug.Log(GlobalData.resourcePath + "Prefabs/Tabs/" + prefabName + " Tab" + "/" + prefabName.Replace(" ", string.Empty) + "Tab"); return; } Debug.Log("-----: " + xmlTabName + ", " + tabCustomName); ds.AddData(tm.getCurrentSection(), xmlTabName, tabCustomName, xml); GameObject newTab = Resources.Load(GlobalData.resourcePath + "/Prefabs/TabButton") as GameObject; TextMeshProUGUI[] children = newTab.GetComponentsInChildren <TextMeshProUGUI>(); foreach (TextMeshProUGUI child in children) { if (child.name.Equals("TabButtonLinkToText")) //Where the button links to { child.text = tabCustomName; } else if (child.name.Equals("TabButtonDisplayText")) //What the button displays { child.text = tabCustomName; //.Replace("_", " ").Substring(0, tabCustomName.Length - 3); //This converts the custom name back to display format since tabName.text can be left blank } } //The button's position newTab = Instantiate(newTab, TabButtonContentPar.transform); newTab.name = tabCustomName /*.Replace(" ", "_")*/ + "TabButton"; if (tabName.text.Equals("Background Info") || tabName.text.Equals("Case Overview")) { newTab.transform.SetSiblingIndex(0); if (!BGInfoOption) { BGInfoOption = ds.transform.Find("TabSelectorBG/TabSelectorPanel/Content/ScrollView/Viewport/Content/BackgroundInfoTabPanel"); } if (!OverviewInfoOption) { OverviewInfoOption = ds.transform.Find("TabSelectorBG/TabSelectorPanel/Content/ScrollView/Viewport/Content/CaseOverviewTab"); } BGInfoOption.gameObject.SetActive(false); UpdateTabPos(); //tm.SwitchTab (xmlTabName + tabCount); } tm.setTabName(tabCustomName); //Debug.Log (xmlTabName); //tm.SwitchTab (xmlTabName); tm.SwitchTab(tabCustomName); Destroy(BG.transform.Find("TabSelectorBG(Clone)").gameObject); }
/** * 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); } }