功能批量实现 优化 服务端 新浮动小游戏框架 新界面UI

This commit is contained in:
FloatGaming
2026-04-24 13:20:16 +08:00
parent e0bc0bbf08
commit 5eec879582
257 changed files with 38481 additions and 1288 deletions
+92 -27
View File
@@ -119,6 +119,7 @@ public class SongData : ScriptableObject
public string thisLevel_overallDescription;
private bool _isPersistentDataLoaded = false;
private bool _isPersistentDataLoading = false;
private void OnValidate()
{
@@ -291,14 +292,33 @@ public class SongData : ScriptableObject
if (chartFileMap == null) chartFileMap = new Dictionary<int, TextAsset>();
if (chartFiles == null) chartFiles = new List<ChartFileEntry>();
// 灏濊瘯浠庢寔涔呭寲瀛樺偍鍔犺浇鏁版嵁
LoadPersistent();
// Keep editor inspection behavior unchanged while avoiding full runtime restore for every song asset.
if (!Application.isPlaying)
{
LoadPersistent();
}
SyncRecordsFromChartFiles();
SyncChartFileMap();
}
public void EnsurePersistentDataLoaded()
{
if (_isPersistentDataLoaded || _isPersistentDataLoading)
{
return;
}
LoadPersistent();
}
public int CalculateHighestPersonalRecord()
{
EnsurePersistentDataLoaded();
return CalculateHighestPersonalRecordInternal();
}
private int CalculateHighestPersonalRecordInternal()
{
if (personalRecordMap == null) personalRecordMap = new Dictionary<int, int>();
if (idolRecordMap == null) idolRecordMap = new Dictionary<int, int>();
@@ -382,32 +402,47 @@ public class SongData : ScriptableObject
/// 浠庢寔涔呭寲 JSON 鎭㈠鏁版嵁銆? /// 鏍¢獙閫昏緫宸茶縼绉昏嚦 DataCheck 鑴氭湰锛屾澶勪粎鎵ц鍩虹鍔犺浇銆? /// </summary>
public void LoadPersistent()
{
if (_isPersistentDataLoaded) return;
string json;
if (SecureSaveVault.TryLoadRawJson(SecureSaveCategory, songID.ToString(), out json, GetLegacySavePath()))
if (_isPersistentDataLoaded || _isPersistentDataLoading)
{
try
return;
}
_isPersistentDataLoading = true;
try
{
string json;
if (SecureSaveVault.TryLoadRawJson(SecureSaveCategory, songID.ToString(), out json, GetLegacySavePath()))
{
// 灏濊瘯瑙f瀽鏁版嵁
SongDataSerializable serializable = JsonUtility.FromJson<SongDataSerializable>(json);
if (serializable != null)
try
{
serializable.ApplyTo(this);
SyncEntriesFromMaps();
_isPersistentDataLoaded = true;
Debug.Log($"[SongData] {songName} (ID:{songID}) data restored from persistent storage.");
SongDataSerializable serializable = JsonUtility.FromJson<SongDataSerializable>(json);
if (serializable != null)
{
serializable.ApplyTo(this);
SyncEntriesFromMaps();
}
else
{
ResetRuntimeProgressStateWithoutSaving();
}
}
catch (System.Exception e)
{
ResetRuntimeProgressStateWithoutSaving();
_isPersistentDataLoaded = true;
Debug.LogWarning($"[SongData] {songName} base load failed and was reset: {e.Message}");
}
}
catch (System.Exception e)
else
{
Debug.LogWarning($"[SongData] {songName} 鍩虹鍔犺浇澶辫触: {e.Message}");
ResetRuntimeProgressStateWithoutSaving();
_isPersistentDataLoaded = true;
}
}
else
finally
{
ResetRuntimeProgressStateWithoutSaving();
_isPersistentDataLoaded = true;
_isPersistentDataLoading = false;
}
}
@@ -602,6 +637,7 @@ public class SongData : ScriptableObject
public void UpdateDifficultyRecord(int difficulty, int pmScore, int idolScore)
{
EnsurePersistentDataLoaded();
if (personalRecordMap == null) personalRecordMap = new Dictionary<int, int>();
if (idolRecordMap == null) idolRecordMap = new Dictionary<int, int>();
@@ -621,11 +657,12 @@ public class SongData : ScriptableObject
entry.totalPersonalRecordForThisDifficulty = newTotal;
}
CalculateHighestPersonalRecord();
CalculateHighestPersonalRecordInternal();
}
public void ApplySettlementResult(int difficulty, int pmScore, int idolScore, int maxScoreSum)
{
EnsurePersistentDataLoaded();
if (difficulty < 0) return;
if (personalRecordMap == null) personalRecordMap = new Dictionary<int, int>();
@@ -710,8 +747,29 @@ public class SongData : ScriptableObject
UpdateOverallRecordsFromEntries();
}
private int GetPersonalRecordDirect(int difficulty)
{
if (personalRecordMap == null)
{
return 0;
}
return personalRecordMap.TryGetValue(difficulty, out int value) ? value : 0;
}
private int GetIdolRecordDirect(int difficulty)
{
if (idolRecordMap == null)
{
return 0;
}
return idolRecordMap.TryGetValue(difficulty, out int value) ? value : 0;
}
public void GetAbsoluteHighestScore(out int highestScore, out int bestDifficulty, out string bestDifficultyName)
{
EnsurePersistentDataLoaded();
highestScore = 0;
bestDifficulty = -1;
bestDifficultyName = "";
@@ -723,7 +781,7 @@ public class SongData : ScriptableObject
ChartFileEntry entry = chartFiles[i];
if (entry == null) continue;
int total = GetPersonalRecord(entry.difficulty) + GetIdolRecord(entry.difficulty);
int total = GetPersonalRecordDirect(entry.difficulty) + GetIdolRecordDirect(entry.difficulty);
if (total <= 0) total = entry.totalPersonalRecordForThisDifficulty;
if (total <= 0) total = entry.chartPersonalRecordForThisDifficulty + entry.idolPersonalRecordForThisDifficulty;
@@ -742,7 +800,7 @@ public class SongData : ScriptableObject
foreach (var kvp in personalRecordMap)
{
int diff = kvp.Key;
int total = kvp.Value + GetIdolRecord(diff);
int total = kvp.Value + GetIdolRecordDirect(diff);
if (total > highestScore || bestDifficulty == -1)
{
highestScore = total;
@@ -766,6 +824,7 @@ public class SongData : ScriptableObject
public void UpdatePersonalRecord(int difficulty, int newScore)
{
EnsurePersistentDataLoaded();
if (personalRecordMap == null) personalRecordMap = new Dictionary<int, int>();
if (!personalRecordMap.ContainsKey(difficulty) || newScore > personalRecordMap[difficulty])
personalRecordMap[difficulty] = newScore;
@@ -778,7 +837,7 @@ public class SongData : ScriptableObject
entry.totalPersonalRecordForThisDifficulty = personalRecordMap[difficulty] + idol;
}
CalculateHighestPersonalRecord();
CalculateHighestPersonalRecordInternal();
}
private void UpdateOverallRecordsFromEntries()
@@ -796,8 +855,8 @@ public class SongData : ScriptableObject
int total = entry.totalPersonalRecordForThisDifficulty;
if (total <= 0)
{
int p = GetPersonalRecord(entry.difficulty);
int idol = GetIdolRecord(entry.difficulty);
int p = GetPersonalRecordDirect(entry.difficulty);
int idol = GetIdolRecordDirect(entry.difficulty);
total = p + idol;
}
@@ -822,7 +881,7 @@ public class SongData : ScriptableObject
foreach (var kvp in personalRecordMap)
{
int diff = kvp.Key;
int total = kvp.Value + GetIdolRecord(diff);
int total = kvp.Value + GetIdolRecordDirect(diff);
if (total > highestTotal) highestTotal = total;
}
personalRecord = highestTotal;
@@ -843,6 +902,7 @@ public class SongData : ScriptableObject
public void UpdateIdolRecord(int difficulty, int newIdolScore)
{
EnsurePersistentDataLoaded();
if (idolRecordMap == null) idolRecordMap = new Dictionary<int, int>();
if (!idolRecordMap.ContainsKey(difficulty) || newIdolScore > idolRecordMap[difficulty])
idolRecordMap[difficulty] = newIdolScore;
@@ -855,11 +915,12 @@ public class SongData : ScriptableObject
entry.totalPersonalRecordForThisDifficulty = personal + idolRecordMap[difficulty];
}
CalculateHighestPersonalRecord();
CalculateHighestPersonalRecordInternal();
}
public void UpdateChartScore(int difficulty, int newChartScore)
{
EnsurePersistentDataLoaded();
if (chartScoreMap == null) chartScoreMap = new Dictionary<int, int>();
chartScoreMap[difficulty] = newChartScore;
@@ -870,24 +931,28 @@ public class SongData : ScriptableObject
public int GetPersonalRecord(int difficulty)
{
EnsurePersistentDataLoaded();
if (personalRecordMap == null) return 0;
return personalRecordMap.TryGetValue(difficulty, out int v) ? v : 0;
}
public int GetIdolRecord(int difficulty)
{
EnsurePersistentDataLoaded();
if (idolRecordMap == null) return 0;
return idolRecordMap.TryGetValue(difficulty, out int v) ? v : 0;
}
public int GetChartScore(int difficulty)
{
EnsurePersistentDataLoaded();
if (chartScoreMap == null) return 0;
return chartScoreMap.TryGetValue(difficulty, out int v) ? v : 0;
}
public TextAsset GetChartFile(int difficulty)
{
EnsurePersistentDataLoaded();
if (chartFiles != null)
{
for (int i = 0; i < chartFiles.Count; i++)
@@ -952,7 +1017,7 @@ public class SongData : ScriptableObject
entry.totalPersonalRecordForThisDifficulty = p + idol;
}
CalculateHighestPersonalRecord();
CalculateHighestPersonalRecordInternal();
}
}