Rebuild the game as a single code-driven scene with a package-folder pack source
- One empty scene; App builds the canvas, safe-area layout and a shared 5x6 Grid in code. Pages (Intro, Main, Choose, Play, Account, Settings) replace 5 scenes, 5 prefabs and the per-cell spawner/display components. - Packs: the game reads Rhyculator/package/ (with All files access) or the app folder, like a plugged-in USB stick. Zips stay where they are and are extracted to a cache keyed by name/size/mtime; folders are read directly. Scans run every second on a background thread. Old songs/ imports and inbox zips are migrated automatically. - Download packs by 8-char code from the new pack website, or via rhyculator://pack/<code> links; opened/shared zips go into the package folder. - Play: pause/resume/retry, auto-pause on background, combo and progress bar; judging and scoring unchanged. Choose page fits 9:16 screens; empty state, pack delete. Android back key handled everywhere. - Slimming: removed TextMesh Pro, unused 2D/Timeline/VisualScripting/etc. packages and modules, scene template, unused sprites; menu theme wav (20MB) -> ogg (2.3MB). Build profile replaced by explicit settings in BuildAndroid. - Tests: PackLibrary/PackReader/migration/serializer tests (39 passing). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
6d5f66ac6a
commit
ddd5fdc28b
295 files changed
+3854
-82126
No files matched your search
@@ -0,0 +1,79 @@
|
||||
using UnityEngine;
|
||||
|
||||
// 以音訊 DSP 時鐘為準的歌曲時間(秒)
|
||||
// AudioSettings.dspTime 在手機上是以音訊 buffer 為單位跳動,
|
||||
// 這裡用 realtime 在兩次跳動之間補間,並保證時間單調遞增
|
||||
public static class SongClock
|
||||
{
|
||||
public static bool Running { get; private set; }
|
||||
public static bool Paused { get; private set; }
|
||||
|
||||
private static double dspStart;
|
||||
private static double lastDsp;
|
||||
private static double lastDspRealtime;
|
||||
private static double lastReturned;
|
||||
private static double offsetSec;
|
||||
private static double pausedAt;
|
||||
|
||||
// 補間最多往前推 0.1 秒,避免音訊卡住時畫面跑太快
|
||||
private const double MaxExtrapolation = 0.1;
|
||||
|
||||
// applyOffset = false:不套用延遲補償(校正量測時使用)
|
||||
public static void Begin(double dspStartTime, bool applyOffset = true)
|
||||
{
|
||||
dspStart = dspStartTime;
|
||||
lastDsp = AudioSettings.dspTime;
|
||||
lastDspRealtime = Time.realtimeSinceStartupAsDouble;
|
||||
lastReturned = double.MinValue;
|
||||
offsetSec = applyOffset ? PlayerPrefs.GetInt(Prefs.AudioOffsetMs, 0) / 1000.0 : 0;
|
||||
Running = true;
|
||||
Paused = false;
|
||||
}
|
||||
|
||||
// 暫停:時間停在目前的值(音符不會過期),以 Resume 接續
|
||||
public static void Pause()
|
||||
{
|
||||
if (!Running || Paused) return;
|
||||
pausedAt = Now;
|
||||
Paused = true;
|
||||
}
|
||||
|
||||
// 接續:音訊的 audioPos 秒在 DSP 時間 dspAt 播出(延遲補償沿用原本的值)
|
||||
public static void Resume(double audioPos, double dspAt)
|
||||
{
|
||||
double offset = offsetSec;
|
||||
Begin(dspAt - audioPos, false);
|
||||
offsetSec = offset;
|
||||
}
|
||||
|
||||
public static double PausedAt => pausedAt;
|
||||
|
||||
public static void Stop()
|
||||
{
|
||||
Running = false;
|
||||
Paused = false;
|
||||
}
|
||||
|
||||
// 目前歌曲時間;音樂開始前為負值
|
||||
public static double Now
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Running) return 0;
|
||||
if (Paused) return pausedAt;
|
||||
|
||||
double dsp = AudioSettings.dspTime;
|
||||
double real = Time.realtimeSinceStartupAsDouble;
|
||||
if (dsp != lastDsp)
|
||||
{
|
||||
lastDsp = dsp;
|
||||
lastDspRealtime = real;
|
||||
}
|
||||
|
||||
double t = lastDsp + System.Math.Min(real - lastDspRealtime, MaxExtrapolation) - dspStart - offsetSec;
|
||||
if (t < lastReturned) t = lastReturned;
|
||||
lastReturned = t;
|
||||
return t;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user