Esempio n. 1
0
        public void AddRuleListItem(string name = null)
        {
            if (name == null)
            {
                name = "item" + ruleListItems.Count.ToString();
            }
            /////////////////////////////
            //resize the parent container
            /////////////////////////////
            Vector2 offset  = new Vector2(0, 20);
            Vector3 offset3 = new Vector3(0, 20, 0);

            //Debug.LogWarningFormat("rectPanelContent={0}", rectPanelContent);
            //Debug.LogWarningFormat("rectPanelContent.sizeDelta={0}", rectPanelContent.sizeDelta);
            rectPanelContent.sizeDelta += offset;

            int        i    = ruleListItems.Count;
            GameObject item = Instantiate(UICreator.GetDefaultButtonAsset(), rectPanelContent);

            item.GetComponent <Button>().onClick.AddListener(delegate { SelectRuleListItem(i); });
            float         pos   = ruleListItems.Count * 20 + 5;
            RectTransform trans = item.transform as RectTransform;

            trans.anchoredPosition = new Vector2(0, -pos);
            Vector2 size = new Vector2(200, 20);

            trans.sizeDelta = size;
            trans.Find("Text").GetComponent <Text>().text = name;
            ruleListItems.Add(item);
        }
Esempio n. 2
0
        public void LoadGrammarList()
        {
            foreach (Button b in grammarListButtons)
            {
                GameObject.Destroy(b.gameObject);
            }
            grammarListButtons.Clear();

            string path = SceneManager.directoryRules;

            string[] files = System.IO.Directory.GetFiles(path, "*.sgr");
            for (int i = 0; i < files.Length; i++)
            {
                string fileName = files[i];
                Button bt       = Instantiate(UICreator.GetDefaultButtonAsset(), grammarListPanelContent).GetComponent <Button>();
                bt.transform.Find("Text").GetComponent <Text>().text = fileName;
                bt.onClick.AddListener(delegate { OnSelectGrammarClicked(fileName); });
                grammarListButtons.Add(bt);
                float posY = i * 20 + 5;
                ((RectTransform)bt.transform).anchoredPosition = new Vector2(5, -posY);
            }
        }