55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using System.IO;
|
|
using UnityEngine;
|
|
|
|
public class SongDataManager : MonoBehaviour
|
|
{
|
|
private const string SecureCategory = "song_export";
|
|
private string jsonDirectory;
|
|
|
|
[Header("Settings")]
|
|
public bool autoSaveOnStart = false;
|
|
|
|
void Start()
|
|
{
|
|
jsonDirectory = Path.Combine(Application.persistentDataPath, "song_json_export");
|
|
|
|
if (autoSaveOnStart)
|
|
{
|
|
StartCoroutine(SaveAllSongDataToJsonRoutine());
|
|
}
|
|
}
|
|
|
|
public void TriggerSaveAllSongs()
|
|
{
|
|
StartCoroutine(SaveAllSongDataToJsonRoutine());
|
|
}
|
|
|
|
System.Collections.IEnumerator SaveAllSongDataToJsonRoutine()
|
|
{
|
|
SongData[] allSongData = RuntimeResourcesCache.LoadSongIndex();
|
|
|
|
if (allSongData.Length == 0)
|
|
{
|
|
Debug.LogWarning("No SongData assets found in Resources/song_songIndex.");
|
|
yield break;
|
|
}
|
|
|
|
Debug.Log($"Start exporting {allSongData.Length} songs to secure vault...");
|
|
|
|
for (int i = 0; i < allSongData.Length; i++)
|
|
{
|
|
SongData song = allSongData[i];
|
|
if (song == null) continue;
|
|
|
|
SongDataSerializable jsonData = new SongDataSerializable(song);
|
|
string json = JsonUtility.ToJson(jsonData, false);
|
|
string legacyPath = Path.Combine(jsonDirectory, song.songID + ".json");
|
|
SecureSaveVault.SaveRawJson(SecureCategory, song.songID.ToString(), json, legacyPath);
|
|
|
|
yield return null;
|
|
}
|
|
|
|
Debug.Log("All song JSON files exported to secure vault.");
|
|
}
|
|
}
|