加入用户最近100场战绩记录并实现展示
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using System.Collections;
|
||||
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<SongDataSerializable> loadedSongs = new List<SongDataSerializable>();
|
||||
[SerializeField] private int _yieldEveryNFiles = 5;
|
||||
@@ -17,26 +18,27 @@ public class SongDataLoader : MonoBehaviour
|
||||
|
||||
IEnumerator LoadAllSongsFromJsonRoutine()
|
||||
{
|
||||
if (!Directory.Exists(jsonDirectory))
|
||||
List<string> loadedJsonList = SecureSaveVault.LoadAllRawJson(SecureCategory, jsonDirectory);
|
||||
if (loadedJsonList == null || loadedJsonList.Count == 0)
|
||||
{
|
||||
Debug.LogError("JSON �ļ��в����ڣ�");
|
||||
Debug.LogError("JSON 持久化数据不存在");
|
||||
yield break;
|
||||
}
|
||||
|
||||
loadedSongs.Clear();
|
||||
IEnumerable<string> jsonFiles = Directory.EnumerateFiles(jsonDirectory, "*.json");
|
||||
int counter = 0;
|
||||
|
||||
foreach (string file in jsonFiles)
|
||||
for (int i = 0; i < loadedJsonList.Count; i++)
|
||||
{
|
||||
string json = File.ReadAllText(file);
|
||||
string json = loadedJsonList[i];
|
||||
SongDataSerializable jsonData = JsonUtility.FromJson<SongDataSerializable>(json);
|
||||
loadedSongs.Add(jsonData);
|
||||
// 由于 SongDataSerializable 现在只存储动态分数,不再包含 songName
|
||||
Debug.Log($"Loaded persistent song data from: {Path.GetFileName(file)}");
|
||||
Debug.Log("Loaded persistent song data from secure vault.");
|
||||
counter++;
|
||||
if (_yieldEveryNFiles > 0 && counter % _yieldEveryNFiles == 0)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user