12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using System.Collections.Generic;
- using UnityEngine;
- using System.Collections;
- using ICTS.Localization;
- using TMPro;
- using UnityEngine.UI;
- public class LevelSelector : MonoBehaviour
- {
- public GameObject levelButtonPrefab;
- public GameObject parent;
- public List<ButtonLevelSelector> ButtonLevelSelectors = new List<ButtonLevelSelector>();
- const int OFFSET = 140;
- const int BUTTON_SPACING = 120;
- void Start()
- {
- //PlayerPrefs.SetInt("Level", 5);
- int numOfLevels = LevelsManager.Instance.levels.Length;
- int posY = OFFSET;
- for (int i = 0; i < numOfLevels; i++)
- {
- var go = (GameObject)Instantiate(levelButtonPrefab);
- go.transform.SetParent(parent.transform);
- Transform button = go.transform;
- //Vector3 pos = new Vector3(0, posY, 0);
- button.localPosition = Vector3.zero;
- button.localScale = Vector3.one;
- // -= BUTTON_SPACING;
- var label = button.GetComponentInChildren<TextMeshProUGUI>();
- label.text = string.Format(Localization.instance.Get("levelButton.text"), i+1); //+1 since players prefer 1-based
- ButtonLevelSelector buttonLevelSelector = button.GetComponent<ButtonLevelSelector>();
- buttonLevelSelector.levelIndex = i;
- ButtonLevelSelectors.Add(buttonLevelSelector);
-
- }
- ActivateCountButtonLevel();
- }
- void ActivateCountButtonLevel()
- {
- int playerLevelDone = PlayerPrefs.GetInt("LevelDone");
-
- if(playerLevelDone==0)
- {
- PlayerPrefs.SetInt("LevelDone", 1);
- }
- //Debug.Log(playerLevel);
- for (int i = 0; i < ButtonLevelSelectors.Count; i++)
- {
- if(i>playerLevelDone-1)
- {
- ButtonLevelSelectors[i].GetComponent<Button>().interactable = false;
- }
- else
- {
- ButtonLevelSelectors[i].GetComponent<Button>().interactable = true;
- }
- }
- }
- void OnEnable()
- {
- //Debug.Log("ActivateCountButtonLevel");
- ActivateCountButtonLevel();
- }
- /*void Update()
- {
-
- }*/
- }
|