using System.Collections.Generic; using System.IO; using UnityEngine; public class SongDataLoader : MonoBehaviour { private string jsonDirectory; public List loadedSongs = new List(); void Start() { jsonDirectory = Path.Combine(Application.persistentDataPath, "SongDataJson"); LoadAllSongsFromJson(); } void LoadAllSongsFromJson() { if (!Directory.Exists(jsonDirectory)) { Debug.LogError("JSON �ļ��в����ڣ�"); return; } loadedSongs.Clear(); string[] jsonFiles = Directory.GetFiles(jsonDirectory, "*.json"); foreach (string file in jsonFiles) { string json = File.ReadAllText(file); SongDataSerializable jsonData = JsonUtility.FromJson(json); loadedSongs.Add(jsonData); // 由于 SongDataSerializable 现在只存储动态分数,不再包含 songName Debug.Log($"Loaded persistent song data from: {Path.GetFileName(file)}"); } } }