コード例 #1
0
    /**
     * Called by the edit section panel to remove a section
     */
    public void removeSection()
    {
        string    removedSection = tObject.text;
        Transform par            = tm.SectionContentPar.transform;

        if (!tObject.text.Contains("/"))
        {
            Destroy(tm.SectionContentPar.transform.Find(tObject.text + "Button").gameObject);
        }
        else
        {
            for (int i = 0; i < tm.SectionContentPar.transform.childCount; i++)
            {
                if (tm.SectionContentPar.transform.GetChild(i).name.Equals(tObject.text + "Button"))
                {
                    Destroy(tm.SectionContentPar.transform.GetChild(i).gameObject);
                    break;
                }
            }
        }
        string sectionData = ds.GetData(removedSection).GetAllData();

        ds.RemoveSection(removedSection);
        //editSectionPanel.gameObject.SetActive (false);
        tm.RemoveCurrentSection();

        List <string> keyList = ds.GetImageKeys();        // ds.GetImages ().Keys.ToList ();

        foreach (string key in keyList)
        {
            if (key.StartsWith(tObject.text) || sectionData.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(tObject.text))
            {
                ds.GetDialogues().Remove(key);
            }
        }

        keyList = ds.GetQuizes().Keys.ToList();
        foreach (string key in keyList)
        {
            if (key.StartsWith(tObject.text))
            {
                ds.GetQuizes().Remove(key);
            }
        }
        string switchTo = "";

        for (int i = 0; i < tm.SectionContentPar.transform.childCount; i++)
        {
            Transform child = tm.SectionContentPar.transform.GetChild(i);
            if (!child.name.Equals("Filler"))
            {
                switchTo = child.Find("SectionDisplayTMP").GetComponent <TextMeshProUGUI> ().text.Replace(" ", "_") + "Section";
                if (!switchTo.Equals(removedSection))
                {
                    break;
                }
            }
            else
            {
                switchTo = "";
            }
        }
        //Debug.Log (tm.SectionContentPar.transform.GetComponentsInChildren<Transform>()[1].name);
        //switchTo = tm.SectionContentPar.GetComponentsInChildren<Transform>()[1].Find("SectionDisplayText").GetComponent<TextMeshProUGUI>().text;
        if (switchTo.Equals(""))
        {
            BG.transform.Find("SectionCreatorBG").gameObject.SetActive(true);
            for (int i = 0; i < tm.TabContentPar.transform.childCount; i++)
            {
                Destroy(tm.TabContentPar.transform.GetChild(i).gameObject);
            }
        }
        else
        {
            tm.SwitchSection(switchTo);
        }

        //Destroy (editTabPanel);
    }