12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System.Collections.Generic;
- using UnityEngine;
- using System.Collections;
- 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++)
- {
- Transform button = NGUITools.AddChild(parent, levelButtonPrefab).transform;
- Vector3 pos = new Vector3(0, posY, 0);
- button.localPosition = pos;
- posY -= BUTTON_SPACING;
- var label = button.GetComponentInChildren<UILabel>();
- 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 playerLevel = PlayerPrefs.GetInt("Level");
-
- if(playerLevel==0)
- {
- PlayerPrefs.SetInt("Level", 1);
- }
- playerLevel = PlayerPrefs.GetInt("Level");
- //Debug.Log(playerLevel);
- for (int i = 0; i < ButtonLevelSelectors.Count; i++)
- {
- if(i>playerLevel-1)
- {
- ButtonLevelSelectors[i].ButtonWithTwoState.DeactivateButton();
- }
- else
- {
- ButtonLevelSelectors[i].ButtonWithTwoState.ActivateButton();
- }
- }
- }
- void OnEnable()
- {
- //Debug.Log("ActivateCountButtonLevel");
- ActivateCountButtonLevel();
- }
- /*void Update()
- {
-
- }*/
- }
|