1.1.0 未驗證
This commit is contained in:
1 parent
2638c5929d
commit
4a72bd132a
31 files changed
+790
-123
No files matched your search
@@ -1,7 +1,9 @@
|
||||
using UnityEngine;
|
||||
|
||||
// 模擬 AI 視覺外掛的輔助瞄準 : 只用 EnemyPerceptor.Output (外掛真正拿到的結果)
|
||||
// 模式依 StartUI 設定 : 0 = 無輔助,1 = 平滑跟槍
|
||||
// 模式與強度由 BotSpawner 每回合用 Apply() 套上 (自動配置的排程,或 StartUI 的設定) ; 0 = 無輔助,1 = 平滑跟槍
|
||||
// 執行順序排在 PlayerLook 之前,修正量在同一幀套用
|
||||
[DefaultExecutionOrder(-10)]
|
||||
public class AimAssist : MonoBehaviour
|
||||
{
|
||||
[Header("參照")]
|
||||
@@ -10,19 +12,12 @@ public class AimAssist : MonoBehaviour
|
||||
[Tooltip("CameraRoot 上的 PlayerLook")]
|
||||
public PlayerLook playerLook;
|
||||
|
||||
[Header("輔助範圍 (準心周圍一圈,半徑隨強度變大)")]
|
||||
[Tooltip("強度 1% 時的半徑 (度)")]
|
||||
public float minFov = 3f;
|
||||
|
||||
[Tooltip("強度 100% 時的半徑 (度)")]
|
||||
public float maxFov = 15f;
|
||||
|
||||
[Header("平滑跟槍")]
|
||||
[Tooltip("強度 1% / 100% 時的修正速度 (每秒修正剩餘誤差的比例係數,越大越快)")]
|
||||
public Vector2 trackSpeed = new Vector2(2f, 30f);
|
||||
|
||||
// 給記錄器用 : 這一幀輔助做了什麼
|
||||
public float FovRadius { get; private set; }
|
||||
public float FovRadius { get; private set; } // 作用範圍半徑 (度) : 有輔助固定 15,無輔助 0 (SessionPlan.AssistFovDeg)
|
||||
public bool Engaged { get; private set; }
|
||||
|
||||
private int mode;
|
||||
@@ -35,19 +30,28 @@ public class AimAssist : MonoBehaviour
|
||||
|
||||
void Start()
|
||||
{
|
||||
// 輔助模式與強度不在這裡讀 : 由 Apply() 每回合套上,才不會被第一回合的生成順序蓋掉
|
||||
GameSettings s = GameSettings.Load();
|
||||
mode = s.assistMode;
|
||||
strength = s.assistStrength / 100f;
|
||||
noHorizontal = s.disableHorizontalAssist;
|
||||
noVertical = s.disableVerticalAssist;
|
||||
degreesPerCount = 0.022f * Mathf.Max(0.01f, s.sensitivity); // 跟 PlayerLook 相同的換算
|
||||
degreesPerCount = 0.022f * Mathf.Max(0.01f, (float)s.sensitivity); // 跟 PlayerLook 相同的換算
|
||||
}
|
||||
|
||||
FovRadius = mode == 1 ? Mathf.Lerp(minFov, maxFov, strength) : 0f; // 無輔助時記 0
|
||||
// 套用這一回合的條件,並清掉上一回合的殘留 (BotSpawner 在生成機器人、觸發 BotSpawned 之前呼叫)
|
||||
public void Apply(SessionPlan.RoundCondition c)
|
||||
{
|
||||
mode = c.assistMode;
|
||||
strength = c.assistStrength / 100f;
|
||||
FovRadius = mode == 1 ? c.assistFovDeg : 0f; // 無輔助時記 0
|
||||
remainingError = Vector2.zero;
|
||||
lastSampleTime = -1f;
|
||||
Engaged = false;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
Engaged = false;
|
||||
if (PauseMenu.IsPaused) return; // 暫停時不算、不累積
|
||||
if (mode != 1 || perceptor == null || playerLook == null) return;
|
||||
|
||||
EnemyPerceptor.Detection d = perceptor.Output;
|
||||
|
||||
@@ -43,6 +43,7 @@ public class EnemyPerceptor : MonoBehaviour
|
||||
private float nextSampleTime;
|
||||
private int baseDelayMs;
|
||||
private int jitterMs;
|
||||
private System.Random jitterRandom = new System.Random(); // 延遲抖動專用,跟機器人的亂數分開
|
||||
private readonly Queue<Detection> pending = new Queue<Detection>();
|
||||
// 各部位佔整個人的比例 (大約是人的外形面積),取樣點的權重照這個分配
|
||||
// 不加權的話,腿有 4 個命中框、佔了大部分取樣點,地上一點小起伏就會讓整個人判定成被擋住
|
||||
@@ -61,14 +62,24 @@ public class EnemyPerceptor : MonoBehaviour
|
||||
// 沒拖、或拖到 prefab 檔案本身 : 自動找場景裡的 BotSpawner (新地圖不用再手動接)
|
||||
spawner = BotSpawner.FindInScene(spawner);
|
||||
|
||||
// 延遲與抖動由 Apply() 每回合套上,不在這裡讀
|
||||
GameSettings settings = GameSettings.Load();
|
||||
baseDelayMs = settings.assistDelayMs;
|
||||
jitterMs = settings.assistDelayJitterMs;
|
||||
|
||||
int refreshRate = settings.refreshRate > 0 ? settings.refreshRate : 60;
|
||||
sampleInterval = 1f / refreshRate;
|
||||
}
|
||||
|
||||
// 套用這一回合的延遲條件,並清掉上一回合的辨識結果 (BotSpawner 在通知記錄器之前呼叫)
|
||||
public void Apply(SessionPlan.RoundCondition c)
|
||||
{
|
||||
baseDelayMs = c.assistDelayMs;
|
||||
jitterMs = c.assistDelayJitterMs;
|
||||
jitterRandom = new System.Random(c.roundSeed ^ 0x5bd1e995); // 跟後座力 (直接用 roundSeed) 錯開,不要變成同一串亂數
|
||||
pending.Clear();
|
||||
Output = default;
|
||||
DelayMs = 0f;
|
||||
nextSampleTime = 0f;
|
||||
}
|
||||
|
||||
void LateUpdate()
|
||||
{
|
||||
// LateUpdate : 等視角和敵人都更新完,才是這一幀畫面上的樣子
|
||||
@@ -80,7 +91,7 @@ public class EnemyPerceptor : MonoBehaviour
|
||||
|
||||
// 抖動 : 每次取樣的延遲在 ±jitterMs 內隨機 (模擬視覺模型推論時間不穩) ; 不會小於 0
|
||||
Detection sample = Truth;
|
||||
sample.delay = Mathf.Max(0f, baseDelayMs + Random.Range(-jitterMs, (float)jitterMs)) / 1000f;
|
||||
sample.delay = Mathf.Max(0f, baseDelayMs + ((float)jitterRandom.NextDouble() * 2f - 1f) * jitterMs) / 1000f;
|
||||
pending.Enqueue(sample);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@ using UnityEngine;
|
||||
|
||||
// 一次只有一隻機器人,倒下後在隨機位置重生下一隻
|
||||
// 掛在場景裡的空物件上,物件的位置就是生成範圍的中心
|
||||
// 每生成一隻就是新的一回合 : 先取出這回合的條件 (SessionPlan) 套到輔助、感知器、武器,再通知記錄器
|
||||
// 執行順序 50 : 第一隻在 Start() 生成,要排在其他腳本的 Start() 之後
|
||||
[DefaultExecutionOrder(50)]
|
||||
public class BotSpawner : MonoBehaviour
|
||||
{
|
||||
[Header("參照")]
|
||||
@@ -26,11 +29,22 @@ public class BotSpawner : MonoBehaviour
|
||||
// 目前活著的機器人,倒下到重生之間是 null (給方位指示等 UI 用)
|
||||
public BotHealth CurrentBot { get; private set; }
|
||||
|
||||
// 這一回合的條件 (記錄器寫進 config 用)
|
||||
public SessionPlan.RoundCondition CurrentCondition { get; private set; }
|
||||
|
||||
// 新的一隻生成時通知 (記錄器用來開始一回合)
|
||||
public event System.Action<BotHealth> BotSpawned;
|
||||
|
||||
private GameSettings settings;
|
||||
private AimAssist aimAssist;
|
||||
private EnemyPerceptor perceptor;
|
||||
private PlayerLook playerLook;
|
||||
private WeaponLoadout loadout;
|
||||
|
||||
void Start()
|
||||
{
|
||||
settings = GameSettings.Load();
|
||||
|
||||
// 拖進來的是 prefab 檔案本身 (不在場景裡) 或沒拖 : 改用場景裡的玩家 (只有玩家身上有 PlayerLook)
|
||||
if (player == null || !player.gameObject.scene.IsValid())
|
||||
{
|
||||
@@ -38,6 +52,19 @@ public class BotSpawner : MonoBehaviour
|
||||
player = look != null ? look.transform.root : null;
|
||||
}
|
||||
|
||||
// 每回合要套條件的腳本 (player 可能只是 PlayerRig 底下的子物件,所以從整個場景找)
|
||||
aimAssist = FindAnyObjectByType<AimAssist>();
|
||||
perceptor = FindAnyObjectByType<EnemyPerceptor>();
|
||||
playerLook = FindAnyObjectByType<PlayerLook>();
|
||||
loadout = FindAnyObjectByType<WeaponLoadout>();
|
||||
|
||||
// 條件套不上去,config 的標籤就會跟實際不符,所以寧可不生成
|
||||
if (aimAssist == null || perceptor == null || playerLook == null || loadout == null)
|
||||
{
|
||||
Debug.LogError("BotSpawner : 場景裡缺少 AimAssist / EnemyPerceptor / PlayerLook / WeaponLoadout,無法套用回合條件");
|
||||
return;
|
||||
}
|
||||
|
||||
Spawn();
|
||||
}
|
||||
|
||||
@@ -53,11 +80,24 @@ public class BotSpawner : MonoBehaviour
|
||||
{
|
||||
if (botPrefab == null) return;
|
||||
|
||||
// 自動配置做完全部回合就不再生成 (RoundProgressHUD 會提示關閉遊戲)
|
||||
if (!SessionPlan.TryGetCurrent(settings, out SessionPlan.RoundCondition c)) return;
|
||||
CurrentCondition = c;
|
||||
|
||||
// 這一回合的種子 : 生成點與機器人動作都用全域亂數
|
||||
Random.InitState(c.roundSeed);
|
||||
|
||||
BotBrain bot = Instantiate(botPrefab, PickSpawnPoint(), Quaternion.identity);
|
||||
bot.target = player;
|
||||
bot.areaCenter = transform.position;
|
||||
bot.areaRadius = spawnRadius;
|
||||
|
||||
// 套用條件並清掉上一回合的殘留,要在通知記錄器之前
|
||||
aimAssist.Apply(c);
|
||||
perceptor.Apply(c);
|
||||
playerLook.ClearAssistDelta();
|
||||
loadout.SetRecoilSeed(c.roundSeed);
|
||||
|
||||
if (bot.TryGetComponent(out BotHealth health))
|
||||
{
|
||||
health.Died += OnBotDied;
|
||||
|
||||
@@ -44,6 +44,12 @@ public class PlayerLook : MonoBehaviour
|
||||
pendingAssistDelta += delta;
|
||||
}
|
||||
|
||||
// 新回合開始時清掉上一回合還沒套用的輔助量
|
||||
public void ClearAssistDelta()
|
||||
{
|
||||
pendingAssistDelta = Vector2.zero;
|
||||
}
|
||||
|
||||
// ===== 後座力 =====
|
||||
// 後座力是疊在滑鼠視角上的一層獨立偏移 (度),不會改到 yaw / pitch,停火後自己回正
|
||||
// x = 往右,y = 往上 ; 記錄器之後可以把它和滑鼠輸入分開存
|
||||
@@ -73,7 +79,7 @@ public class PlayerLook : MonoBehaviour
|
||||
void Start()
|
||||
{
|
||||
GameSettings settings = GameSettings.Load();
|
||||
sensitivity = settings.sensitivity;
|
||||
sensitivity = (float)settings.sensitivity;
|
||||
fovSetting = settings.fov;
|
||||
|
||||
yaw = transform.eulerAngles.y;
|
||||
|
||||
@@ -18,6 +18,7 @@ MouseTrail_<ID>_<yyyyMMdd_HHmmss>.zip
|
||||
├─ events_0.csv 第 0 回合的離散事件
|
||||
├─ config_1.json 第 1 回合的設定與摘要
|
||||
├─ mouse_1... 第 1 回合...
|
||||
├─ plan.csv 這次執行的完整排程 (只有自動配置才有)
|
||||
└─ recovered/ (只有上次沒正常關閉遊戲時才有)
|
||||
└─ <yyyyMMdd_HHmmss>/ 上次沒打包的那次執行,裡面的結構跟外層一樣
|
||||
```
|
||||
@@ -92,10 +93,10 @@ MouseTrail_<ID>_<yyyyMMdd_HHmmss>.zip
|
||||
| | `truth_screen_x`、`truth_screen_y` | 敵人胸口的螢幕座標 |
|
||||
| 外掛拿到的結果 | `out_detected` | 經過取樣與延遲後,外掛手上的結果有沒有偵測到 |
|
||||
| | `out_err_x`、`out_err_y` | 外掛手上的角度誤差(是擷取當時的舊畫面) |
|
||||
| | `out_age_ms` | 這份結果是多久以前擷取的(毫秒),也就是外掛手上的資訊有多舊 |
|
||||
| | `out_age_ms` | 這份結果是多久以前擷取的(毫秒),也就是外掛手上的資訊有多舊。v1.1.0 起每回合開始時會清空外掛的結果,第一份結果到達之前(約 1–3 幀)`out_detected` 為 0,這時的 `out_age_ms` 沒有意義 |
|
||||
| | `out_delay_ms` | 這份結果實際的延遲(已包含抖動) |
|
||||
| 輔助 | `assist_engaged` | 這一幀輔助有沒有作用 |
|
||||
| | `assist_fov` | 輔助作用範圍半徑(度),無輔助時為 0。v1.0.1 起固定為 15°(第一階段資料就是 15°);v1.0.0 隨強度在 5°–30° 之間變化。每幀都有記錄,分析時請以這個欄位為準 |
|
||||
| | `assist_fov` | 輔助作用範圍半徑(度),無輔助時為 0。v1.1.0 起固定為 15°。更早的版本**不能用 `appVersion` 判斷**(見「版本與資料階段」),每幀都有記錄,分析時請以這個欄位為準 |
|
||||
| 武器 | `ammo` | 彈匣剩餘 |
|
||||
| | `reloading` | 是否換彈中 |
|
||||
|
||||
@@ -128,10 +129,10 @@ MouseTrail_<ID>_<yyyyMMdd_HHmmss>.zip
|
||||
| 欄位 | 說明 |
|
||||
|---|---|
|
||||
| `contributorID` | 貢獻者 ID,匿名時為 `Anonymous` |
|
||||
| `sensitivity`、`fov` | 靈敏度、FOV(以 4:3 畫面為基準的水平 FOV,跟 Apex 相同) |
|
||||
| `sensitivity`、`fov` | 靈敏度、FOV(以 4:3 畫面為基準的水平 FOV,跟 Apex 相同)。v1.1.0 之前靈敏度是單精度,1.4 會存成 1.399999976158142 |
|
||||
| `assistMode` | 0 = 無輔助、1 = 平滑跟槍(線性比例控制,公式見下方「平滑跟槍的修正量」) |
|
||||
| `assistStrength` | 輔助強度 1–100(無輔助時為 0) |
|
||||
| `assistDelayMs`、`assistDelayJitterMs` | 模擬辨識延遲(ms)、延遲抖動範圍:每次取樣的延遲在 ±N ms 內均勻隨機(0 = 不抖動;延遲不會小於 0) |
|
||||
| `assistStrength` | 輔助強度 1–100(無輔助時為 0)。`assistMode`、`assistStrength` 和下面的延遲都是這一回合實際套用的值 |
|
||||
| `assistDelayMs`、`assistDelayJitterMs` | 模擬辨識延遲(ms)、延遲抖動範圍:每次取樣的延遲在 ±N ms 內均勻隨機(0 = 不抖動;延遲不會小於 0)。自動配置的無輔助回合也是 15 ± 5,讓 `out_*` 的定義一致;其他無輔助回合為 0 |
|
||||
| `disableHorizontalAssist`、`disableVerticalAssist` | 是否停用水平 / 垂直方向的輔助。兩個都勾等於沒有輔助,會存成 `assistMode = 0`,所以不會同時為 true;無輔助時兩者一律為 false |
|
||||
| `map`、`weapon` | 地圖、武器 |
|
||||
| `screenWidth`、`screenHeight`、`refreshRate` | 解析度與螢幕刷新率 |
|
||||
@@ -139,21 +140,52 @@ MouseTrail_<ID>_<yyyyMMdd_HHmmss>.zip
|
||||
| `startTimeLocal` | 回合開始的實際時間(ISO 8601) |
|
||||
| `startTime`、`endTime`、`duration`、`pausedSeconds` | 開始與結束時間(同 CSV 的時間軸)、時長(包含暫停)、暫停總秒數。實際遊玩時間 = `duration` − `pausedSeconds` |
|
||||
| `shots`、`hits`、`mouseEvents`、`frames` | 開槍數、命中數、滑鼠事件數、幀數 |
|
||||
| `recoilSeed` | 後座力隨機部分的種子 |
|
||||
| `recoilSeed` | 後座力隨機部分的種子。v1.1.0 起每回合一個(等於 `roundSeed`);之前是每次載入場景一個,同一次載入的回合共用 |
|
||||
| `cameraVerticalFov`、`fixedDeltaTime` | 相機實際的垂直 FOV、物理更新間隔 |
|
||||
| `appVersion`、`unityVersion` | 程式與 Unity 版本。各階段資料使用的版本見下方「版本與資料階段」 |
|
||||
| `savedTime`、`isTest` | StartUI 存檔的時間、是否為測試模式(資料集中一律為 false) |
|
||||
|
||||
## 版本與資料階段
|
||||
v1.1.0 新增:
|
||||
|
||||
資料分三個階段收集,各階段使用的程式版本不同,差異如下。`config_N.json` 的 `appVersion` 可以用來判斷。
|
||||
| 欄位 | 說明 |
|
||||
|---|---|
|
||||
| `autoPlan` | 是否為自動配置(正式錄製)。false = 自由模式,條件由玩家自己選 |
|
||||
| `protocolVersion` | 錄製協定版本 |
|
||||
| `buildId` | 出包時的 git commit 短碼,用來分辨同版號的不同 build。`-dirty` 表示出包時有未提交的改動,`editor` 表示在編輯器裡錄的 |
|
||||
| `sessionId` | 這次執行的代號(跟 zip 檔名的時間相同) |
|
||||
| `planSeed` | 這次執行的排程種子 |
|
||||
| `planIndex` | 排程中的第幾項:熱身 0–4,正式 5–84。自由模式為 -1 |
|
||||
| `blockIndex`、`orderInBlock` | 區塊 0–7、區塊內第幾回合 0–9。熱身與自由模式為 -1 |
|
||||
| `isWarmup` | 熱身回合,分析時請排除 |
|
||||
| `assistFovDeg` | 作用範圍半徑(度),無輔助時為 0 |
|
||||
| `roundSeed` | 這一回合的亂數種子:後座力、生成點、機器人動作、延遲抖動都由它開始。機器人動作與抖動的取用次數隨幀而變,所以只能近似重現 |
|
||||
| `targetFps`、`vSyncCount` | 實際生效的幀率設定,`targetFps` 為 -1 表示不限制 |
|
||||
|
||||
## 版本與資料階段
|
||||
|
||||
| 階段 | 版本 | 說明 |
|
||||
|---|---|---|
|
||||
| 第一階段(data_1) | v1.0.1 | 開發者自行錄製,用於驗證流程與初步分析。共 150 回合(無輔助 100、平滑跟槍 20 / 40 / 60 / 80 / 100% 各 10),武器 Uzi,地圖以地下室為主,500Hz 滑鼠,辨識延遲 15ms ± 5ms,作用範圍固定 15° |
|
||||
| 第二、三階段(data_2、data_3) | v1.0.2 起 | 熟識受試者與公開招募。作用範圍同樣固定 15° |
|
||||
| 第一階段(data_1) | `appVersion` 皆為 1.0.1 | 兩位玩家,**每人** 150 回合(無輔助 100、有輔助 50),125Hz 滑鼠,60Hz 螢幕,辨識延遲 15ms ± 5ms。先錄完有輔助(強度 20 → 100),再錄無輔助 |
|
||||
| 第二階段起 | v1.1.0 | 自動配置,見下方「v1.1.0 錄製協定」 |
|
||||
|
||||
作用範圍從 v1.0.1 起固定為 15°,使輔助強度成為唯一控制修正行為的變數。最早發佈的 v1.0.0 作用範圍會隨強度在 5°–30° 之間變化,若有這個版本的資料,請以 frames 的 `assist_fov` 為準。
|
||||
第一階段兩位玩家的差異:
|
||||
|
||||
| | 武器 | 地圖 | 靈敏度 | 作用範圍 |
|
||||
|---|---|---|---|---|
|
||||
| 玩家 1 | Uzi | 地下室 | 1.2 | 固定 15° |
|
||||
| 玩家 2 | AK74 | 森林 | 7.0 | 隨強度 20 / 40 / 60 / 80 / 100 為 10 / 15 / 20 / 25 / 30° |
|
||||
|
||||
兩人的 `appVersion` 都是 1.0.1,作用範圍卻不同:版號改成 1.0.1 時作用範圍仍是 5°–30°,之後才改成固定 15°,而版號沒有再更新。所以 v1.1.0 之前的資料請以 frames 的 `assist_fov` 為準;v1.1.0 起用 `buildId` 分辨 build。
|
||||
|
||||
### v1.1.0 錄製協定
|
||||
|
||||
勾選 StartUI 的「自動配置」就會照這個協定錄製:
|
||||
|
||||
- 熱身 5 回合(無輔助,`isWarmup` = true),接著 8 個區塊,每區塊 10 回合,共 85 回合。
|
||||
- 每個區塊有無輔助 5 回合、強度 20 / 40 / 60 / 80 / 100 各 1 回合,**區塊內隨機排序**。每次執行的種子都不同,完整順序在 `plan.csv`。
|
||||
- 固定的條件:地下室、Uzi、FOV 90、作用範圍 15°、辨識延遲 15ms ± 5ms(有無輔助都一樣)、目標幀率 60。靈敏度由玩家自選。
|
||||
- 畫面只顯示總進度,不顯示當下有無輔助與強度(玩家仍可能感覺得到)。
|
||||
- 回合存檔成功才進到下一項;中途回主畫面會重做同一項。關閉遊戲後再開是新的 session 與新的種子,不會接續。
|
||||
|
||||
## 模擬視覺模型
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ using UnityEngine;
|
||||
|
||||
// config_N.json 的內容 : 當下完整的 GameSettings + 這一回合的資訊
|
||||
// 直接繼承 GameSettings,之後 StartUI 多了什麼設定,這裡會自動跟著記錄
|
||||
// 輔助欄位以這一回合實際套用的條件為準 (自動配置時不是 StartUI 存的值)
|
||||
[Serializable]
|
||||
public class RoundConfig : GameSettings
|
||||
{
|
||||
@@ -21,23 +22,56 @@ public class RoundConfig : GameSettings
|
||||
public int frames;
|
||||
|
||||
// 重現與分析用
|
||||
public int recoilSeed;
|
||||
public int recoilSeed; // v1.1.0 起 = roundSeed
|
||||
public float cameraVerticalFov;
|
||||
public float fixedDeltaTime;
|
||||
public string appVersion;
|
||||
public string unityVersion;
|
||||
|
||||
public static RoundConfig Create(int index)
|
||||
// v1.1.0 : 協定、build 與排程 (自由模式的 planIndex / blockIndex / orderInBlock 為 -1)
|
||||
public string protocolVersion;
|
||||
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 orderInBlock; // 區塊內 0~9,熱身 -1
|
||||
public bool isWarmup; // 熱身回合 (分析時排除)
|
||||
public float assistFovDeg; // 作用範圍 (度),無輔助為 0
|
||||
public int roundSeed; // 這一回合的亂數種子
|
||||
public int targetFps; // Application.targetFrameRate,-1 = 不限制
|
||||
public int vSyncCount;
|
||||
|
||||
public static RoundConfig Create(int index, SessionPlan.RoundCondition condition)
|
||||
{
|
||||
RoundConfig c = new RoundConfig();
|
||||
JsonUtility.FromJsonOverwrite(JsonUtility.ToJson(Load()), c); // 複製目前存檔的設定
|
||||
|
||||
c.assistMode = condition.assistMode;
|
||||
c.assistStrength = condition.assistStrength;
|
||||
c.assistDelayMs = condition.assistDelayMs;
|
||||
c.assistDelayJitterMs = condition.assistDelayJitterMs;
|
||||
|
||||
c.roundIndex = index;
|
||||
c.startTimeLocal = DateTime.Now.ToString("o");
|
||||
c.startTime = Time.realtimeSinceStartupAsDouble;
|
||||
c.fixedDeltaTime = Time.fixedDeltaTime;
|
||||
c.appVersion = Application.version;
|
||||
c.unityVersion = Application.unityVersion;
|
||||
|
||||
c.protocolVersion = SessionPlan.ProtocolVersion;
|
||||
c.buildId = BuildInfo.Id;
|
||||
c.sessionId = SessionPlan.SessionId;
|
||||
c.planSeed = SessionPlan.PlanSeed;
|
||||
c.planIndex = condition.planIndex;
|
||||
c.blockIndex = condition.blockIndex;
|
||||
c.orderInBlock = condition.orderInBlock;
|
||||
c.isWarmup = condition.isWarmup;
|
||||
c.assistFovDeg = condition.assistFovDeg;
|
||||
c.roundSeed = condition.roundSeed;
|
||||
c.recoilSeed = condition.roundSeed;
|
||||
c.targetFps = Application.targetFrameRate;
|
||||
c.vSyncCount = QualitySettings.vSyncCount;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
@@ -77,14 +77,13 @@ public class RoundRecorder : MonoBehaviour
|
||||
round = new Round
|
||||
{
|
||||
bot = bot,
|
||||
config = RoundConfig.Create(index),
|
||||
config = RoundConfig.Create(index, spawner.CurrentCondition), // 條件在生成時已經由 BotSpawner 套用
|
||||
mouse = new CsvWriter(Path.Combine(folder, $"mouse_{index}.csv"), "t,dx,dy,left,frame"),
|
||||
frames = new CsvWriter(Path.Combine(folder, $"frames_{index}.csv"), FrameHeader),
|
||||
events = new CsvWriter(Path.Combine(folder, $"events_{index}.csv"), "t,type,weapon,part,damage,bot_hp,ammo"),
|
||||
};
|
||||
|
||||
if (perceptor != null && perceptor.viewCamera != null) round.config.cameraVerticalFov = perceptor.viewCamera.fieldOfView;
|
||||
if (loadout != null && loadout.Current != null) round.config.recoilSeed = loadout.Current.RecoilSeed;
|
||||
|
||||
bot.Died += OnBotDied;
|
||||
WriteEvent("round_start");
|
||||
@@ -123,6 +122,7 @@ public class RoundRecorder : MonoBehaviour
|
||||
File.WriteAllText(Path.Combine(SessionStorage.Folder, $"config_{c.roundIndex}.json"), JsonUtility.ToJson(c, true));
|
||||
|
||||
SessionStorage.MarkRoundSaved(c.assistMode);
|
||||
SessionPlan.MarkSaved(c.planIndex); // 存檔成功才前進到下一項
|
||||
Debug.Log($"第 {c.roundIndex} 回合已存檔 ({c.duration:F1} 秒,{c.mouseEvents} 筆滑鼠事件,{c.frames} 幀)");
|
||||
round = null;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,9 @@ public static class SessionStorage
|
||||
private static string startStamp;
|
||||
private static int nextRoundIndex;
|
||||
|
||||
// 這次執行的開始時間 (資料夾與 zip 的名稱,也是 config 的 sessionId)
|
||||
public static string StartStamp => startStamp;
|
||||
|
||||
// 這次執行已存的回合數 (給 StartUI 顯示,方便貢獻者平衡無輔助 / 有輔助)
|
||||
public static int NoAssistRounds { get; private set; }
|
||||
public static int AssistRounds { get; private set; }
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
// 遊戲中顯示目前回合進度 (自動配置 : 第 n / 85 回合,不顯示有無輔助 ; 自由模式 : 已記錄幾回合 ; 測試模式不顯示)
|
||||
// 掛在 PlayerRig,Text 放在 HUD 上
|
||||
public class RoundProgressHUD : MonoBehaviour
|
||||
{
|
||||
[Header("UI 參照")]
|
||||
[Tooltip("Text (TMP)")]
|
||||
public TextMeshProUGUI progressText;
|
||||
|
||||
private GameSettings settings;
|
||||
|
||||
void Start()
|
||||
{
|
||||
settings = GameSettings.Load();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (progressText != null) progressText.text = SessionPlan.GetProgressText(settings);
|
||||
}
|
||||
}
|
||||
@@ -50,6 +50,13 @@ public class HitscanWeapon : MonoBehaviour
|
||||
recoilRandom = new System.Random(RecoilSeed);
|
||||
}
|
||||
|
||||
// 每回合開始時重設 (種子 = 這一回合的 roundSeed,記在 config)
|
||||
public void ResetRecoilSeed(int seed)
|
||||
{
|
||||
RecoilSeed = seed;
|
||||
recoilRandom = new System.Random(seed);
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
// 切槍時取消換彈,模型回到原位
|
||||
|
||||
@@ -41,6 +41,16 @@ public class WeaponLoadout : MonoBehaviour
|
||||
else if (Keyboard.current.digit4Key.wasPressedThisFrame) Equip(3);
|
||||
}
|
||||
|
||||
// 每回合開始時由 BotSpawner 呼叫 : 所有槍都重設後座力種子 (不看 Current,因為第一回合時可能還沒 Equip)
|
||||
public void SetRecoilSeed(int seed)
|
||||
{
|
||||
if (weapons == null) return;
|
||||
foreach (HitscanWeapon w in weapons)
|
||||
{
|
||||
if (w != null) w.ResetRecoilSeed(seed);
|
||||
}
|
||||
}
|
||||
|
||||
void Equip(int index)
|
||||
{
|
||||
if (index < 0 || index >= weapons.Length || weapons[index] == null) return;
|
||||
|
||||
Reference in new issue
Block a user