feat: load dynamically level music

This commit is contained in:
2025-02-09 19:37:37 +01:00
parent a5cdd3ada1
commit 707dee5063
70 changed files with 230 additions and 122 deletions

View 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);
}
}
}