refactor: improve save JSON

This commit is contained in:
2025-02-09 20:26:05 +01:00
parent 0dbc959c19
commit 3026ea5367
12 changed files with 763 additions and 757 deletions

View File

@ -3,6 +3,8 @@ using UnityEngine;
[System.Serializable]
public class Level
{
public string JsonName { get; set; }
public string name;
public string musicName;
public int totalJumps;

View File

@ -19,16 +19,17 @@ public class LevelsLoader : MonoBehaviour
TextAsset[] levelFiles = Resources.LoadAll<TextAsset>("Levels");
foreach (TextAsset jsonTextFile in levelFiles)
{
Level loadedLevel = JsonUtility.FromJson<Level>(jsonTextFile.text);
levels.Add(loadedLevel);
Level level = Level.CreateFromJSON(jsonTextFile.text);
level.JsonName = jsonTextFile.name;
levels.Add(level);
}
levels.Sort((x, y) => x.order.CompareTo(y.order));
}
private void SaveLevelCurrent()
{
string json = JsonUtility.ToJson(levelCurrent, true);
File.WriteAllText(Path.Combine(Application.dataPath, "Resources", "Levels", levelCurrent.name + ".json"), json);
string json = JsonUtility.ToJson(levelCurrent, true) + "\n";
File.WriteAllText(Path.Combine(Application.dataPath, "Resources", "Levels", levelCurrent.JsonName + ".json"), json);
}
public void NextLevel()