using System.Collections; using System.Collections.Generic; using System.IO; using UnityEngine; public class SongDataLoader : MonoBehaviour { private const string SecureCategory = "song_export"; private string jsonDirectory; public List loadedSongs = new List(); [SerializeField] private int _yieldEveryNFiles = 5; void Start() { jsonDirectory = Path.Combine(Application.persistentDataPath, "SongDataJson"); StartCoroutine(LoadAllSongsFromJsonRoutine()); } IEnumerator LoadAllSongsFromJsonRoutine() { List loadedJsonList = SecureSaveVault.LoadAllRawJson(SecureCategory, jsonDirectory); if (loadedJsonList == null || loadedJsonList.Count == 0) { Debug.LogError("JSON 持久化数据不存在"); yield break; } loadedSongs.Clear(); int counter = 0; for (int i = 0; i < loadedJsonList.Count; i++) { string json = loadedJsonList[i]; SongDataSerializable jsonData = JsonUtility.FromJson(json); loadedSongs.Add(jsonData); Debug.Log("Loaded persistent song data from secure vault."); counter++; if (_yieldEveryNFiles > 0 && counter % _yieldEveryNFiles == 0) { yield return null; } } } }