mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-12-11 00:27:48 +01:00
feat: load dynamically level music
This commit is contained in:
31
Assets/Scripts/LevelsLoader.cs
Normal file
31
Assets/Scripts/LevelsLoader.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System.IO;
|
||||
using System.Runtime.Serialization.Json;
|
||||
using UnityEngine;
|
||||
|
||||
public class LevelsLoader : MonoBehaviour
|
||||
{
|
||||
public Level level;
|
||||
|
||||
public void Start()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
|
||||
// var jsonTextFile = Resources.Load<TextAsset>("Text/jsonFile01");
|
||||
//Then use JsonUtility.FromJson<T>() to deserialize jsonTextFile into an object
|
||||
|
||||
string path = Path.Combine(Application.dataPath, "Levels", "back-on-track.json");
|
||||
if (File.Exists(path))
|
||||
{
|
||||
string json = File.ReadAllText(path);
|
||||
using (MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(json)))
|
||||
{
|
||||
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Level));
|
||||
level = (Level)serializer.ReadObject(stream);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Level file not found: " + path);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user