using System.IO; using UnityEngine; public class SongDataManager : MonoBehaviour { private string jsonDirectory; [Header("Settings")] public bool autoSaveOnStart = false; void Start() { jsonDirectory = Path.Combine(Application.persistentDataPath, "song_json_export"); if (!Directory.Exists(jsonDirectory)) { Directory.CreateDirectory(jsonDirectory); Debug.Log("Created song JSON directory: " + jsonDirectory); } if (autoSaveOnStart) { StartCoroutine(SaveAllSongDataToJsonRoutine()); } } public void TriggerSaveAllSongs() { StartCoroutine(SaveAllSongDataToJsonRoutine()); } System.Collections.IEnumerator SaveAllSongDataToJsonRoutine() { SongData[] allSongData = Resources.LoadAll("song_songIndex"); if (allSongData.Length == 0) { Debug.LogWarning("No SongData assets found in Resources/song_songIndex."); yield break; } Debug.Log($"Start exporting {allSongData.Length} songs to JSON..."); 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, true); string filePath = Path.Combine(jsonDirectory, song.songID + ".json"); File.WriteAllText(filePath, json); yield return null; } Debug.Log("All song JSON files exported."); } }