Files
2025-06-02 00:48:08 +08:00

36 lines
980 B
C#

using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class SongDataLoader : MonoBehaviour
{
private string jsonDirectory;
public List<SongDataSerializable> loadedSongs = new List<SongDataSerializable>();
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<SongDataSerializable>(json);
loadedSongs.Add(jsonData);
Debug.Log($"Loaded song: {jsonData.songName}");
}
}
}