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); Debug.Log($"Loaded song: {jsonData.songName}"); } } }