mirror of
https://github.com/boudji-ludwig-pett/cnam-geometry-dash.git
synced 2025-06-27 11:58:51 +02:00
refactor: improve save JSON
This commit is contained in:
@ -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;
|
||||
|
@ -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()
|
||||
|
Reference in New Issue
Block a user