製作地下室地圖、Raw Input 整合後續修正

This commit is contained in:
Sahik committed 2026-10-24 05:15:56 +08:00
1 parent 81d2a150c2
commit 23c311e905
191 files changed
+59056 -9911

No files matched your search

+14 -11
View File
@@ -17,13 +17,16 @@ MouseTrail_<ID>_<yyyyMMdd_HHmmss>.zip
├─ frames_0.csv 第 0 回合每一幀的狀態
├─ events_0.csv 第 0 回合的離散事件
├─ config_1.json 第 1 回合的設定與摘要
└─ mouse_1... 第 1 回合...
├─ mouse_1... 第 1 回合...
└─ recovered/ (只有上次沒正常關閉遊戲時才有)
└─ <yyyyMMdd_HHmmss>/ 上次沒打包的那次執行,裡面的結構跟外層一樣
```
- **一回合 = 一隻敵人**:從敵人出現開始,到敵人被擊倒為止。
- 只收錄完整打完的回合;打到一半就離開的回合不會出現。
- 同一個 zip 裡的回合,設定可能不同,因為玩家可以中途回主畫面調整,所以每一回合都有自己的 `config_N.json`。
- 測試模式不會產生資料。
- 如果上次遊戲當機或被強制關閉,那次已完成的回合會在這次關遊戲時一起打包,放在 `recovered/<那次的開始時間>/`。**每個資料夾的時間軸各自獨立**(各自從那次遊戲啟動開始算),回合編號也各自從 0 開始,所以不要跨資料夾比較時間。
## 慣例
@@ -74,10 +77,9 @@ MouseTrail_<ID>_<yyyyMMdd_HHmmss>.zip
| | `view_yaw`、`view_pitch` | 畫面實際的視角 = 前兩組相加 |
| 輸入 | `mouse_dx`、`mouse_dy` | 這一幀套用的所有滑鼠回報總和(= `mouse_N.csv` 中這一幀內的 `dx`、`dy` 加總) |
| | `assist_dx`、`assist_dy` | 平滑跟槍這一幀加上的量(滑鼠單位),每一幀套用一次 |
| | `sens_scale` | 動態靈敏度的倍率,1 = 沒有作用 |
| 玩家 | `px`、`py`、`pz` | 位置 |
| | `vx`、`vy`、`vz` | 速度 |
| | `state` | 移動狀態(MotionCore 的狀態名稱):Idle / Moving / Jumping / Falling / Crouching / PlayerSlide(滑鏟)/ Sliding(斜坡下滑)/ Vaulting(翻越) |
| | `state` | 移動狀態(MotionCore 的狀態名稱):Idle / Moving / Jumping / Falling / Crouching / Prone(趴下)/ PlayerSlide(滑鏟)/ Sliding(斜坡下滑)/ Vaulting(翻越) |
| 敵人 | `bx`、`by`、`bz` | 位置 |
| | `bvx`、`bvy`、`bvz` | 速度 |
| | `bot_hp` | 剩餘血量(滿血 500) |
@@ -88,7 +90,7 @@ MouseTrail_<ID>_<yyyyMMdd_HHmmss>.zip
| 外掛拿到的結果 | `out_detected` | 經過取樣與延遲後,外掛手上的結果有沒有偵測到 |
| | `out_err_x`、`out_err_y` | 外掛手上的角度誤差(是擷取當時的舊畫面) |
| | `out_age_ms` | 這份結果是多久以前擷取的(毫秒),也就是外掛手上的資訊有多舊 |
| | `out_delay_ms` | 這份結果的延遲 |
| | `out_delay_ms` | 這份結果實際的延遲(已包含抖動) |
| 輔助 | `assist_engaged` | 這一幀輔助有沒有作用 |
| | `assist_fov` | 輔助作用範圍半徑(度) |
| 武器 | `ammo` | 彈匣剩餘 |
@@ -113,9 +115,10 @@ MouseTrail_<ID>_<yyyyMMdd_HHmmss>.zip
| `hit` | 命中一次(霰彈的每顆彈丸各記一次) |
| `kill` | 敵人倒下,回合結束 |
| `reload_start` | 開始換彈 |
| `pause` / `resume` | 暫停 / 繼續。暫停期間 mouse 和 frames 不會有資料 |
| `pause` / `resume` | 暫停 / 繼續。按 Esc 或切出遊戲視窗(Alt+Tab 等)都會暫停。暫停期間 mouse 和 frames 不會有資料,`pause` 的時間是真正開始暫停的時間 |
| `prone_start` / `prone_end` | 開始趴下 / 結束趴下(站起或蹲起)。按 Z 切換。回合開始時已經趴著的話,會在 `round_start` 之後立刻補一筆 `prone_start`;回合結束時還趴著的話不會有 `prone_end` |
不記錄鍵盤按鍵。玩家的移動用 `frames_N.csv` 的位置、速度和 `state` 表示,這是物理引擎實際算出的結果(包含加速度、滑鏟、空中轉向),比按鍵本身更能描述「畫面相對於玩家怎麼動」。
不記錄鍵盤按鍵(`prone_start` / `prone_end` 是姿勢改變的事件,不是按鍵事件)。玩家的移動用 `frames_N.csv` 的位置、速度和 `state` 表示,這是物理引擎實際算出的結果(包含加速度、滑鏟、空中轉向),比按鍵本身更能描述「畫面相對於玩家怎麼動」。
## `config_N.json`:回合設定與摘要
@@ -123,10 +126,10 @@ MouseTrail_<ID>_<yyyyMMdd_HHmmss>.zip
|---|---|
| `contributorID` | 貢獻者 ID,匿名時為 `Anonymous` |
| `sensitivity`、`fov` | 靈敏度、FOV(以 4:3 畫面為基準的水平 FOV,跟 Apex 相同) |
| `assistMode` | 0 = 無輔助、1 = 平滑跟槍、2 = 動態靈敏度 |
| `assistMode` | 0 = 無輔助、1 = 平滑跟槍 |
| `assistStrength` | 輔助強度 1–100(無輔助時為 0) |
| `assistDelayMs`、`assistDelayJitter` | 模擬辨識延遲(ms)、是否加上 ±5ms 抖動 |
| `disableHorizontalAssist`、`disableVerticalAssist` | 是否停用水平 / 垂直方向的輔助 |
| `assistDelayMs`、`assistDelayJitterMs` | 模擬辨識延遲(ms)、延遲抖動範圍:每次取樣的延遲在 ±N ms 內均勻隨機(0 = 不抖動;延遲不會小於 0) |
| `disableHorizontalAssist`、`disableVerticalAssist` | 是否停用水平 / 垂直方向的輔助。兩個都勾等於沒有輔助,會存成 `assistMode = 0`,所以不會同時為 true;無輔助時兩者一律為 false |
| `map`、`weapon` | 地圖、武器 |
| `screenWidth`、`screenHeight`、`refreshRate` | 解析度與螢幕刷新率 |
| `roundIndex` | 回合編號(同一次執行中由 0 往上加) |
@@ -143,7 +146,7 @@ MouseTrail_<ID>_<yyyyMMdd_HHmmss>.zip
有輔助的回合中,輔助使用的敵人位置來自「模擬 AI 視覺模型」。它直接讀取敵人的骨架位置(完美感知器),只加上三個真實外掛本來就有的限制,**不做插值或預測**:
1. **依螢幕刷新率取樣**:外掛是擷取畫面,畫面一秒只更新刷新率那麼多次。
2. **辨識延遲**:擷取 → 辨識 → 輸出需要時間,延遲值記錄在 `assistDelayMs`。
2. **辨識延遲**:擷取 → 辨識 → 輸出需要時間,延遲值記錄在 `assistDelayMs`;推論時間不穩定的程度記錄在 `assistDelayJitterMs`,每次實際的延遲記錄在 frames 的 `out_delay_ms`。
3. **被擋住 25% 以上就偵測不到**:視覺辨識看不到被遮住的目標。
`truth_*` 是每一幀的真實狀態,`out_*` 是外掛實際拿到、拿來輔助的結果。兩者的差距就是上面三個限制造成的。
@@ -160,7 +163,7 @@ MouseTrail_<ID>_<yyyyMMdd_HHmmss>.zip
## 分析時要注意
- **後座力與玩家輸入是分開的**:`mouse_*` 只有手的動作。玩家往下拉,可能是在壓槍,也可能是在追蹤目標,要對照 `recoil_*` 來判斷。
- **輔助後的軌跡** = 玩家輸入 + `assist_*`(平滑跟槍),或是玩家輸入 × `sens_scale`(動態靈敏度)。
- **輔助後的軌跡** = 玩家輸入 + `assist_*`(平滑跟槍)。
- **玩家輸入與輔助的頻率不同**:`mouse_N.csv` 是原始回報(不等間隔),`assist_*` 是每幀一次。要比較兩者時,可以把滑鼠回報依 `t` 歸到所屬的幀(加總後就是 `mouse_dx`、`mouse_dy`)。
- **相對於視角的移動**:用 `yaw` 把 `vx`、`vz` 轉到視角座標,就能得到玩家往準心左右、前後移動的速度。
- 每一回合的開頭通常包含「找敵人」的轉身,可以用 `truth_detected` 或螢幕座標,把「找人」和「追蹤瞄準」兩段切開。
+24 -8
View File
@@ -10,7 +10,7 @@ using CharacterMovement;
public class RoundRecorder : MonoBehaviour
{
[Header("參照")]
[Tooltip("場景裡的 BotSpawner")]
[Tooltip("場景裡的 BotSpawner (沒拖會自動找)")]
public BotSpawner spawner;
public PlayerLook playerLook;
public PlayerController playerController;
@@ -46,7 +46,10 @@ public class RoundRecorder : MonoBehaviour
active = !settings.isTest || recordInTestMode;
if (!active) return;
// prefab 存不住場景物件的參照 : 沒拖的話自動找場景裡的 BotSpawner (新地圖不用再手動接)
if (spawner == null) spawner = FindAnyObjectByType<BotSpawner>();
if (spawner != null) spawner.BotSpawned += StartRound;
if (playerController != null) playerController.StanceChanged += OnStanceChanged;
// 機器人已經先生成了的話,直接從它開始
if (spawner != null && spawner.CurrentBot != null) StartRound(spawner.CurrentBot);
@@ -55,6 +58,7 @@ public class RoundRecorder : MonoBehaviour
void OnDisable()
{
if (spawner != null) spawner.BotSpawned -= StartRound;
if (playerController != null) playerController.StanceChanged -= OnStanceChanged;
SubscribeWeapon(null);
// 離開場景或關遊戲 : 沒打完的回合不存
@@ -84,6 +88,17 @@ public class RoundRecorder : MonoBehaviour
bot.Died += OnBotDied;
WriteEvent("round_start");
// 回合開始時已經趴著,先補一筆,讓 events 裡的趴下都有開始和結束
if (playerController != null && playerController.CurrentStance == PlayerStance.Prone) WriteEvent("prone_start");
}
// 趴下 (Z 切換) : 進入趴姿記 prone_start,離開趴姿 (站起或蹲起) 記 prone_end
void OnStanceChanged(PlayerStance previous, PlayerStance current)
{
if (round == null) return;
if (current == PlayerStance.Prone) WriteEvent("prone_start");
else if (previous == PlayerStance.Prone) WriteEvent("prone_end");
}
void OnBotDied(BotHealth bot)
@@ -107,7 +122,7 @@ public class RoundRecorder : MonoBehaviour
round.events.Commit();
File.WriteAllText(Path.Combine(SessionStorage.Folder, $"config_{c.roundIndex}.json"), JsonUtility.ToJson(c, true));
SessionStorage.MarkRoundSaved();
SessionStorage.MarkRoundSaved(c.assistMode);
Debug.Log($"第 {c.roundIndex} 回合已存檔 ({c.duration:F1} 秒,{c.mouseEvents} 筆滑鼠事件,{c.frames} 幀)");
round = null;
}
@@ -140,8 +155,9 @@ public class RoundRecorder : MonoBehaviour
wasPaused = paused;
if (paused)
{
round.pauseStart = Now;
WriteEvent("pause");
// 用真正開始暫停的時間 : 切出視窗時遊戲會停住,等切回來才跑到這裡
round.pauseStart = PauseMenu.PauseStartTime;
WriteEvent("pause", null, -1f, round.pauseStart);
}
else
{
@@ -166,7 +182,7 @@ public class RoundRecorder : MonoBehaviour
const string FrameHeader =
"t,dt,yaw,pitch,recoil_x,recoil_y,view_yaw,view_pitch," +
"mouse_dx,mouse_dy,assist_dx,assist_dy,sens_scale," +
"mouse_dx,mouse_dy,assist_dx,assist_dy," +
"px,py,pz,vx,vy,vz,state," +
"bx,by,bz,bvx,bvy,bvz,bot_hp," +
"truth_detected,truth_visible,truth_err_x,truth_err_y,truth_screen_x,truth_screen_y," +
@@ -187,7 +203,7 @@ public class RoundRecorder : MonoBehaviour
// 這一幀的輸入
Vector2 mouse = playerLook != null ? playerLook.LastMouseDelta : Vector2.zero;
Vector2 assist = playerLook != null ? playerLook.LastAssistDelta : Vector2.zero;
w.Add(mouse.x).Add(mouse.y).Add(assist.x).Add(assist.y).Add(playerLook != null ? playerLook.sensitivityScale : 1f);
w.Add(mouse.x).Add(mouse.y).Add(assist.x).Add(assist.y);
// 玩家
Vector3 p = playerController != null ? playerController.transform.position : Vector3.zero;
@@ -263,13 +279,13 @@ public class RoundRecorder : MonoBehaviour
WriteEvent("hit", part.ToString(), damage);
}
void WriteEvent(string type, string part = null, float damage = -1f)
void WriteEvent(string type, string part = null, float damage = -1f, double time = -1)
{
if (round == null) return;
HitscanWeapon weapon = loadout != null ? loadout.Current : null;
CsvWriter w = round.events;
w.Add(Now).Add(type).Add(weapon != null && weapon.data != null ? weapon.data.weaponName : "").Add(part);
w.Add(time >= 0 ? time : Now).Add(type).Add(weapon != null && weapon.data != null ? weapon.data.weaponName : "").Add(part);
if (damage >= 0f) w.Add(damage); else w.Empty();
w.Add(round.bot != null ? round.bot.Health : 0f).Add(weapon != null ? weapon.Ammo : 0);
w.EndRow();
+92 -17
View File
@@ -1,16 +1,31 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using UnityEngine;
// 這次執行遊戲的資料夾與回合編號 ; 關遊戲時把整個資料夾打包成 zip 放到桌面
// 這次執行遊戲的資料夾與回合編號 ; 關遊戲時把資料打包成 zip 放到桌面
// 跨場景共用 (回主畫面調參數再回來,回合編號會接著往下)
// 上次如果當機 (沒有正常關遊戲),那次的回合會在這次關遊戲時一起打包進 recovered/ 資料夾
public static class SessionStorage
{
// 打包過的資料夾會放這個檔案,下次就不會再包一次
private const string PackedMarker = "packed.txt";
private static string folder;
private static string startStamp;
private static int nextRoundIndex;
private static int savedRounds;
// 這次執行已存的回合數 (給 StartUI 顯示,方便貢獻者平衡無輔助 / 有輔助)
public static int NoAssistRounds { get; private set; }
public static int AssistRounds { get; private set; }
// 上次沒打包、這次關遊戲時會一起打包的回合數
public static int RecoveredRounds { get; private set; }
private static List<string> recoveredFolders = new List<string>();
private static string Root => Path.Combine(Application.persistentDataPath, "Sessions");
// 第一次用到時才建立 : persistentDataPath/Sessions/<開始時間>/
public static string Folder
@@ -19,8 +34,7 @@ public static class SessionStorage
{
if (folder == null)
{
startStamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
folder = Path.Combine(Application.persistentDataPath, "Sessions", startStamp);
folder = Path.Combine(Root, startStamp);
Directory.CreateDirectory(folder);
}
return folder;
@@ -29,39 +43,100 @@ public static class SessionStorage
public static int TakeRoundIndex() => nextRoundIndex++;
public static void MarkRoundSaved() => savedRounds++;
public static void MarkRoundSaved(int assistMode)
{
if (assistMode == 0) NoAssistRounds++;
else AssistRounds++;
}
// 每次進入 Play 都重設 (編輯器關掉 Domain Reload 時,static 不會自動清空)
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void Init()
{
folder = null;
startStamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
nextRoundIndex = 0;
savedRounds = 0;
NoAssistRounds = 0;
AssistRounds = 0;
FindUnpackedSessions();
Application.quitting -= OnQuitting;
Application.quitting += OnQuitting;
}
// 關遊戲 (或編輯器停止 Play) 時 : 有完成的回合才打包
// 找出之前沒打包的資料夾 (當機或被強制關閉) : 有完成的回合、而且沒有打包記號
static void FindUnpackedSessions()
{
recoveredFolders = new List<string>();
RecoveredRounds = 0;
if (!Directory.Exists(Root)) return;
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
foreach (string dir in Directory.GetDirectories(Root))
{
if (File.Exists(Path.Combine(dir, PackedMarker))) continue;
// 舊版本打包過的資料夾沒有記號 : 桌面上已經有同一個時間的 zip 就當作打包過了
string stamp = Path.GetFileName(dir);
if (Directory.GetFiles(desktop, $"MouseTrail_*_{stamp}.zip").Length > 0) continue;
int rounds = Directory.GetFiles(dir, "config_*.json").Length;
if (rounds == 0) continue;
recoveredFolders.Add(dir);
RecoveredRounds += rounds;
}
}
// 關遊戲 (或編輯器停止 Play) 時 : 這次或上次有完成的回合才打包
static void OnQuitting()
{
if (folder == null || savedRounds == 0) return;
int thisRounds = NoAssistRounds + AssistRounds;
if (thisRounds == 0 && recoveredFolders.Count == 0) return;
string id = SafeFileName(GameSettings.Load().contributorID);
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string zipPath = Path.Combine(desktop, $"MouseTrail_{id}_{startStamp}.zip");
try
{
File.WriteAllText(Path.Combine(folder, "README.md"), DatasetReadme.Text);
string id = SafeFileName(GameSettings.Load().contributorID);
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string zipPath = Path.Combine(desktop, $"MouseTrail_{id}_{startStamp}.zip");
if (File.Exists(zipPath)) File.Delete(zipPath);
ZipFile.CreateFromDirectory(folder, zipPath);
Debug.Log($"資料已打包到 : {zipPath} (原始資料保留在 {folder})");
using (ZipArchive zip = ZipFile.Open(zipPath, ZipArchiveMode.Create))
{
// README 放在最外層
ZipArchiveEntry readme = zip.CreateEntry("README.md");
using (StreamWriter w = new StreamWriter(readme.Open())) w.Write(DatasetReadme.Text);
// 這次的回合放在最外層
if (thisRounds > 0) AddFolder(zip, folder, "");
// 上次沒打包的回合放在 recovered/<那次的開始時間>/ (時間軸各自獨立,所以分開放)
foreach (string dir in recoveredFolders)
{
AddFolder(zip, dir, $"recovered/{Path.GetFileName(dir)}/");
}
}
// 打包成功才放記號
if (thisRounds > 0) File.WriteAllText(Path.Combine(folder, PackedMarker), zipPath);
foreach (string dir in recoveredFolders) File.WriteAllText(Path.Combine(dir, PackedMarker), zipPath);
Debug.Log($"資料已打包到 : {zipPath} (這次 {thisRounds} 回合,上次未打包 {RecoveredRounds} 回合)");
}
catch (Exception e)
{
Debug.LogError($"打包資料失敗,原始資料仍在 {folder} : {e.Message}");
Debug.LogError($"打包資料失敗,原始資料仍在 {Root} : {e.Message}");
}
}
// 只放完成的檔案 (.tmp 是沒打完的回合,略過)
static void AddFolder(ZipArchive zip, string dir, string prefix)
{
foreach (string file in Directory.GetFiles(dir))
{
string name = Path.GetFileName(file);
if (name.EndsWith(".tmp") || name == PackedMarker || name == "README.md") continue;
zip.CreateEntryFromFile(file, prefix + name);
}
}