original ver 25/06/01
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user