mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-12-11 00:27:48 +01:00
feat: navigate between previous and next levels
This commit is contained in:
@@ -1,15 +1,38 @@
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class LevelsLoader : MonoBehaviour
|
||||
{
|
||||
public Level level;
|
||||
public List<Level> levels = new();
|
||||
public Level levelCurrent;
|
||||
|
||||
public void Start()
|
||||
private void Start()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
LoadAllLevels();
|
||||
levelCurrent = levels[0];
|
||||
}
|
||||
|
||||
TextAsset jsonTextFile = Resources.Load<TextAsset>(Path.Combine("Levels", "BackOnTrack"));
|
||||
level = JsonUtility.FromJson<Level>(jsonTextFile.text);
|
||||
private void LoadAllLevels()
|
||||
{
|
||||
TextAsset[] levelFiles = Resources.LoadAll<TextAsset>("Levels");
|
||||
foreach (TextAsset jsonTextFile in levelFiles)
|
||||
{
|
||||
Level loadedLevel = JsonUtility.FromJson<Level>(jsonTextFile.text);
|
||||
levels.Add(loadedLevel);
|
||||
}
|
||||
levels.Sort((x, y) => x.order.CompareTo(y.order));
|
||||
}
|
||||
|
||||
public void NextLevel()
|
||||
{
|
||||
int currentIndex = levels.IndexOf(levelCurrent);
|
||||
levelCurrent = levels[(currentIndex + 1) % levels.Count];
|
||||
}
|
||||
|
||||
public void PreviousLevel()
|
||||
{
|
||||
int currentIndex = levels.IndexOf(levelCurrent);
|
||||
levelCurrent = levels[(currentIndex - 1 + levels.Count) % levels.Count];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user