Level selector was already working after work by William but some small bugs remained to be fixed + it wasn't possible to return to level selector once we were in the level. - it's now possible to go back to level selector from Level - LevelManagerScript is no longer a singleton (this way, it resets with the Game scene unloading) - Added a property drawer for using scene files in inspectors
82 lines
2.3 KiB
C#
82 lines
2.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine.UI;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using System;
|
|
using UnityEditor;
|
|
|
|
public class WorldMapManager : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private GameObject[] _buttonList;
|
|
[SerializeField]
|
|
private Sprite _unlockedIcon;
|
|
[SerializeField]
|
|
private Sprite _lockedIcon;
|
|
[SerializeField]
|
|
private Sprite _savedIcon;
|
|
[Scene][SerializeField]
|
|
private string gameScene;
|
|
|
|
private WorldMapSave _worldMapSave;
|
|
|
|
void Start()
|
|
{
|
|
//TODO: getMajorSaveFile() //Call et obtiens le chemin du fichier de sauvegarde;
|
|
_worldMapSave = new WorldMapSave();
|
|
UnlockLevels();
|
|
|
|
PlayerPrefs.SetInt("LevelToLoad", -1);
|
|
}
|
|
|
|
/**
|
|
* Debloque les niveaux deja debloquer dans le fichier de sauvegarde majeur.
|
|
*/
|
|
public void UnlockLevels()
|
|
{
|
|
int counterIndex = 0;
|
|
foreach(GameObject CurrentLevelButton in _buttonList)
|
|
{
|
|
if (_worldMapSave.GetLevelState(counterIndex) == WorldMapSave.LevelState.UNLOCKED)
|
|
{
|
|
CurrentLevelButton.SetActive(true);
|
|
ShowUnlockedIcon(CurrentLevelButton);
|
|
}
|
|
else if (_worldMapSave.GetLevelState(counterIndex) == WorldMapSave.LevelState.LOCKED)
|
|
{
|
|
//CurrentLevelButton.SetActive(false);
|
|
ShowLockedIcon(CurrentLevelButton);
|
|
}
|
|
else
|
|
{
|
|
CurrentLevelButton.SetActive(true);
|
|
ShowSavedIcon(CurrentLevelButton);
|
|
}
|
|
counterIndex++;
|
|
}
|
|
}
|
|
private void ShowLockedIcon(GameObject currentLevelButton)
|
|
{
|
|
currentLevelButton.GetComponent<Image>().sprite = _lockedIcon;
|
|
}
|
|
|
|
private void ShowUnlockedIcon(GameObject currentLevelButton)
|
|
{
|
|
currentLevelButton.GetComponent<Image>().sprite = _unlockedIcon;
|
|
}
|
|
private void ShowSavedIcon(GameObject currentLevelButton)
|
|
{
|
|
currentLevelButton.GetComponent<Image>().sprite = _savedIcon;
|
|
}
|
|
|
|
public void CallLevelWorld1(int levelToCall)
|
|
{
|
|
if (_buttonList[levelToCall - 1].GetComponent<Image>().sprite.name != "worldmap_level_locked")
|
|
{
|
|
PlayerPrefs.SetInt("LevelToLoad", levelToCall);
|
|
SceneManager.LoadScene(gameScene);
|
|
}
|
|
}
|
|
}
|