UI HUGE UPDATE
This commit is contained in:
@@ -6,6 +6,7 @@ public class SongDataLibrary : MonoBehaviour
|
||||
{
|
||||
public static SongDataLibrary Instance;
|
||||
private Dictionary<int, SongData> songDataDictionary = new Dictionary<int, SongData>();
|
||||
private Coroutine loadCoroutine;
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
|
||||
private static void EnsureRuntimeInstance()
|
||||
@@ -38,7 +39,7 @@ public class SongDataLibrary : MonoBehaviour
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
StartCoroutine(LoadSongDataCoroutine());
|
||||
BeginLoad();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -50,10 +51,12 @@ public class SongDataLibrary : MonoBehaviour
|
||||
{
|
||||
if (IsLoading || IsLoaded)
|
||||
{
|
||||
loadCoroutine = null;
|
||||
yield break;
|
||||
}
|
||||
|
||||
IsLoading = true;
|
||||
IsLoaded = false;
|
||||
songDataDictionary.Clear();
|
||||
|
||||
// Allow one frame to render before heavy load begins
|
||||
@@ -73,8 +76,10 @@ public class SongDataLibrary : MonoBehaviour
|
||||
if (songList != null && songList.songs != null && songList.songs.Count > 0)
|
||||
{
|
||||
yield return LoadFromList(songList.songs, "songList");
|
||||
yield return LoadFromRuntimeRegistry("runtimeSongs");
|
||||
IsLoaded = true;
|
||||
IsLoading = false;
|
||||
loadCoroutine = null;
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
@@ -98,6 +103,7 @@ public class SongDataLibrary : MonoBehaviour
|
||||
|
||||
IsLoaded = true;
|
||||
IsLoading = false;
|
||||
loadCoroutine = null;
|
||||
}
|
||||
|
||||
private IEnumerator LoadFromPath(string path, string label)
|
||||
@@ -174,6 +180,44 @@ public class SongDataLibrary : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator LoadFromRuntimeRegistry(string label)
|
||||
{
|
||||
SongData[] runtimeSongs = DlcRuntimeRegistry.GetAllSongs();
|
||||
if (runtimeSongs == null || runtimeSongs.Length == 0)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
int yielded = 0;
|
||||
for (int i = 0; i < runtimeSongs.Length; i++)
|
||||
{
|
||||
SongData data = runtimeSongs[i];
|
||||
if (data == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!songDataDictionary.ContainsKey(data.songID))
|
||||
{
|
||||
songDataDictionary.Add(data.songID, data);
|
||||
if (logLoadProgress)
|
||||
{
|
||||
Debug.Log("Loaded SongData [" + label + "] songID: " + data.songID + ", name: " + data.songName);
|
||||
}
|
||||
}
|
||||
else if (logLoadProgress)
|
||||
{
|
||||
Debug.LogWarning("Duplicate songID: " + data.songID);
|
||||
}
|
||||
|
||||
yielded++;
|
||||
if (yieldEvery > 0 && (yielded % yieldEvery) == 0)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
public SongData GetSongDataByID(int songID)
|
||||
{
|
||||
if (songDataDictionary.ContainsKey(songID))
|
||||
@@ -185,4 +229,38 @@ public SongData GetSongDataByID(int songID)
|
||||
Debug.LogError("未找到 songID: " + songID);
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<SongData> GetAllSongs()
|
||||
{
|
||||
return new List<SongData>(songDataDictionary.Values);
|
||||
}
|
||||
|
||||
public void RefreshLibrary()
|
||||
{
|
||||
if (!isActiveAndEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (loadCoroutine != null)
|
||||
{
|
||||
StopCoroutine(loadCoroutine);
|
||||
loadCoroutine = null;
|
||||
}
|
||||
|
||||
IsLoaded = false;
|
||||
IsLoading = false;
|
||||
songDataDictionary.Clear();
|
||||
BeginLoad();
|
||||
}
|
||||
|
||||
private void BeginLoad()
|
||||
{
|
||||
if (loadCoroutine != null)
|
||||
{
|
||||
StopCoroutine(loadCoroutine);
|
||||
}
|
||||
|
||||
loadCoroutine = StartCoroutine(LoadSongDataCoroutine());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user