LevelManager.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class LevelManager : MonoBehaviour
  5. {
  6. public static LevelManager Instance;
  7. public List<Level> ListLevels;
  8. public Level CurLevel;
  9. public const int STAGE_LEVEL = 3;
  10. void Start()
  11. {
  12. Instance = this;
  13. SetLevel(Core.Instance.PlayerData.Stage);
  14. }
  15. public void SetLevel(int indexStage)
  16. {
  17. int indexLevel = Mathf.CeilToInt(indexStage / STAGE_LEVEL);
  18. UIManager.Instance.StageLabel.text = "Level " + (Core.Instance.PlayerData.Stage+1).ToString();
  19. for(var i=0; i< ListLevels.Count;i++)
  20. {
  21. ListLevels[i].gameObject.SetActive(false);
  22. }
  23. ListLevels[indexLevel].gameObject.SetActive(true);
  24. ListLevels[indexLevel].Init();
  25. CurLevel = ListLevels[indexLevel];
  26. ListLevels[indexLevel].ResetLever();
  27. }
  28. public void NextLevel()
  29. {
  30. if (Core.Instance.PlayerData.Stage<= ListLevels.Count * STAGE_LEVEL)
  31. {
  32. //var curLevel = Mathf.CeilToInt(Core.Instance.PlayerData.Stage / STAGE_LEVEL);
  33. SetLevel(Core.Instance.PlayerData.Stage);
  34. }
  35. else
  36. {
  37. UIManager.Instance.GameEnd();
  38. }
  39. //for (var i = 0; i < ListLevels.Count; i++)
  40. //{
  41. // ListLevels[i].gameObject.SetActive(false);
  42. //}
  43. //ListLevels[indexLevel].gameObject.SetActive(true);
  44. //ListLevels[indexLevel].Init();
  45. }
  46. }