void CreateSelectLevel(int i) { levels[i] = new Level(); levels[i].SetIndex(i); if (i < currentUnlockedLevel) { levels[i].SetIsUnlocked(true); } if (levels[i].IsUnlocked()) { levelPrefab = Instantiate(levelUnlockedPrefab, Vector3.zero, Quaternion.identity) as GameObject; levelPrefab.GetComponentInChildren<Text>().text = i + 1 + ""; Button btn = levelPrefab.GetComponent<Button>(); btn.onClick.AddListener(OnButtonClick); Button btnInfo = levelPrefab.GetComponentsInChildren<Button>()[1]; btnInfo.onClick.AddListener(OnButtonInfoClick); } else { levelPrefab = Instantiate(levelLockedPrefab, Vector3.zero, Quaternion.identity) as GameObject; } if (i == currentUnlockedLevel - 1) { highestUnlockedLevel = levelPrefab; } levelPrefab.transform.SetParent(transform); levelPrefab.transform.localScale = new Vector3(1, 1); if (i == LevelUtils.GetLevels().Count - 1 || i == LevelUtils.GetLevels().Count - 2) { levelPrefab.GetComponent<Image>().color = Color.red; } }
// Use this for initialization void Start() { LevelUtils.initLevel(); PlayerDataUtils.loadData(); if (PlayerDataUtils.playerData.highestLevelUnlocked != 0) { currentUnlockedLevel = PlayerDataUtils.playerData.highestLevelUnlocked; } for (int i = 0; i < LevelUtils.GetLevels().Count; i++) { CreateSelectLevel(i); } }