public void SwipeLeft() { if (!OnValidScreen()) { return; } TabInfoScript currentTab = ds.GetData(tm.getCurrentSection()).GetTabInfo(tm.getCurrentTab()); if (ds.GetData(tm.getCurrentSection()).GetTabList().Count > currentTab.position + 1) { //This is the name of the next tab. string newTabName = ds.GetData(tm.getCurrentSection()).GetTabList()[currentTab.position + 1]; tm.setTabName(newTabName); tm.SwitchTab(newTabName); } else if (!ds.forceInOrder || ds.GetData(tm.getCurrentSection()).AllTabsVisited()) { var nextSectionIndex = ds.GetSectionsList().FindIndex((string obj) => obj.Equals(tm.getCurrentSection())) + 1; if (ds.GetSectionsList().Count > nextSectionIndex) { string nextSection = ds.GetSectionsList()[nextSectionIndex]; tm.SwitchSection(nextSection); } } }
public void SwipeRight() { if (!OnValidScreen()) { return; } TabInfoScript currentTab = ds.GetData(tm.getCurrentSection()).GetTabInfo(tm.getCurrentTab()); if (currentTab.position > 0) { //This is the name of the next tab. string newTabName = ds.GetData(tm.getCurrentSection()).GetTabList()[currentTab.position - 1]; tm.setTabName(newTabName); tm.SwitchTab(newTabName); } else { var sectionList = ds.GetSectionsList(); var nextSectionIndex = sectionList.FindIndex((string obj) => obj.Equals(tm.getCurrentSection())) - 1; if (nextSectionIndex >= 0) { string lastSection = sectionList[nextSectionIndex]; tm.SwitchSection(lastSection, true); } } }
public void NextTab() { TabInfoScript currentTab = ds.GetData(tm.getCurrentSection()).GetTabInfo(tm.getCurrentTab()); //This is the name of the next tab. string newTabName = ds.GetData(tm.getCurrentSection()).GetTabList().ToArray()[currentTab.position + 1]; tm.setTabName(newTabName); tm.SwitchTab(newTabName); }
/** * Updates the current tab */ public void SetCurrentTab(string tabName) { if (Dict.ContainsKey(tabName)) { currentTab = Dict[tabName]; } //if (Dict [tabName] != null) { //currentTab = Dict [tabName]; //} else { Debug.Log("Could not find " + tabName + " in Dict"); } }
/// <summary> /// Switches the tab /// </summary> /// <param name="tabName">Formatted tab name</param> public void SwitchTab(string tabName) { //Transform[] tabButtonsList = TabButtonContentPar.GetComponentsInChildren<Transform>(); List <Transform> tabButtonsList = new List <Transform>(); for (int i = 0; i < TabButtonContentPar.transform.childCount; i++) { var trans = TabButtonContentPar.transform.GetChild(i); if (trans.gameObject.activeSelf) { tabButtonsList.Add(TabButtonContentPar.transform.GetChild(i)); } } /* For debugging * string str = ""; * foreach (Transform t in tabButtonsList) { * str += t.name + ", "; * } * Debug.Log (str);*/ string tName = null; string section = currentSection; string tabType; float tempScrollPos = 0; //Check if the tab is specified. If not, let the user choose their tab TabInfoScript tabScript = null; //int n = -1; if (tabName == null || tabName.Equals("")) //If no provided tab name { tabScript = ds.GetData(section).GetCurrentTab(); //Check to see if there were any active tabs for the current section if (tabScript == null || tabScript.type == "") //If no active tab //n = 0; { SectionDataScript sds = ds.GetData(section); if (sds.GetTabList().Count > 0) //If the section has any tabs at all { string tempTabName = sds.GetTabList()[0]; tempTabName = tempTabName.Replace('_', ' ').Substring(0, tempTabName.Length - "Tab".Length); sds.SetCurrentTab(tempTabName); tabType = tempTabName; sds.GetTabInfo(tabType).Visit(); if (sds.AllTabsVisited()) { //Track that this section has had all tabs visited Tracker.RecordData( Tracker.DataType.progress, GlobalData.caseObj.recordNumber, new Tracker.ProgressData(sds.GetPosition(), -1));// ds.GetSectionsList().FindIndex((string sec) => sec.Equals(section)))); } else { //Track the tab visit Tracker.RecordData( Tracker.DataType.progress, GlobalData.caseObj.recordNumber, new Tracker.ProgressData(sds.GetPosition(), sds.GetTabInfo(tabType).n)); } Tracker.PrintAllData(); } else //Section has no tabs. New Section. Let user pick tab //transform.Find("TabSelectorBG").gameObject.SetActive(true); { return; //This will set the tab as the default specified in the Default data script //sds.SetCurrentTab (new TabInfoScript(0, ID.defaultTab)); //tab = ID.defaultTab; } } else //Set tab to the section's last active tab { tabType = tabScript.type; } Destroy(currentTab); currentTab = null; } else { //Switching away from a tab if (currentTab != null) { if ((tabName + "Tab").Equals(currentTab.name) && section.Equals(currentSection)) { return; } else { //This line throws errors with a "/" in the name //TabButtonContentPar.transform.Find(currentTab.name + "Button").GetComponent<Button>().interactable = true; tName = currentTab.name /*.Replace (" ", "_")*/ + "Button"; foreach (Transform t in tabButtonsList) { if (t.name.Equals(tName)) { t.GetComponent <Button>().interactable = true; //Enable visited mark if (ds.forceInOrder) { //Enabling something (like the visited notice) resets the scrollbar back to 0 (to the left) //NextFrame.Function(delegate { TabButtonContentPar.transform.parent.parent.GetComponent<ScrollRect>().horizontalNormalizedPosition = tempScrollPos; }); tempScrollPos = TabButtonContentPar.transform.parent.parent.GetComponent <ScrollRect>().horizontalNormalizedPosition; t.Find("Visited").gameObject.SetActive(true); } break; } } Destroy(currentTab); currentTab = null; } } //Debug.Log(string.Join(",", ds.GetData (currentSection).GetTabList().ToArray())); tabType = ds.GetData(currentSection).GetTabInfo(tabName).type; ds.GetData(currentSection).GetTabInfo(tabName).Visit(); if (ds.GetData(currentSection).AllTabsVisited()) { //Track that this section has had all tabs visited int sectionIdx = ds.GetSectionsList().FindIndex((string sec) => sec.Equals(section)); //If the last section has been completed, mark the case as visited if (sectionIdx == ds.GetSectionsList().Count - 1) { Tracker.RecordData( Tracker.DataType.finishedCase, GlobalData.caseObj.recordNumber, true); } else { //Record the completed section Tracker.RecordData( Tracker.DataType.progress, GlobalData.caseObj.recordNumber, new Tracker.ProgressData(ds.GetData(currentSection).GetPosition(), ds.GetData(currentSection).GetTabInfo(tabName).n)); } //Remove the lock on the next step if (ds.forceInOrder) { int nextPos = ds.GetData(currentSection).GetPosition() + 1; if (nextPos < ds.GetSectionsList().Count) { Transform button = ds.SectionButtonPar.transform.GetChild(nextPos); button.GetComponent <Button>().interactable = true; if (button.Find("Overlay")) { button.Find("Overlay").GetComponent <Image>().color = new Color(0, 0, 0, (float)50 / 255); button.Find("Overlay").GetComponent <HideOnMouseHoverScript>().enabled = true; } button.Find("Lock").gameObject.SetActive(false); ds.SectionButtonPar.transform.GetChild(ds.GetData(currentSection).GetPosition() + 1).GetComponent <Button>().interactable = true; } } //Apply the checkmark when the last tab is visited Transform currentButton = ds.SectionButtonPar.transform.GetChild(ds.GetData(currentSection).GetPosition()); currentButton.Find("AllTabsVisitedCheck").gameObject.SetActive(true); } else { //Track the tab visit Tracker.RecordData( Tracker.DataType.progress, GlobalData.caseObj.recordNumber, new Tracker.ProgressData(ds.GetData(currentSection).GetPosition(), ds.GetData(currentSection).GetTabInfo(tabName).n)); } Tracker.PrintAllData(); if (tabType.ToLower().EndsWith("tab")) //Remove the "Tab" from the end of the type { tabType = tabType.Substring(0, tabType.Length - 3); } } //Debug.Log ("Section: " + currentSection + ", Name: " + tabName + ", Type: " + tabType); //Type is _ + Tab, but should be prefab folder - " Tab" //Load in the specified tab //string name = tabName; //string folder = tabType + " Tab"; //tabType = tabType.Replace (" ", string.Empty) + "Tab"; //Folder should be the same as the prefab folder. Tab should equal the prefab name. Name should be the link to text //Debug.Log ("Prefabs/Tabs/" + folder + "/" + tabType); //GameObject newPrefab = Resources.Load(GlobalData.resourcePath + "/Prefabs/Tabs/" + folder + "/" + tabType) as GameObject; //GameObject newTab = Instantiate (newPrefab, TabContentPar.transform); //GameObject newPrefab = Resources.Load(GlobalData.resourcePath + "/Prefabs/Tabs/" + tabType + " Tab/" + tabType.Replace(" ", string.Empty) + "Tab") as GameObject; GameObject newTab = Instantiate(Resources.Load(GlobalData.resourcePath + "/Prefabs/Tabs/" + tabType + " Tab/" + tabType.Replace(" ", string.Empty) + "Tab") as GameObject, TabContentPar.transform); newTab.name = tabName + "Tab"; if (GlobalData.GDS.isMobile) { newTab.transform.GetComponentInChildren <Scrollbar>().targetGraphic.enabled = true; newTab.transform.GetComponentInChildren <Scrollbar>().GetComponent <Image>().enabled = true; } //newTab.AddComponent<Text> ().text = "" + n; currentTab = newTab; ds.GetData(section).SetCurrentTab(tabName); //Adjust the buttons int tNameHash = (currentTab.name /*.Replace (" ", "_")*/ + "Button").GetHashCode(); int j = 0; foreach (Transform t in tabButtonsList) { //if (t.name.Equals (tName)) { if (t.name.GetHashCode() == tNameHash) { //Writer code to disable trash button for persistant tabs was here. Changing to visited code now //Enable the visited check t.GetChild(t.childCount - 1).gameObject.SetActive(true); t.GetComponent <Button>().interactable = false; t.GetComponent <ScriptButtonFixScript>().FixTab(); //Find the value that we need to auto-scroll to float viewportWidth = TabButtonContentPar.transform.parent.GetComponent <RectTransform>().rect.width; float tabWidth = t.GetComponent <RectTransform>().rect.width; float contentParOffset = TabButtonContentPar.GetComponent <RectTransform>().anchoredPosition.x; float tabButtonOffset = t.transform.localPosition.x; float leftSideTabButtonLocal = tabButtonOffset - tabWidth / 2 + contentParOffset; float rightSideTabButtonLocal = tabButtonOffset + tabWidth / 2 + contentParOffset; if (leftSideTabButtonLocal < 0) { //Past left side print("Past left"); float tabHorizontalPos = Mathf.Clamp01((tabButtonOffset - tabWidth / 2) / (TabButtonContentPar.GetComponent <RectTransform>().rect.width - viewportWidth)); TabButtonContentPar.transform.parent.parent.GetComponent <ScrollRect>().horizontalNormalizedPosition = tabHorizontalPos; } else if (rightSideTabButtonLocal > viewportWidth) { //past right side print("Past right"); float tabHorizontalPos = Mathf.Clamp01((tabButtonOffset + tabWidth / 2 - viewportWidth) / (TabButtonContentPar.GetComponent <RectTransform>().rect.width - viewportWidth)); TabButtonContentPar.transform.parent.parent.GetComponent <ScrollRect>().horizontalNormalizedPosition = tabHorizontalPos; } /* * //If the tab's left side is to the left of the tab viewport * if (t.position.x - tabWidth / 2 < viewportX - viewportWidth / 2) { * float tabHorizontalPos = (t.localPosition.x - t.GetComponent<RectTransform>().rect.width / 2 - viewportWidth) / (TabButtonContentPar.GetComponent<RectTransform>().rect.width - viewportWidth); * TabButtonContentPar.transform.parent.parent.GetComponent<ScrollRect>().horizontalNormalizedPosition = tabHorizontalPos; * //Else if the right side of the tab is past the right side of the tab viewport * } else if (t.position.x + tabWidth / 2 > viewportX + viewportWidth / 2) { * float tabHorizontalPos = (t.localPosition.x + t.GetComponent<RectTransform>().rect.width / 2 - viewportWidth) / (TabButtonContentPar.GetComponent<RectTransform>().rect.width - viewportWidth); * TabButtonContentPar.transform.parent.parent.GetComponent<ScrollRect>().horizontalNormalizedPosition = tabHorizontalPos; * } */ break; } j++; } if (ds.forceInOrder && tabButtonsList.Count > j + 1) { //tabButtonsList[j + 1].Find("Locked").gameObject.SetActive(false); //tabButtonsList[j + 1].GetComponent<Button>().enabled = true; } print(tempScrollPos); if (tempScrollPos > 0) { TabButtonContentPar.transform.parent.parent.GetComponent <ScrollRect>().horizontalNormalizedPosition = tempScrollPos; NextFrame.Function(delegate { //Can't do next frame, because that messes up the code that alligns to a tab off the screen //TabButtonContentPar.transform.parent.parent.GetComponent<ScrollRect>().horizontalNormalizedPosition = tempScrollPos; }); } /* * foreach(TabScrollButtonScript scrollButton in TabButtonContentPar.transform.parent.parent.parent.GetComponentsInChildren<TabScrollButtonScript>()) { * if (scrollButton.name.EndsWith("Right")) { * //scrollButton.gameObject.SetActive(true); * } * }*/ //Debug.Log(ds.GetData(getCurrentSection()).GetAllData()); //Resources.UnloadUnusedAssets(); }
/** * Switches the active section. * Pass in the LinkToText */ public void SwitchSection(string sectionName) { string sName = null; //Disable the text and edit button of the section we're switching away from (show only the icon) List <Button> sectionButtonsList = SectionContentPar.GetComponentsInChildren <Button>().ToList(); sectionButtonsList.RemoveAt(sectionButtonsList.Count - 1); //Remove the AddSectionButton if (currentSection != null && !currentSection.Equals("")) { sName = currentSection.Replace(" ", "_") + "Button"; foreach (Button t in sectionButtonsList) { if (t.transform.name.Equals(sName)) { Transform[] components = t.transform.GetComponentsInChildren <Transform>(); foreach (Transform c in components) { if (!c.name.Equals(t.name) && !c.name.Equals("SectionDisplayTMP")) { c.gameObject.SetActive(false); } if (c.name.Equals("SectionDisplayTMP") && c.GetComponent <TextMeshProUGUI>().preferredWidth > 85) { c.GetComponent <LayoutElement>().preferredWidth = 85; } } t.transform.GetChild(0).gameObject.SetActive(true); t.interactable = true; } } } if (sectionName == null || sectionName.Equals("")) //No section provided. Use default { if (ID == null) { ID = new DefaultDataScript(); } sectionName = ID.defaultSection; print(string.Join(",", sectionButtonsList.Select(b => b.name))); if (sectionButtonsList.Count > 0 && sectionButtonsList[0].name.Length > 0) { sectionName = sectionButtonsList[0].name.Remove(sectionButtonsList[0].name.Length - "Button".Length); } print(sectionName); } else if (sectionName.Equals(currentSection)) //Trying to switch to current section { return; } if (currentSection != null && !currentSection.Equals("")) //Save data before switching away { AddToDictionary(); currentSection = null; currentTab = null; } currentSection = sectionName; //Destroy Tab buttons and content foreach (Transform child in TabContentPar.GetComponentInChildren <Transform>()) { Destroy(child.gameObject); } foreach (Transform child in TabButtonContentPar.GetComponentInChildren <Transform>()) { if (child.name != "AddTabButton") { Destroy(child.gameObject); } } //Enable the new section's text and edit button sName = currentSection.Replace(" ", "_") + "Button"; foreach (Button t in sectionButtonsList) { if (t.name.Equals(sName) && !t.name.Equals("AddSectionButton")) { Transform[] components = t.GetComponentsInChildren <Transform>(true); foreach (Transform c in components) { if (c.name.Equals("SectionDisplayText")) { continue; } c.gameObject.SetActive(true); if (c.name.Equals("SectionDisplayTMP")) { if (c.GetComponent <TextMeshProUGUI>().preferredWidth > 270) { c.GetComponent <LayoutElement>().preferredWidth = 270; } else { c.GetComponent <LayoutElement>().preferredWidth = -1; } } } t.GetComponent <Button>().interactable = false; t.GetComponent <ScriptButtonFixScript>().FixTab(); } } //Load in the Tab buttons for each tab List <string> sectionTabs = null; if (ds.GetData(currentSection) != null) { sectionTabs = ds.GetData(currentSection).GetTabList(); } int i = 0; if (sectionTabs == null || sectionTabs.Count == 0) //Spawn a default tab //transform.Find("TabSelectorBG").gameObject.SetActive(true); //Let the user choose their new tab { GameObject savePrefab = Instantiate(Resources.Load("Writer/Prefabs/Panels/TabSelectorBG")) as GameObject; savePrefab.transform.SetParent(BG.transform, false); if (savePrefab.transform.Find("TabSelectorPanel/RowTitle/CancelButton")) { savePrefab.transform.Find("TabSelectorPanel/RowTitle/CancelButton").gameObject.SetActive(false); } //This code spawns in the default tab listed in DefaultDataScript /*string tabName = ID.defaultTab; * GameObject newTab = Resources.Load (gData.resourcesPath + "/Prefabs/TabButton") as GameObject; * Text[] children = newTab.GetComponentsInChildren<Text> (); * foreach (Text child in children) { * if (child.name.Equals ("TabButtonLinkToText")) { //Where the button links to * child.text = tabName.Replace (" ", "_") + "Tab" + i; * } else if (child.name.Equals ("TabButtonDisplayText")) { //What the button displays * child.text = tabName; * } * } * //The button's position * newTab = Instantiate (newTab, TabButtonContentPar.transform); * newTab.name = tabName + "Button"; * ds.GetData (currentSection).AddData (tabName.Replace (" ", "_") + "Tab" + i, null); * ds.GetData (currentSection).SetCurrentTab (new TabInfoScript (i, tabName.Replace (" ", "_") + "Tab"));*/ } else { //Spawn in the section's tab buttons Debug.Log("TABS = " + string.Join(",", sectionTabs.ToArray())); foreach (string tabName in sectionTabs) { 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 = tabName; } else if (child.name.Equals("TabButtonDisplayText")) //What the button displays { string customName = ds.GetData(currentSection).GetTabInfo(tabName).customName; if (customName != null) // && customName != tabName) { { child.text = customName; } else { if (child.text.Contains(" ")) { //child.text = tabName.Replace ("_", " ").Substring (0, tabName.Length - "Tab".Length); //Unformat it //child.text = child.text.Replace(" ", "_") + "Tab"; } child.text = tabName; ds.GetData(currentSection).GetTabInfo(tabName).customName = child.text; } } } //The button's position i++; newTab = Instantiate(newTab, TabButtonContentPar.transform); newTab.name = tabName /*.Replace (" ", "_")*/ + "TabButton"; } //transform.Find ("TabSelectorBG/TabSelectorPanel/Content/ScrollView/Viewport/Content/BackgroundInfoTabPanel").gameObject.SetActive (activateBGInfoOption); for (int j = 0; j < TabButtonContentPar.transform.childCount; j++) { //foreach (string tabName in sectionTabs) { //TabButtonContentPar.transform.Find (tabName/*.Replace (" ", "_")*/ + "TabButton").GetComponent<TabAndSectionDragScript> ().UpdateEntryList (); if (!TabButtonContentPar.transform.GetChild(j).name.Equals("AddTabButton")) { TabButtonContentPar.transform.GetChild(j).GetComponent <TabAndSectionDragScript>().UpdateEntryList(); } } } //If the section had a custom icon image (and can load it), then set the tab background bar color to the icon image color if (currentSection != null && ds.GetImageKeys().Contains(currentSection)) { if (ds.GetImage(currentSection).color.a > 0) { GameObject.Find("TabButtonsPanel").GetComponent <Image>().color = ds.GetImage(currentSection).color; } else { GameObject.Find("TabButtonsPanel").GetComponent <Image>().color = ID.defaultColor; } } else if (currentSection == ID.defaultSection) { GameObject.Find("TabButtonsPanel").GetComponent <Image>().color = ID.defaultColor; } addTabButton.transform.SetAsLastSibling(); //Switch to the default/last active tab of the new section TabInfoScript tab = ds.GetData(currentSection).GetCurrentTab(); if (tab != null) { string formattedName = tab.customName; //.Replace (" ", "_") + "Tab"; //Debug.Log ("CUSTOM NAME: " + tab.customName); setTabName(formattedName); SwitchTab(formattedName); } else if (ds.GetData(getCurrentSection()).GetTabList().Count <= 0) { return; } else { //Debug.Log (string.Join (",", ds.GetData (getCurrentSection ()).GetTabList ().ToArray ())); TabInfoScript newTabInfo = ds.GetData(getCurrentSection()).GetTabInfo(ds.GetData(getCurrentSection()).GetTabList()[0]); string formattedName = newTabInfo.customName; //.Replace (" ", "_") + "Tab"; //Debug.Log ("DEFAULT'S CUSTOM NAME: " + newTabInfo.customName); setTabName(formattedName); SwitchTab(formattedName); //SwitchTab (ds.GetData (getCurrentSection ()).GetTabList () [0]); } }
/** * Switches the active tab * Pass in the formatted tabName */ public void SwitchTab(string tabName) { Transform[] tabButtonsList = TabButtonContentPar.GetComponentsInChildren <Transform>(); /* For debugging * string str = ""; * foreach (Transform t in tabButtonsList) { * str += t.name + ", "; * } * Debug.Log (str);*/ string tName = null; string section = currentSection; string tabType; //Check if the tab is specified. If not, let the user choose their tab TabInfoScript tabScript = null; //int n = -1; if (tabName == null || tabName.Equals("")) //If no provided tab name { tabScript = ds.GetData(section).GetCurrentTab(); //Check to see if there were any active tabs for the current section if (tabScript == null || tabScript.type == "") //If no active tab //n = 0; { SectionDataScript sds = ds.GetData(section); if (sds.GetTabList().Count > 0) //If the section has any tabs at all { string tempTabName = sds.GetTabList()[0]; tempTabName = tempTabName.Replace('_', ' ').Substring(0, tempTabName.Length - "Tab".Length); sds.SetCurrentTab(tempTabName); tabType = tempTabName; } else //Section has no tabs. New Section. Let user pick tab //transform.Find("TabSelectorBG").gameObject.SetActive(true); { return; //This will set the tab as the default specified in the Default data script //sds.SetCurrentTab (new TabInfoScript(0, ID.defaultTab)); //tab = ID.defaultTab; } } else //Set tab to the section's last active tab { tabType = tabScript.type; } Destroy(currentTab); currentTab = null; } else { //Remove the number at the end of tab and store it as n /*string[] tabSplit = Regex.Split (tab, @"[0-9]*$"); * n = int.Parse (tab.Substring (tabSplit [0].Length, tab.Length - tabSplit [0].Length)); * tab = tabSplit [0];*/ /* Debugging test * GameObject test = Resources.Load(gData.resourcesPath + "/Prefabs/Tabs/" + tab.Replace("_", " ").Substring(0, tab.Length - 3) + " Tab" + "/" + tab.Replace (" ", String.Empty).Replace("_", String.Empty)) as GameObject; * if (test == null) { * Debug.Log ("Cannot load tab prefab"); * //return; * } */ //If we're switching away from a tab, save the data if (currentTab != null) { if ((tabName + "Tab").Equals(currentTab.name) && section.Equals(currentSection)) { sameTab = true; AddToDictionary(); sameTab = false; return; } else { AddToDictionary(); tName = currentTab.name /*.Replace (" ", "_")*/ + "Button"; foreach (Transform t in tabButtonsList) { if (t.name.Equals(tName)) { t.GetChild(t.childCount - 1).gameObject.SetActive(false); t.GetComponent <Button>().interactable = true; } } Destroy(currentTab); currentTab = null; } } //Debug.Log(string.Join(",", ds.GetData (currentSection).GetTabList().ToArray())); tabType = ds.GetData(currentSection).GetTabInfo(tabName).type; if (tabType.ToLower().EndsWith("tab")) //Remove the "Tab" from the end of the type { tabType = tabType.Substring(0, tabType.Length - 3); } } Debug.Log("Section: " + currentSection + ", Name: " + tabName + ", Type: " + tabType); //Type is _ + Tab, but should be prefab folder - " Tab" //Load in the specified tab string name = tabName; string folder = tabType + " Tab"; tabType = tabType.Replace(" ", string.Empty) + "Tab"; /*if (tabType.Contains (" ")) { * //name = tabName.Replace (" ", "_") + "Tab"; * tabType = tabType.Replace (" ", String.Empty); * tabType = tabType + "Tab"; * folder = tabType + " Tab"; * } else { * //name = tabName.Replace (" ", "_") + "Tab"; * folder = tabType.Replace ("_", " "); * if (!folder.EndsWith (" Tab") && folder.EndsWith ("Tab")) { * folder = folder.Substring (0, folder.Length - 3) + " Tab"; * } else if (!folder.EndsWith ("Tab")) { * folder = folder + " Tab"; * } * tabType = tabType.Replace ("_", String.Empty); * if (!tabType.EndsWith ("Tab")) { * tabType = tabType + "Tab"; * } * /*if (!name.EndsWith ("Tab")) { * name = name + "Tab"; * } * }*/ name = tabName; //Folder should be the same as the prefab folder. Tab should equal the prefab name. Name should be the link to text GameObject par = TabContentPar; //Debug.Log ("Prefabs/Tabs/" + folder + "/" + tabType); GameObject newPrefab = Resources.Load(GlobalData.resourcePath + "/Prefabs/Tabs/" + folder + "/" + tabType) as GameObject; GameObject newTab = Instantiate(newPrefab, par.transform); newTab.name = name + "Tab"; //newTab.AddComponent<Text> ().text = "" + n; currentTab = newTab; ds.GetData(section).SetCurrentTab(name); if (newTab.transform.Find("AddFieldButton") && ds.GetImage(getCurrentSection()) != null) { newTab.transform.Find("AddFieldButton").GetComponent <Image>().color = ds.GetImage(getCurrentSection()).color; } //Adjust the buttons tName = currentTab.name /*.Replace (" ", "_")*/ + "Button"; foreach (Transform t in tabButtonsList) { if (t.name.Equals(tName)) { if (!ds.GetData(currentSection).IsPersistant(name)) { t.GetChild(t.childCount - 1).gameObject.SetActive(true); } t.GetComponent <Button>().interactable = false; t.GetComponent <ScriptButtonFixScript>().FixTab(); t.GetComponent <ScriptButtonFixScript>().FixTab(); } } if (addTabButton != null) { addTabButton.transform.SetAsLastSibling(); if (ds.GetData(currentSection).GetTabList().Count >= 8) { addTabButton.SetActive(false); } else { addTabButton.SetActive(true); } } //Debug.Log(ds.GetData(getCurrentSection()).GetAllData()); Resources.UnloadUnusedAssets(); }
/** * Called when removing a tab from the edit tab panel */ public void removeTab() { //Debug.Log (tObject.text); tm.AddToDictionary(); string tabData = ds.GetData(tm.getCurrentSection(), tabName.text); ds.RemoveTab(tabName.text); tm.DestroyCurrentTab(); tm.TabButtonContentPar.transform.Find(tabName.text + "TabButton"); if (!tabName.text.Contains("/")) { Destroy(tm.TabButtonContentPar.transform.Find(tabName.text + "TabButton").gameObject); } else { for (int i = 0; i < tm.TabButtonContentPar.transform.childCount; i++) { if (tm.TabButtonContentPar.transform.GetChild(i).name.Equals(tabName.text + "TabButton")) { Destroy(tm.TabButtonContentPar.transform.GetChild(i).gameObject); break; //break out of the loop } } } if (ds.GetData(tm.getCurrentSection()).GetTabList().Count != 0) { TabInfoScript newTabInfo = ds.GetData(tm.getCurrentSection()).GetTabInfo(ds.GetData(tm.getCurrentSection()).GetTabList() [0]); tm.setTabName(newTabInfo.customName); tm.SwitchTab(ds.GetData(tm.getCurrentSection()).GetTabList() [0]); } else { //BG.transform.Find ("TabSelectorBG").gameObject.SetActive (true); GameObject tabSelectorPrefab = Instantiate(Resources.Load("Writer/Prefabs/Panels/TabSelectorBG")) as GameObject; tabSelectorPrefab.transform.SetParent(BG.transform, false); if (tabSelectorPrefab.transform.Find("TabSelectorPanel/RowTitle/CancelButton")) { tabSelectorPrefab.transform.Find("TabSelectorPanel/RowTitle/CancelButton").gameObject.SetActive(false); } } //Debug.Log (ds.GetData (tm.getCurrentSection()).getTabList ()[0]); tabEditPrefab.transform.Find(TitleValuePath).GetComponent <TMP_InputField>().text = ""; //tabEditPrefab.gameObject.SetActive (false); if (tabName.text.StartsWith("Background_InfoTab")) { ds.transform.Find("TabSelectorBG/TabSelectorPanel/Content/ScrollView/Viewport/Content/BackgroundInfoTabPanel").gameObject.SetActive(true); } Destroy(tabEditPrefab); List <string> keyList = ds.GetImageKeys(); // ds.GetImages ().Keys.ToList(); foreach (string key in keyList) { if (tabData.Contains("<Image>" + key + "</Image>")) { Debug.Log("Removing Image: " + key); ds.RemoveImage(key); //ds.GetImages ().Remove (key); } } keyList = ds.GetDialogues().Keys.ToList(); foreach (string key in keyList) { if (key.StartsWith(tm.getCurrentSection() + "/" + tabName.text + "Tab")) { ds.GetDialogues().Remove(key); } } keyList = ds.GetQuizes().Keys.ToList(); foreach (string key in keyList) { if (key.StartsWith(tm.getCurrentSection() + "/" + tabName.text + "Tab")) { ds.GetQuizes().Remove(key); } } }