157 lines
5.0 KiB
C#
157 lines
5.0 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Bansonic;
|
|
using UnityEngine.SceneManagement;
|
|
#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 = 5f;
|
|
private int clearupClickCount = 0;
|
|
private float clearupExpireTime;
|
|
|
|
private void OnEnable()
|
|
{
|
|
if (clearup_saveData_button != null)
|
|
clearup_saveData_button.onClick.AddListener(OnClearupSaveDataClicked);
|
|
|
|
if (export_saveData_button != null) export_saveData_button.onClick.AddListener(ResetClearupCounter);
|
|
if (import_saveData_button != null) import_saveData_button.onClick.AddListener(ResetClearupCounter);
|
|
if (view_detailedHighlight_button != null) view_detailedHighlight_button.onClick.AddListener(ResetClearupCounter);
|
|
if (language_dropdown != null) language_dropdown.onValueChanged.AddListener(_ => ResetClearupCounter());
|
|
|
|
ResetClearupCounter();
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
if (clearup_saveData_button != null)
|
|
clearup_saveData_button.onClick.RemoveListener(OnClearupSaveDataClicked);
|
|
|
|
if (export_saveData_button != null) export_saveData_button.onClick.RemoveListener(ResetClearupCounter);
|
|
if (import_saveData_button != null) import_saveData_button.onClick.RemoveListener(ResetClearupCounter);
|
|
if (view_detailedHighlight_button != null) view_detailedHighlight_button.onClick.RemoveListener(ResetClearupCounter);
|
|
if (language_dropdown != null) language_dropdown.onValueChanged.RemoveListener(_ => ResetClearupCounter());
|
|
|
|
ResetClearupCounter();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (clearupClickCount > 0 && Time.unscaledTime > clearupExpireTime)
|
|
{
|
|
ResetClearupCounter();
|
|
}
|
|
}
|
|
|
|
private void ResetClearupCounter()
|
|
{
|
|
clearupClickCount = 0;
|
|
}
|
|
|
|
private void OnClearupSaveDataClicked()
|
|
{
|
|
if (clearupClickCount > 0 && Time.unscaledTime > clearupExpireTime)
|
|
{
|
|
ResetClearupCounter();
|
|
}
|
|
|
|
clearupClickCount++;
|
|
clearupExpireTime = Time.unscaledTime + clearupConfirmSeconds;
|
|
|
|
if (clearupClickCount == 1)
|
|
{
|
|
gNotice.warning.display("此操作将重置存档");
|
|
}
|
|
else if (clearupClickCount == 2)
|
|
{
|
|
gNotice.error.display("再次点击以确认此危险操作");
|
|
}
|
|
else if (clearupClickCount >= 3)
|
|
{
|
|
ResetClearupCounter();
|
|
StartCoroutine(ClearSongDataRoutine());
|
|
}
|
|
}
|
|
|
|
private IEnumerator ClearSongDataRoutine()
|
|
{
|
|
Dictionary<int, SongData> songs = new Dictionary<int, SongData>();
|
|
|
|
SongData[] runtimeSongs = Resources.LoadAll<SongData>(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<SongData>(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;
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
AssetDatabase.SaveAssets();
|
|
#endif
|
|
|
|
// 完成后返回主界面
|
|
SceneManager.LoadScene("Main_main");
|
|
}
|
|
}
|