Exemplo n.º 1
0
    private void PrepareCatButtons()
    {
        if (CatButtons.Count > 0)
        {
            foreach (var item in CatButtons)
            {
                Destroy(item.gameObject);
            }
            CatButtons = new List <ModButton>();
        }
        GameObject buttonPrefab = Resources.Load <GameObject>("ModSystem/UI/Button");

        foreach (var item in target.GetCompatibleCategories())
        {
            var gm = Instantiate(buttonPrefab, CategoryBar.GetComponent <RectTransform>());

            var btn = gm.GetComponent <Button>();
            btn.onClick.AddListener(delegate { ChangeCategory(item); });

            var modbtn = gm.GetComponent <ModButton>();
            modbtn.Name = item;
            CatButtons.Add(modbtn);
        }
        ChangeCategory(CatButtons[0].name);
    }