コード例 #1
0
    public void Refresh()
    {
        LevelInfo[] levels = Resources.LoadAll <LevelInfo>("Levels");

        // Remove all children
        for (int i = 0; i < buttonListParent.transform.childCount; i++)
        {
            Destroy(buttonListParent.transform.GetChild(i).gameObject);
        }

        // Instantiate Buttons for Levels
        for (int i = 0; i < levels.Length; i++)
        {
            GameObject      levelButton = GameObject.Instantiate(buttonPrefab) as GameObject;
            LevelButtonInfo buttonInfo  = levelButton.GetComponent <LevelButtonInfo>();

            buttonInfo.levelInfo = levels[i];
            buttonInfo.Rename();

            levelButton.transform.localScale = Vector3.one;
            //levelButton.transform.parent = buttonListParent;
            levelButton.transform.SetParent(buttonListParent, false);
        }
    }