using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Bansonic; #if UNITY_EDITOR using UnityEditor; #endif public class userSettings : MonoBehaviour { [Header("Inspector")] [Tooltip("Documentation text normalized.")] public Text user_login_source_text; [Tooltip("Documentation text normalized.")] public Text user_source_uid_text; [Header("Inspector")] [Tooltip("Documentation text normalized.")] public Dropdown language_dropdown; [Header("Inspector")] [Tooltip("Documentation text normalized.")] public Button export_saveData_button; [Tooltip("Documentation text normalized.")] public Button import_saveData_button; [Tooltip("Documentation text normalized.")] public Button clearup_saveData_button; [Header("Inspector")] [Tooltip("Documentation text normalized.")] public Button view_detailedHighlight_button; private const string RuntimeResourcesPath = "song_songIndex"; private const string EditorAssetsPath = "Assets/Resources/song_songIndex"; [SerializeField] private float clearupConfirmSeconds = 2f; private bool clearupPending; private float clearupExpireTime; private void OnEnable() { if (clearup_saveData_button != null) clearup_saveData_button.onClick.AddListener(OnClearupSaveDataClicked); } private void OnDisable() { if (clearup_saveData_button != null) clearup_saveData_button.onClick.RemoveListener(OnClearupSaveDataClicked); } private void Update() { if (clearupPending && Time.unscaledTime > clearupExpireTime) clearupPending = false; } private void OnClearupSaveDataClicked() { if (clearupPending && Time.unscaledTime <= clearupExpireTime) { clearupPending = false; StartCoroutine(ClearSongDataRoutine()); return; } clearupPending = true; clearupExpireTime = Time.unscaledTime + clearupConfirmSeconds; gNotice.alarm.display("再次按下清空存档"); } private IEnumerator ClearSongDataRoutine() { Dictionary songs = new Dictionary(); SongData[] runtimeSongs = Resources.LoadAll(RuntimeResourcesPath); if (runtimeSongs != null) { for (int i = 0; i < runtimeSongs.Length; i++) { SongData so = runtimeSongs[i]; if (so != null && !songs.ContainsKey(so.songID)) songs.Add(so.songID, so); if ((i % 24) == 0) yield return null; } } #if UNITY_EDITOR string[] guids = AssetDatabase.FindAssets("t:SongData", new[] { EditorAssetsPath }); if (guids != null) { for (int i = 0; i < guids.Length; i++) { string path = AssetDatabase.GUIDToAssetPath(guids[i]); SongData so = AssetDatabase.LoadAssetAtPath(path); if (so != null && !songs.ContainsKey(so.songID)) songs.Add(so.songID, so); if ((i % 24) == 0) yield return null; } } #endif int index = 0; foreach (var kvp in songs) { SongData so = kvp.Value; if (so != null) so.ClearSaveDataAndReload(); index++; if ((index % 16) == 0) yield return null; } } }