Exemplo n.º 1
0
    private void Start()
    {
        GameSaveData data = GameData.LoadData();

        for (int id = 0; id < LevelManager.Instance.levels.levels.Length; id++)
        {
            if (id > data.highestLevel + 1)
            {
                Instantiate(DummyButtonPrefab, transform);
                continue;
            }

            string levelName = LevelManager.Instance.levels.levels[id];

            UI_LevelButton newButton = Instantiate(LevelButtonPrefab, transform).GetComponent <UI_LevelButton>();
            newButton.parentElement = this;

            float completionTime = 0.0f;

            // get player's progress data
            if (data.levelData.ContainsKey(levelName))
            {
                completionTime = data.levelData[levelName].completionTime;
            }

            // Initialize the button with player's data too
            newButton.Init(id, completionTime);
            //newButton.transform.GetChild(0).GetComponent<Text>().text = (id+1).ToString();
        }
    }
Exemplo n.º 2
0
    private void InitLevelSelectPanel()
    {
        foreach (var item in levelButtonList)
        {
            if (item)
            {
                Destroy(item.gameObject);
            }
        }
        levelButtonList.Clear();

        for (int i = 0; i < LevelLibrary.I.GetLevelCount(); i++)
        {
            UI_LevelButton lvlBtn = Instantiate <UI_LevelButton>(levelButtonTemplate);
            lvlBtn.transform.SetParent(levelSelectGroup);
            lvlBtn.transform.localScale    = Vector3.one;
            lvlBtn.transform.localPosition = Vector3.zero;
            lvlBtn.gameObject.SetActive(true);

            int lvlIdx = i;
            lvlBtn.GetComponent <Button>().onClick.AddListener(() => ClickLevel(lvlIdx));
            lvlBtn.Init(i);
            levelButtonList.Add(lvlBtn);
        }
    }