This commit is contained in:
Sahik committed 2026-12-03 02:00:00 +08:00
1 parent c3bb8d1a9e
commit fd0312270b
26 files changed
+3310 -87

No files matched your search

+25
View File
@@ -80,6 +80,23 @@ public class BotSpawner : MonoBehaviour
{
if (botPrefab == null) return;
// 熱身剛做完 : 平均 FPS 太低就先提示,按「繼續」才生成第一個正式回合 (只檢查一次)
if (SessionPlan.NeedsFpsCheck(settings))
{
SessionPlan.MarkFpsChecked();
float fps = SessionPlan.WarmupFps;
Debug.Log($"BotSpawner : 熱身平均 FPS = {fps:F1}");
if (fps >= 0f && fps < SessionPlan.FpsWarnThreshold)
{
FpsWarning warning = FpsWarning.FindInScene();
if (warning != null && warning.Show(fps, () => StartCoroutine(SpawnWhenUnpaused())))
{
return;
}
Debug.LogWarning("BotSpawner : 場景裡沒有可用的 FpsWarning (或 PauseMenu),不提示直接繼續");
}
}
// 自動配置做完全部回合就不再生成 (RoundProgressHUD 會提示關閉遊戲)
if (!SessionPlan.TryGetCurrent(settings, out SessionPlan.RoundCondition c)) return;
CurrentCondition = c;
@@ -119,6 +136,14 @@ public class BotSpawner : MonoBehaviour
Spawn();
}
// 提示關掉後,等到「這一幀不是暫停」才生成 : 不然新回合的第一幀會被記成回合內的暫停
IEnumerator SpawnWhenUnpaused()
{
yield return null;
yield return new WaitUntil(() => !PauseMenu.IsPaused);
Spawn();
}
// 在範圍內隨機選點 : 要離玩家夠遠,而且不能卡在障礙物或牆裡 ; 試很多次都不行就用最後一次的結果
Vector3 PickSpawnPoint()
{
+90
View File
@@ -0,0 +1,90 @@
using System;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using TMPro;
// 熱身做完、平均 FPS 太低時的提示 (v1.2.0) : 只提醒,不擋錄製
// 由 BotSpawner 在第一個正式回合生成之前呼叫,這時沒有回合在進行,所以不會吃到回合時間,也不會記成回合內的暫停
// 掛在場景裡一直啟用的物件上 (例如 HUD 的 Canvas),提示視窗本身平常隱藏
public class FpsWarning : MonoBehaviour
{
[Header("UI 參照")]
[Tooltip("提示視窗 (Panel),平常隱藏")]
public GameObject panel;
[Tooltip("提示文字 Text (TMP)")]
public TextMeshProUGUI messageText;
[Tooltip("繼續 Button")]
public Button continueButton;
[Tooltip("回主選單 Button")]
public Button menuButton;
[Header("場景")]
public string startSceneName = "StartUI";
private Action onContinue;
private bool wired;
void Start()
{
if (panel != null && onContinue == null) panel.SetActive(false);
WireButtons();
}
// 掛的物件沒啟用時 Start() 不會跑,所以 Show() 也會呼叫一次
void WireButtons()
{
if (wired) return;
wired = true;
if (continueButton != null) continueButton.onClick.AddListener(OnContinueClicked);
if (menuButton != null) menuButton.onClick.AddListener(OnMenuClicked);
}
// 給 BotSpawner 找場景裡的提示 (提示視窗可能是隱藏的,所以也找未啟用的物件)
public static FpsWarning FindInScene()
{
return FindAnyObjectByType<FpsWarning>(FindObjectsInactive.Include);
}
// 顯示提示並暫停 (不顯示暫停視窗) ; 按「繼續」後呼叫 continueAction
// 顯示不出來 (沒接 Panel 或場景沒有 PauseMenu) 時回傳 false,呼叫端直接繼續
public bool Show(float fps, Action continueAction)
{
if (panel == null) return false;
if (!PauseMenu.PauseForPrompt()) return false;
WireButtons();
onContinue = continueAction;
if (messageText != null)
{
messageText.text = $"目前平均 FPS 是 {fps:F0},目標是 {SessionPlan.TargetFps}。\n" +
"建議關掉其他程式,或回主選單勾選「低畫質」。\n" +
"也可以直接繼續。";
}
panel.SetActive(true);
return true;
}
void OnContinueClicked()
{
if (panel != null) panel.SetActive(false);
PauseMenu.ResumeFromPrompt();
Action action = onContinue;
onContinue = null;
action?.Invoke();
}
// 回主選單 : 排程進度照舊 (再進來從第一個正式回合開始,熱身不用重做)
void OnMenuClicked()
{
onContinue = null;
Time.timeScale = 1f;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
SceneManager.LoadScene(startSceneName);
}
}
+2
View File
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 9a00a586eeeb99241b2b77f6cdd35837
+53 -5
View File
@@ -8,6 +8,10 @@ using UnityEngine.InputSystem.UI;
// 遊戲中按 Esc 暫停 : 時間停止、放開滑鼠,選「繼續」或「回到主畫面」
// 切出遊戲視窗 (Alt+Tab 等) 時也會自動暫停
// 暫停期間記錄器不記錄,回合照樣有效
// v1.2.0 : 暫停狀態在每一幀開頭鎖存,同一幀裡所有腳本 (視角、輔助、感知器、武器、記錄器) 看到的都一樣
// 幀中途發生的暫停 / 繼續 (Esc、按鈕、切出視窗) 從下一幀才生效
// 執行順序 -100 : 在 RawMouseInput (-10000) 之後、AimAssist (-10) / PlayerLook (0) / RoundRecorder (100) 之前
[DefaultExecutionOrder(-100)]
public class PauseMenu : MonoBehaviour
{
[Header("UI 參照")]
@@ -23,12 +27,28 @@ public class PauseMenu : MonoBehaviour
[Header("場景")]
public string startSceneName = "StartUI";
// 給其他腳本判斷 (視角、記錄器)
// 給其他腳本判斷 (視角、輔助、感知器、武器、記錄器) : 「這一幀是否暫停」,整幀內不會變
public static bool IsPaused { get; private set; }
// 開始暫停的時間 (跟記錄器同一條時間軸) : 切出視窗時遊戲會停住,記錄器要靠這個知道真正的暫停時間
public static double PauseStartTime { get; private set; }
// 即時的暫停狀態 : 下一幀開頭才複製到 IsPaused
private static bool paused;
// 提示視窗 (例如熱身 FPS 提示) 開著 : 也算暫停,但不顯示暫停視窗,Esc 不作用
private static bool inPrompt;
private static PauseMenu instance;
void Awake()
{
instance = this;
paused = false;
inPrompt = false;
IsPaused = false;
}
void Start()
{
EnsureButtonsClickable();
@@ -40,9 +60,13 @@ public class PauseMenu : MonoBehaviour
void Update()
{
// 先鎖存這一幀的狀態,之後的 Esc 從下一幀才生效
IsPaused = paused;
if (inPrompt) return;
if (Keyboard.current != null && Keyboard.current.escapeKey.wasPressedThisFrame)
{
if (IsPaused) Resume();
if (paused) Resume();
else Pause();
}
}
@@ -50,16 +74,38 @@ public class PauseMenu : MonoBehaviour
// 遊戲視窗失去焦點 (Alt+Tab、點到別的視窗) : 自動暫停,回來時要按「繼續」
void OnApplicationFocus(bool hasFocus)
{
if (!hasFocus && !IsPaused) Pause();
if (!hasFocus && !paused) Pause();
}
void OnDestroy()
{
// 離開場景時一定要恢復,不然下一個場景會停住
if (instance == this) instance = null;
paused = false;
inPrompt = false;
IsPaused = false;
Time.timeScale = 1f;
}
// ===== 提示視窗用 (FpsWarning) =====
// 暫停但不顯示暫停視窗 ; 場景裡沒有 PauseMenu 時回傳 false
public static bool PauseForPrompt()
{
if (instance == null) return false;
inPrompt = true;
if (!paused) instance.Pause();
if (instance.pausePanel != null) instance.pausePanel.SetActive(false);
return true;
}
public static void ResumeFromPrompt()
{
if (instance == null) return;
inPrompt = false;
instance.Resume();
}
// 按鈕要能點,需要 : 場景裡有 EventSystem、Canvas 上有 Graphic Raycaster
// 地圖場景不一定有 (例如沙漠是從 Demo 場景改的),缺的話這裡自動補上
void EnsureButtonsClickable()
@@ -80,7 +126,7 @@ public class PauseMenu : MonoBehaviour
void Pause()
{
IsPaused = true;
paused = true;
PauseStartTime = Time.realtimeSinceStartupAsDouble;
Time.timeScale = 0f;
Cursor.lockState = CursorLockMode.None;
@@ -90,7 +136,7 @@ public class PauseMenu : MonoBehaviour
void Resume()
{
IsPaused = false;
paused = false;
Time.timeScale = 1f;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
@@ -99,6 +145,8 @@ public class PauseMenu : MonoBehaviour
void BackToMenu()
{
paused = false;
inPrompt = false;
IsPaused = false;
Time.timeScale = 1f;
Cursor.lockState = CursorLockMode.None;
+25 -5
View File
@@ -119,7 +119,7 @@ MouseTrail_<ID>_<yyyyMMdd_HHmmss>.zip
| `hit` | 命中一次(霰彈的每顆彈丸各記一次) |
| `kill` | 敵人倒下,回合結束 |
| `reload_start` | 開始換彈 |
| `pause` / `resume` | 暫停 / 繼續。按 Esc 或切出遊戲視窗(Alt+Tab 等)都會暫停。暫停期間 mouse 和 frames 不會有資料,`pause` 的時間是真正開始暫停的時間 |
| `pause` / `resume` | 暫停 / 繼續。按 Esc 或切出遊戲視窗(Alt+Tab 等)都會暫停。暫停期間 mouse 和 frames 不會有資料,`pause` 的時間是真正開始暫停的時間。v1.2.0 起暫停狀態在每一幀開頭決定,幀中途發生的暫停 / 繼續從下一幀才生效,所以每一幀的 mouse 加總都等於 frames 的 `mouse_dx`、`mouse_dy`(v1.1.0 在恢復的那一幀可能有 mouse 回報、但 frames 的位移是 0)。按 Esc 的那一幀仍會記錄,所以 `pause` 的時間不會早於最後一筆 frames 的 `t` |
| `prone_start` / `prone_end` | 開始趴下 / 結束趴下(站起或蹲起)。按 Z 切換。回合開始時已經趴著的話,會在 `round_start` 之後立刻補一筆 `prone_start`;回合結束時還趴著的話不會有 `prone_end` |
不記錄鍵盤按鍵(`prone_start` / `prone_end` 是姿勢改變的事件,不是按鍵事件)。玩家的移動用 `frames_N.csv` 的位置、速度和 `state` 表示,這是物理引擎實際算出的結果(包含加速度、滑鏟、空中轉向),比按鍵本身更能描述「畫面相對於玩家怎麼動」。
@@ -151,22 +151,33 @@ v1.1.0 新增:
|---|---|
| `autoPlan` | 是否為自動配置(正式錄製)。false = 自由模式,條件由玩家自己選 |
| `protocolVersion` | 錄製協定版本 |
| `buildId` | 出包時的 git commit 短碼,用來分辨同版號的不同 build。`-dirty` 表示出包時有未提交的改動,`editor` 表示在編輯器裡錄的 |
| `buildId` | 出包時的 git commit 短碼,用來分辨同版號的不同 build。`-dirty` 表示出包時有未提交的改動,`editor` 表示在編輯器裡錄的。v1.2.0 起出包時若 git 執行不了,會改讀 `.git` 檔案並加上 `-nogit`(無法確認工作區是否乾淨),都讀不到才是 `unknown`;正式發布的 build 應該是乾淨的 7 碼 |
| `sessionId` | 這次執行的代號(跟 zip 檔名的時間相同) |
| `planSeed` | 這次執行的排程種子 |
| `planIndex` | 排程中的第幾項:熱身 0–4,正式 5–84。自由模式為 -1 |
| `blockIndex`、`orderInBlock` | 區塊 0–7、區塊內第幾回合 0–9。熱身與自由模式為 -1 |
| `planIndex` | 排程中的第幾項:v1.1.0 熱身 0–4、正式 5–84;v1.2.0 熱身 0–2、正式 3–52。自由模式為 -1 |
| `blockIndex`、`orderInBlock` | 區塊(v1.1.0 為 0–7,v1.2.0 為 0–4)、區塊內第幾回合 0–9。熱身與自由模式為 -1 |
| `isWarmup` | 熱身回合,分析時請排除 |
| `assistFovDeg` | 作用範圍半徑(度),無輔助時為 0 |
| `roundSeed` | 這一回合的亂數種子:後座力、生成點、機器人動作、延遲抖動都由它開始。機器人動作與抖動的取用次數隨幀而變,所以只能近似重現 |
| `targetFps`、`vSyncCount` | 實際生效的幀率設定,`targetFps` 為 -1 表示不限制 |
v1.2.0 新增:
| 欄位 | 說明 |
|---|---|
| `mouseModel` | 滑鼠型號,玩家選填(最多 40 字),沒填為空字串 |
| `mouseDpi` | 滑鼠 DPI,玩家選填,範圍 100–50000,沒填或超出範圍為 0。回報率沒有欄位,請從 `mouse_N.csv` 的時間間隔計算 |
| `lowQuality` | StartUI 是否勾選「低畫質」(切到最低的畫質等級,只影響畫面,遊戲邏輯與遮擋判定不變) |
| `qualityLevel` | 這一回合實際的畫質等級名稱(`PC` 為預設、`Low` 為低畫質) |
| `warmupFps` | 熱身回合的平均 FPS(熱身的總幀數 ÷ 扣掉暫停的總遊玩秒數)。熱身還沒結束與自由模式為 -1。低於 55 時,遊戲會在第一個正式回合前提示玩家,但不擋錄製,分析時請自行標記 |
## 版本與資料階段
| 階段 | 版本 | 說明 |
|---|---|---|
| 第一階段(data_1) | `appVersion` 皆為 1.0.1 | 兩位玩家,**每人** 150 回合(無輔助 100、有輔助 50),125Hz 滑鼠,60Hz 螢幕,辨識延遲 15ms ± 5ms。先錄完有輔助(強度 20 → 100),再錄無輔助 |
| 第二階段起 | v1.1.0 | 自動配置,見下方「v1.1.0 錄製協定」 |
| 第二階段(data_2) | v1.1.0 | 自動配置,見下方「v1.1.0 錄製協定」 |
| 第三階段(data_3) | v1.2.0 | 與 v1.1.0 只差回合數,見下方「v1.2.0 錄製協定」 |
第一階段兩位玩家的差異:
@@ -187,6 +198,15 @@ v1.1.0 新增:
- 有輔助的回合準心是綠色、無輔助是白色,所以**玩家知道當下有沒有輔助**,但不知道強度。玩家可能因此調整瞄準方式,有無輔助的差異會同時包含輔助本身與玩家的反應。
- 回合存檔成功才進到下一項;中途回主畫面會重做同一項。關閉遊戲後再開是新的 session 與新的種子,不會接續。
### v1.2.0 錄製協定
與 v1.1.0 **只差回合數**,其他條件、輔助公式、區塊組成與洗牌方式、記錄格式都相同,可以和 v1.1.0 的資料直接合併:
- 熱身 3 回合(`planIndex` 0–2),接著 5 個區塊(`blockIndex` 0–4,`planIndex` 3–52),共 53 回合,約 6–12 分鐘。
- 新增的 config 欄位(`mouseModel`、`mouseDpi`、`lowQuality`、`qualityLevel`、`warmupFps`)見上方「v1.2.0 新增」。
- 暫停 / 繼續從下一幀才生效(見 `events_N.csv` 的 `pause` / `resume`);暫停期間不能開槍。
- 熱身平均 FPS 低於 55 時,第一個正式回合之前會跳提示(建議關掉其他程式或回主選單勾選低畫質,也可以直接繼續)。提示出現時沒有回合在進行,不會記成回合內的暫停。
## 模擬視覺模型
有輔助的回合中,輔助使用的敵人位置來自「模擬 AI 視覺模型」。它直接讀取敵人的骨架位置(完美感知器),只加上三個真實外掛本來就有的限制,**不做插值或預測**:
+11 -2
View File
@@ -33,8 +33,8 @@ public class RoundConfig : GameSettings
public string buildId; // 出包時的 git commit 短碼,分辨同版號的不同 build
public string sessionId; // 這次執行的代號 (= 資料夾 / zip 的時間戳)
public int planSeed; // 排程種子
public int planIndex; // 排程中的第幾項 (熱身 0~4,正式 5~84)
public int blockIndex; // 區塊 0~7,熱身 -1
public int planIndex; // 排程中的第幾項 (v1.2.0 : 熱身 0~2,正式 3~52)
public int blockIndex; // 區塊 (v1.2.0 : 0~4),熱身 -1
public int orderInBlock; // 區塊內 0~9,熱身 -1
public bool isWarmup; // 熱身回合 (分析時排除)
public float assistFovDeg; // 作用範圍 (度),無輔助為 0
@@ -42,6 +42,10 @@ public class RoundConfig : GameSettings
public int targetFps; // Application.targetFrameRate,-1 = 不限制
public int vSyncCount;
// v1.2.0
public float warmupFps; // 熱身量到的平均 FPS ; 熱身還沒結束、自由模式為 -1
public string qualityLevel; // 這一回合的畫質等級名稱
public static RoundConfig Create(int index, SessionPlan.RoundCondition condition)
{
RoundConfig c = new RoundConfig();
@@ -72,6 +76,11 @@ public class RoundConfig : GameSettings
c.recoilSeed = condition.roundSeed;
c.targetFps = Application.targetFrameRate;
c.vSyncCount = QualitySettings.vSyncCount;
c.warmupFps = SessionPlan.IsAuto(c) ? SessionPlan.WarmupFps : -1f;
int quality = QualitySettings.GetQualityLevel();
string[] names = QualitySettings.names;
c.qualityLevel = quality >= 0 && quality < names.Length ? names[quality] : quality.ToString();
return c;
}
}
+7 -2
View File
@@ -31,6 +31,7 @@ public class RoundRecorder : MonoBehaviour
public CsvWriter frames;
public CsvWriter events;
public double pauseStart;
public double lastFrameTime; // 最後寫進 frames 的那一幀的 t
public bool finishing; // 機器人倒下了,等這一幀結束再存 (同一幀最後一發的命中也要記到)
}
@@ -122,6 +123,7 @@ public class RoundRecorder : MonoBehaviour
File.WriteAllText(Path.Combine(SessionStorage.Folder, $"config_{c.roundIndex}.json"), JsonUtility.ToJson(c, true));
SessionStorage.MarkRoundSaved(c.assistMode);
if (c.isWarmup) SessionPlan.AddWarmupRound(c.frames, c.duration - c.pausedSeconds); // 熱身平均 FPS 用
SessionPlan.MarkSaved(c.planIndex); // 存檔成功才前進到下一項
Debug.Log($"第 {c.roundIndex} 回合已存檔 ({c.duration:F1} 秒,{c.mouseEvents} 筆滑鼠事件,{c.frames} 幀)");
round = null;
@@ -156,7 +158,9 @@ public class RoundRecorder : MonoBehaviour
if (paused)
{
// 用真正開始暫停的時間 : 切出視窗時遊戲會停住,等切回來才跑到這裡
round.pauseStart = PauseMenu.PauseStartTime;
// v1.2.0 : 按 Esc 的那一幀照常記錄 (暫停從下一幀才生效),所以暫停的開始不能早於最後一幀,
// 不然 pause 事件會排在已記錄的幀前面 ; 切出視窗發生在幀與幀之間,不受影響
round.pauseStart = Math.Max(PauseMenu.PauseStartTime, round.lastFrameTime);
WriteEvent("pause", null, -1f, round.pauseStart);
}
else
@@ -192,7 +196,8 @@ public class RoundRecorder : MonoBehaviour
void WriteFrame(HitscanWeapon weapon)
{
CsvWriter w = round.frames;
w.Add(Now).Add(Time.unscaledDeltaTime);
round.lastFrameTime = Now;
w.Add(round.lastFrameTime).Add(Time.unscaledDeltaTime);
// 視角
Vector2 recoil = playerLook != null ? playerLook.RecoilOffset : Vector2.zero;
+1 -1
View File
@@ -1,7 +1,7 @@
using UnityEngine;
using TMPro;
// 遊戲中顯示目前回合進度 (自動配置 : 第 n / 85 回合,不顯示條件 ; 自由模式 : 已記錄幾回合 ; 測試模式不顯示)
// 遊戲中顯示目前回合進度 (自動配置 : 第 n / 總回合數,不顯示條件 ; 自由模式 : 已記錄幾回合 ; 測試模式不顯示)
// 掛在 PlayerRig,Text 放在 HUD 上
public class RoundProgressHUD : MonoBehaviour
{
+2 -1
View File
@@ -72,7 +72,8 @@ public class HitscanWeapon : MonoBehaviour
UpdateModelKick();
// 選單開著 (滑鼠沒鎖定) 時不能開槍
if (Cursor.lockState != CursorLockMode.Locked) return;
// 這一幀標為暫停時也不行 : 按「繼續」的那一幀滑鼠已經鎖定,但這一幀不記錄,開槍會有 shot 卻沒有對應的幀
if (Cursor.lockState != CursorLockMode.Locked || PauseMenu.IsPaused) return;
if (Keyboard.current != null && Keyboard.current.rKey.wasPressedThisFrame)
{