功能批量实现 优化 服务端 新浮动小游戏框架 新界面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
@@ -4,9 +4,10 @@ using UnityEngine.UI;
using System.Collections.Generic;
using TMPro;
public class BeatmapManager : MonoBehaviour
{
public static BeatmapManager Instance { get; private set; }
public class BeatmapManager : MonoBehaviour
{
private const bool VerboseLogs = false;
public static BeatmapManager Instance { get; private set; }
private void Awake()
{
@@ -26,11 +27,11 @@ public class BeatmapManager : MonoBehaviour
/// Called by previous scene to hand over a SongData SO and difficulty to this manager after scene load.
/// This stores the pair in static fields so BeatmapManager.Start can pick them up.
/// </summary>
public static void SetPendingSong(SongData song, int difficulty)
{
pendingSongData = song;
pendingDifficulty = difficulty;
Debug.LogWarning($"BeatmapManager.SetPendingSong called: song={(song==null?"NULL":song.songName)}, difficulty={difficulty}");
public static void SetPendingSong(SongData song, int difficulty)
{
pendingSongData = song;
pendingDifficulty = difficulty;
if (VerboseLogs) Debug.Log($"BeatmapManager.SetPendingSong called: song={(song==null?"NULL":song.songName)}, difficulty={difficulty}");
}
[Header("Assigned SongData (set at runtime from previous scene or via Inspector)")]
@@ -42,12 +43,12 @@ public class BeatmapManager : MonoBehaviour
/// Public API to accept a SongData at runtime (can be called by other scripts after scene load)
/// Also sets inspector-exposed fields so you can visually confirm in Editor during play.
/// </summary>
public void AcceptSongData(SongData song, int difficulty)
{
assignedSongData = song;
assignedDifficulty = difficulty;
Debug.LogWarning($"BeatmapManager.AcceptSongData: accepted song={(song==null?"NULL":song.songName)}, difficulty={difficulty}");
UpdateGameplayUI();
public void AcceptSongData(SongData song, int difficulty)
{
assignedSongData = song;
assignedDifficulty = difficulty;
if (VerboseLogs) Debug.Log($"BeatmapManager.AcceptSongData: accepted song={(song==null?"NULL":song.songName)}, difficulty={difficulty}");
UpdateGameplayUI();
}
public Beatmap beatmap; // Documentation text normalized.
@@ -119,7 +120,7 @@ public class BeatmapManager : MonoBehaviour
if (File.Exists(path))
{
string json = File.ReadAllText(path);
Debug.Log("读取 JSON 路径: " + path);
if (VerboseLogs) Debug.Log("读取 JSON 路径: " + path);
ProcessJsonAndLoad(json);
}
else
@@ -228,7 +229,7 @@ public class BeatmapManager : MonoBehaviour
// NOTE: Do NOT modify parsed.notes here. globalDelaySeconds will be applied to audio playback instead.
beatmap = parsed;
Debug.Log("ParseJsonOnly: parsed beatmap " + beatmap.title);
if (VerboseLogs) Debug.Log("ParseJsonOnly: parsed beatmap " + beatmap.title);
// Documentation text normalized.
SetupEnemiesAndHP();
@@ -244,7 +245,7 @@ public class BeatmapManager : MonoBehaviour
beatmap = loadedBeatmap;
parsedNoteAmount = (beatmap != null && beatmap.notes != null) ? beatmap.notes.Length : 0;
CalculateNoteScores(beatmap);
Debug.Log("谱面加载完成,当前 Beatmap 标题: " + (beatmap != null ? beatmap.title : "null"));
if (VerboseLogs) Debug.Log("谱面加载完成,当前 Beatmap 标题: " + (beatmap != null ? beatmap.title : "null"));
// No globalDelaySeconds available in this path. Call NoteSpawner directly.
noteSpawner.LoadBeatmap(beatmap);
ApplyTrackScoreCaps(beatmap);
@@ -306,7 +307,7 @@ public class BeatmapManager : MonoBehaviour
Debug.LogWarning($"LoadBeatmapFromSongData: chart TextAsset for difficulty {difficulty} is null on song {song.songName}");
return false;
}
Debug.LogWarning($"LoadBeatmapFromSongData: loading chart for song {song.songName}, difficulty {difficulty}, parseOnly={parseOnly}, chartSize={(ta.text != null ? ta.text.Length : 0)}");
if (VerboseLogs) Debug.Log($"LoadBeatmapFromSongData: loading chart for song {song.songName}, difficulty {difficulty}, parseOnly={parseOnly}, chartSize={(ta.text != null ? ta.text.Length : 0)}");
return LoadBeatmapFromTextAsset(ta, parseOnly);
}
@@ -317,7 +318,7 @@ public class BeatmapManager : MonoBehaviour
if (pendingSongData == null && assignedSongData == null)
{
assignedSongData = SongDataHolder.SelectedSongData;
Debug.Log($"[BeatmapManager] No pending song, fallback to SongDataHolder: {(assignedSongData != null ? assignedSongData.songName : "null")}");
if (VerboseLogs) Debug.Log($"[BeatmapManager] No pending song, fallback to SongDataHolder: {(assignedSongData != null ? assignedSongData.songName : "null")}");
}
// 无论如何,在加载谱面前先同步敌人编队到 teamUIController
@@ -325,17 +326,17 @@ public class BeatmapManager : MonoBehaviour
if (pendingSongData != null)
{
Debug.LogWarning($"BeatmapManager.Start: pendingSongData detected: {pendingSongData.songName}, difficulty={pendingDifficulty}");
if (VerboseLogs) Debug.Log($"BeatmapManager.Start: pendingSongData detected: {pendingSongData.songName}, difficulty={pendingDifficulty}");
// Documentation text normalized.
assignedSongData = pendingSongData;
assignedDifficulty = pendingDifficulty;
// Documentation text normalized.
bool ok = LoadBeatmapFromSongData(assignedSongData, assignedDifficulty, true);
if (!ok) Debug.LogWarning("BeatmapManager.Start: LoadBeatmapFromSongData failed");
else
{
Debug.LogWarning("BeatmapManager.Start: chart parsed from SongData, attempting to assign audio and pause system");
if (!ok) Debug.LogWarning("BeatmapManager.Start: LoadBeatmapFromSongData failed");
else
{
if (VerboseLogs) Debug.Log("BeatmapManager.Start: chart parsed from SongData, attempting to assign audio and pause system");
// try to assign audio to GameManager.musicSource
var gm = FindAnyObjectByType<GameManager>();
@@ -345,31 +346,31 @@ public class BeatmapManager : MonoBehaviour
{
gm.musicSource.clip = assignedSongData.audioFile;
gm.musicSource.loop = false;
Debug.LogWarning("Assigned SongData.audioFile to GameManager.musicSource.clip (from SO)");
if (VerboseLogs) Debug.Log("Assigned SongData.audioFile to GameManager.musicSource.clip (from SO)");
}
else if (!string.IsNullOrEmpty(parsedMusicFile))
{
Debug.LogWarning($"Attempting Resources.Load for audio: {parsedMusicFile}");
if (VerboseLogs) Debug.Log($"Attempting Resources.Load for audio: {parsedMusicFile}");
var ac = Resources.Load<AudioClip>(parsedMusicFile);
if (ac != null)
{
gm.musicSource.clip = ac;
gm.musicSource.loop = false;
Debug.LogWarning("Assigned audio via Resources.Load(parsedMusicFile)");
if (VerboseLogs) Debug.Log("Assigned audio via Resources.Load(parsedMusicFile)");
}
else
{
Debug.LogWarning($"Resources.Load failed for '{parsedMusicFile}'");
if (VerboseLogs) Debug.Log($"Resources.Load failed for '{parsedMusicFile}'");
}
}
else
{
Debug.LogWarning("No audio available on SongData and parsedMusicFile empty");
if (VerboseLogs) Debug.Log("No audio available on SongData and parsedMusicFile empty");
}
}
else
{
Debug.LogWarning("GameManager or its musicSource not found; audio not assigned");
if (VerboseLogs) Debug.Log("GameManager or its musicSource not found; audio not assigned");
}
// Assign fullscreen image from SongData to background images if available
@@ -382,13 +383,13 @@ public class BeatmapManager : MonoBehaviour
bgMainImage.sprite = bgSprite;
// ensure fully visible
bgMainImage.color = new Color(bgMainImage.color.r, bgMainImage.color.g, bgMainImage.color.b, 1f);
Debug.LogWarning($"Assigned SongData.fullscreen_songPicture to bgMainImage for song {assignedSongData.songName}");
if (VerboseLogs) Debug.Log($"Assigned SongData.fullscreen_songPicture to bgMainImage for song {assignedSongData.songName}");
}
if (bgSpriteRenderer != null)
{
bgSpriteRenderer.sprite = bgSprite;
Debug.LogWarning($"Assigned SongData.fullscreen_songPicture to bgSpriteRenderer for song {assignedSongData.songName}");
if (VerboseLogs) Debug.Log($"Assigned SongData.fullscreen_songPicture to bgSpriteRenderer for song {assignedSongData.songName}");
// 释放引用以节省内存(按要求:完毕后令 sprite renderer = null
bgSpriteRenderer = null;
}
@@ -396,12 +397,12 @@ public class BeatmapManager : MonoBehaviour
if (startCanvas_image != null)
{
startCanvas_image.sprite = bgSprite;
Debug.LogWarning($"Assigned SongData.fullscreen_songPicture to startCanvas_image for song {assignedSongData.songName}");
if (VerboseLogs) Debug.Log($"Assigned SongData.fullscreen_songPicture to startCanvas_image for song {assignedSongData.songName}");
}
if (bgMainImage == null && startCanvas_image == null)
{
Debug.LogWarning("No background Image targets assigned in BeatmapManager; fullscreen sprite not applied");
if (VerboseLogs) Debug.Log("No background Image targets assigned in BeatmapManager; fullscreen sprite not applied");
}
}
@@ -410,11 +411,11 @@ public class BeatmapManager : MonoBehaviour
if (pauseMgr != null)
{
pauseMgr.Pause(true);
Debug.LogWarning("System paused after loading chart and audio to allow player to start");
if (VerboseLogs) Debug.Log("System paused after loading chart and audio to allow player to start");
}
else
{
Debug.LogWarning("PauseManager not found in scene; cannot pause system automatically");
if (VerboseLogs) Debug.Log("PauseManager not found in scene; cannot pause system automatically");
}
}
@@ -426,13 +427,13 @@ public class BeatmapManager : MonoBehaviour
// Documentation text normalized.
if (GameConfig.testMode)
{
Debug.Log("Test mode active: skipping automatic beatmap load in BeatmapManager.Start");
if (VerboseLogs) Debug.Log("Test mode active: skipping automatic beatmap load in BeatmapManager.Start");
}
else
{
// Documentation text normalized.
// Documentation text normalized.
Debug.LogWarning("Default automatic demo beatmap load is commented out to prioritize SO-provided charts.");
if (VerboseLogs) Debug.Log("Default automatic demo beatmap load is commented out to prioritize SO-provided charts.");
}
UpdateGameplayUI();
@@ -524,7 +525,7 @@ public class BeatmapManager : MonoBehaviour
uiController.enemySlotIds = enemyIds;
uiController.PopulateEnemySOsFromIds();
Debug.Log($"[BeatmapManager] SyncEnemyListToUI: {string.Join(",", enemyIds)}");
if (VerboseLogs) Debug.Log($"[BeatmapManager] SyncEnemyListToUI: {string.Join(",", enemyIds)}");
}
private void SetupEnemiesAndHP()
@@ -553,7 +554,7 @@ public class BeatmapManager : MonoBehaviour
if (config.enemyID != 0) activePercentages.Add(config.hpPercentage);
}
foundInDifficulty = true;
Debug.Log($"[BeatmapManager] Using enemyConfigList from ChartFileEntry (difficulty {assignedDifficulty})");
if (VerboseLogs) Debug.Log($"[BeatmapManager] Using enemyConfigList from ChartFileEntry (difficulty {assignedDifficulty})");
}
break;
}
@@ -564,7 +565,7 @@ public class BeatmapManager : MonoBehaviour
{
foreach (var segment in parsedColorSegments)
{
Debug.Log($"Processing colorSegment: enemyID='{segment.enemyID}', percentage={segment.percentage}");
if (VerboseLogs) Debug.Log($"Processing colorSegment: enemyID='{segment.enemyID}', percentage={segment.percentage}");
int enemyId;
if (!int.TryParse(segment.enemyID, out enemyId))
{
@@ -573,7 +574,7 @@ public class BeatmapManager : MonoBehaviour
}
enemyIds.Add(enemyId);
}
Debug.Log($"[BeatmapManager] Using enemyList from Beatmap JSON: {string.Join(",", enemyIds)}");
if (VerboseLogs) Debug.Log($"[BeatmapManager] Using enemyList from Beatmap JSON: {string.Join(",", enemyIds)}");
}
while (enemyIds.Count < 5) enemyIds.Add(0);
@@ -595,7 +596,7 @@ public class BeatmapManager : MonoBehaviour
if (entry.enemyTotalHP_Multiplier > 0.01f)
{
currentMultiplier = entry.enemyTotalHP_Multiplier;
Debug.Log($"[BeatmapManager] Using override enemyTotalHP_Multiplier from SongData: {currentMultiplier}");
if (VerboseLogs) Debug.Log($"[BeatmapManager] Using override enemyTotalHP_Multiplier from SongData: {currentMultiplier}");
}
break;
}
@@ -647,7 +648,7 @@ public class BeatmapManager : MonoBehaviour
}
for (int i = 0; i < activeEnemyCount; i++) individualHPList.Add(baseHp[i]);
Debug.Log($"[BeatmapManager] HP Calc (Custom Percentages) -> Total: {totalHP}, HPs: {string.Join(",", individualHPList)}");
if (VerboseLogs) Debug.Log($"[BeatmapManager] HP Calc (Custom Percentages) -> Total: {totalHP}, HPs: {string.Join(",", individualHPList)}");
}
else
{
@@ -658,7 +659,7 @@ public class BeatmapManager : MonoBehaviour
int hp = basePer + (i < remainder ? 1 : 0);
individualHPList.Add(hp);
}
Debug.Log($"[BeatmapManager] HP Calc (Equal Dist) -> Total: {totalHP}, Active: {activeEnemyCount}, HPs: {string.Join(",", individualHPList)}");
if (VerboseLogs) Debug.Log($"[BeatmapManager] HP Calc (Equal Dist) -> Total: {totalHP}, Active: {activeEnemyCount}, HPs: {string.Join(",", individualHPList)}");
}
uiController.ApplyCalculatedEnemyHP(individualHPList);
@@ -765,7 +766,7 @@ public class BeatmapManager : MonoBehaviour
CalculateNoteScores(parsed);
beatmap = parsed;
Debug.Log("谱面加载完成: " + beatmap.title);
if (VerboseLogs) Debug.Log("谱面加载完成: " + beatmap.title);
if (noteSpawner != null) noteSpawner.LoadBeatmap(beatmap);
else Debug.LogError("NoteSpawner is null in BeatmapManager.");
@@ -797,7 +798,7 @@ public class BeatmapManager : MonoBehaviour
{
perNoteScore = totalChartScore / noteCount;
leftoverScore = totalChartScore % noteCount;
Debug.Log($"Calculated perNoteScore: {perNoteScore}, leftoverScore: {leftoverScore}, noteCount: {noteCount}");
if (VerboseLogs) Debug.Log($"Calculated perNoteScore: {perNoteScore}, leftoverScore: {leftoverScore}, noteCount: {noteCount}");
}
else
{