1.2.0
This commit is contained in:
1 parent
c3bb8d1a9e
commit
fd0312270b
26 files changed
+3310
-87
No files matched your search
@@ -28,6 +28,11 @@ public class GameSettings
|
||||
public bool isTest = false; // 測試模式 : 不記錄資料
|
||||
public bool autoPlan = false; // 自動配置 (正式錄製) : 由 SessionPlan 安排每回合有無輔助與強度,鎖定地圖 / 武器 / FOV
|
||||
|
||||
// v1.2.0 : 滑鼠 (選填,沒填是空字串 / 0) 與畫質
|
||||
public string mouseModel = "";
|
||||
public int mouseDpi = 0; // 100~50000,0 = 沒填
|
||||
public bool lowQuality = false; // 低畫質 : 切到最低的畫質等級 (只影響畫面)
|
||||
|
||||
// 系統資訊
|
||||
public int screenWidth;
|
||||
public int screenHeight;
|
||||
|
||||
@@ -4,7 +4,7 @@ using System.IO;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
// 自動配置 (v1.1.0 正式錄製協定) : 這次執行的回合順序、進度與亂數種子
|
||||
// 自動配置 (v1.2.0 正式錄製協定) : 這次執行的回合順序、進度與亂數種子
|
||||
// 勾了 StartUI 的「自動配置」才會套排程 ; 自由模式與測試模式也由這裡組出條件,讓輔助腳本只走同一條路徑
|
||||
// 跨場景共用 (回主畫面再回來,進度接著走) ; 回合存檔成功才前進,所以中途離開會重做同一個條件
|
||||
// 當機後重開 : 新的種子、進度歸零,不接續 (舊回合由 SessionStorage 的 recovered/ 處理)
|
||||
@@ -18,21 +18,21 @@ public static class SessionPlan
|
||||
public int assistDelayMs; // 模擬辨識延遲 (自動配置兩類回合都一樣)
|
||||
public int assistDelayJitterMs;
|
||||
public float assistFovDeg; // 作用範圍 : 有輔助 15, 無輔助 0 (frames 的 assist_fov)
|
||||
public int planIndex; // 排程中的第幾項 (熱身 0~4, 正式 5~84) ; 自由 / 測試模式 -1
|
||||
public int blockIndex; // 區塊 0~7 ; 熱身、自由 / 測試模式 -1
|
||||
public int planIndex; // 排程中的第幾項 (熱身 0~2, 正式 3~52) ; 自由 / 測試模式 -1
|
||||
public int blockIndex; // 區塊 0~4 ; 熱身、自由 / 測試模式 -1
|
||||
public int orderInBlock; // 區塊內 0~9 ; 熱身、自由 / 測試模式 -1
|
||||
public bool isWarmup; // 熱身回合照常存檔,分析時排除
|
||||
public int roundSeed; // 這一回合的亂數種子 (後座力、機器人動作、生成點、延遲抖動)
|
||||
}
|
||||
|
||||
// ===== 協定常數 : 改任何一個都要升版號,已錄的人全部重錄 =====
|
||||
public const string ProtocolVersion = "1.1.0";
|
||||
public const int WarmupRounds = 5; // 熱身 : 無輔助
|
||||
public const int Blocks = 8; // 試錄超過 20 分鐘就改 7,出包前決定
|
||||
public const string ProtocolVersion = "1.2.0";
|
||||
public const int WarmupRounds = 3; // 熱身 : 無輔助 (v1.1.0 為 5)
|
||||
public const int Blocks = 5; // v1.1.0 為 8
|
||||
public const int NoAssistPerBlock = 5; // 每區塊無輔助回合數
|
||||
public static readonly int[] Strengths = { 20, 40, 60, 80, 100 }; // 每區塊各一回合
|
||||
public const int RoundsPerBlock = NoAssistPerBlock + 5; // 5 = Strengths 的個數
|
||||
public const int Total = WarmupRounds + Blocks * RoundsPerBlock; // 85
|
||||
public const int Total = WarmupRounds + Blocks * RoundsPerBlock; // 53
|
||||
public const float AssistFovDeg = 15f;
|
||||
public const int DelayMs = 15;
|
||||
public const int JitterMs = 5;
|
||||
@@ -40,6 +40,7 @@ public static class SessionPlan
|
||||
public const string Weapon = "Uzi";
|
||||
public const int Fov = 90;
|
||||
public const int TargetFps = 60;
|
||||
public const float FpsWarnThreshold = 55f; // 熱身平均 FPS 低於這個值就提示 (不擋錄製)
|
||||
|
||||
// 這次執行的排程種子 (6 個人各自不同) ; 種子加 Generate() 就能重算整份順序
|
||||
public static int PlanSeed { get; private set; }
|
||||
@@ -58,6 +59,12 @@ public static class SessionPlan
|
||||
private static int progress;
|
||||
private static System.Random freeSeedRandom;
|
||||
|
||||
// 熱身的幀數與遊玩秒數 (扣掉暫停) : 熱身做完後算平均 FPS
|
||||
private static long warmupFrames;
|
||||
private static double warmupSeconds;
|
||||
private static bool fpsChecked;
|
||||
private static int defaultQualityLevel = -1;
|
||||
|
||||
// 每次進入 Play 都重設 (編輯器關掉 Domain Reload 時,static 不會自動清空)
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void Init()
|
||||
@@ -67,6 +74,9 @@ public static class SessionPlan
|
||||
progress = 0;
|
||||
Started = false;
|
||||
freeSeedRandom = new System.Random();
|
||||
warmupFrames = 0;
|
||||
warmupSeconds = 0;
|
||||
fpsChecked = false;
|
||||
}
|
||||
|
||||
public static bool IsAuto(GameSettings s) => s != null && s.autoPlan && !s.isTest;
|
||||
@@ -121,6 +131,24 @@ public static class SessionPlan
|
||||
if (planIndex >= 0 && planIndex == progress) progress++;
|
||||
}
|
||||
|
||||
// ===== 熱身 FPS 檢查 =====
|
||||
|
||||
// 熱身回合存檔時呼叫 (幀數只算有寫進 frames 的幀,秒數扣掉暫停)
|
||||
public static void AddWarmupRound(int frames, double playSeconds)
|
||||
{
|
||||
if (playSeconds <= 0) return;
|
||||
warmupFrames += frames;
|
||||
warmupSeconds += playSeconds;
|
||||
}
|
||||
|
||||
// 熱身的平均 FPS ; 熱身還沒做完為 -1
|
||||
public static float WarmupFps => progress >= WarmupRounds && warmupSeconds > 0 ? (float)(warmupFrames / warmupSeconds) : -1f;
|
||||
|
||||
// 熱身剛做完、第一個正式回合生成之前,而且還沒檢查過 (回主選單再進來不會再檢查一次)
|
||||
public static bool NeedsFpsCheck(GameSettings s) => IsAuto(s) && progress == WarmupRounds && !fpsChecked;
|
||||
|
||||
public static void MarkFpsChecked() => fpsChecked = true;
|
||||
|
||||
// 畫面上的進度文字 : 不顯示有無輔助或強度
|
||||
public static string GetProgressText(GameSettings s)
|
||||
{
|
||||
@@ -133,7 +161,7 @@ public static class SessionPlan
|
||||
return $"已記錄 {SessionStorage.NoAssistRounds + SessionStorage.AssistRounds} 回合";
|
||||
}
|
||||
|
||||
// 由種子產生整份順序 : 熱身 5 回合無輔助 ; 之後每區塊 10 回合 (無輔助 5、各強度 1),區塊內隨機排序
|
||||
// 由種子產生整份順序 : 熱身 3 回合無輔助 ; 之後每區塊 10 回合 (無輔助 5、各強度 1),區塊內隨機排序
|
||||
// 同一個種子一定得到同一份順序
|
||||
public static List<RoundCondition> Generate(int seed)
|
||||
{
|
||||
@@ -206,6 +234,19 @@ public static class SessionPlan
|
||||
};
|
||||
}
|
||||
|
||||
// 進遊戲前套用畫質與幀率 : 切換畫質等級會改掉 vSync 設定,所以幀率一定要在畫質之後設
|
||||
// 低畫質 = 最低的畫質等級 (索引 0) ; 只影響畫面,遊戲邏輯與遮擋判定 (碰撞體射線) 不受影響
|
||||
public static void ApplyDisplaySettings(GameSettings s)
|
||||
{
|
||||
// 一般畫質 = 名稱為 PC 的等級 ; 找不到才用第一次呼叫時的等級 (編輯器裡上次 Play 切過的等級會留著,所以優先用名稱)
|
||||
if (defaultQualityLevel < 0) defaultQualityLevel = QualitySettings.GetQualityLevel();
|
||||
int normal = Array.IndexOf(QualitySettings.names, "PC");
|
||||
if (normal < 0) normal = defaultQualityLevel;
|
||||
int level = s != null && s.lowQuality ? 0 : normal;
|
||||
if (QualitySettings.GetQualityLevel() != level) QualitySettings.SetQualityLevel(level, true);
|
||||
ApplyFrameRate(s);
|
||||
}
|
||||
|
||||
// 自動配置時固定幀率,讓每個人的幀間隔一致 (實際幀率仍由 frames 的 dt 記錄) ; 其他模式維持不限制
|
||||
public static void ApplyFrameRate(GameSettings s)
|
||||
{
|
||||
|
||||
@@ -7,7 +7,8 @@ using UnityEngine;
|
||||
using Debug = UnityEngine.Debug;
|
||||
|
||||
// Build 前把 git commit 短碼寫到 Assets/BuildInfo/Resources/build_id.txt (不進 git),執行時由 BuildInfo.Id 讀出、記進 config 的 buildId
|
||||
// 工作區不乾淨 (有未提交的改動) 會在後面加 "-dirty" 並警告 : 正式出包前請先全部 commit,出包後對該 commit 打 tag
|
||||
// 工作區不乾淨 (有未提交的改動) 會在後面加 "-dirty" ; git 執行不了時改讀 .git 檔案並加 "-nogit" ; 都讀不到是 "unknown"
|
||||
// 正式出包前請先全部 commit,出包後對該 commit 打 tag
|
||||
public class BuildIdWriter : IPreprocessBuildWithReport
|
||||
{
|
||||
const string Folder = "Assets/BuildInfo/Resources";
|
||||
@@ -16,9 +17,32 @@ public class BuildIdWriter : IPreprocessBuildWithReport
|
||||
public int callbackOrder => 0;
|
||||
|
||||
public void OnPreprocessBuild(BuildReport report)
|
||||
{
|
||||
string id = BuildId();
|
||||
|
||||
Directory.CreateDirectory(Folder);
|
||||
File.WriteAllText(FilePath, id);
|
||||
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
|
||||
Debug.Log($"BuildIdWriter : buildId = {id}");
|
||||
}
|
||||
|
||||
// 正式出包應該是乾淨的 7 碼 ; 出現 -dirty、-nogit、unknown 都代表這個 exe 不該發出去
|
||||
static string BuildId()
|
||||
{
|
||||
string hash = Git("rev-parse --short HEAD");
|
||||
string id = string.IsNullOrEmpty(hash) ? "unknown" : hash;
|
||||
|
||||
// git 執行不了 (v1.1.0 出過包) : 改直接讀 .git 裡的檔案,但無法判斷工作區乾不乾淨
|
||||
if (string.IsNullOrEmpty(hash))
|
||||
{
|
||||
string fromFiles = ReadHeadFromFiles();
|
||||
if (string.IsNullOrEmpty(fromFiles))
|
||||
{
|
||||
Debug.LogWarning("BuildIdWriter : git 與 .git 檔案都讀不到,buildId 會是 unknown。這個 exe 不該發出去。");
|
||||
return "unknown";
|
||||
}
|
||||
Debug.LogWarning("BuildIdWriter : git 執行失敗,改從 .git 檔案讀 commit,無法確認工作區是否乾淨,buildId 加上 -nogit。這個 exe 不該發出去,請在 git 能正常執行的環境重新出包。");
|
||||
return fromFiles + "-nogit";
|
||||
}
|
||||
|
||||
bool dirty = false;
|
||||
foreach (string line in Git("status --porcelain").Split('\n'))
|
||||
@@ -31,14 +55,61 @@ public class BuildIdWriter : IPreprocessBuildWithReport
|
||||
|
||||
if (dirty)
|
||||
{
|
||||
id += "-dirty";
|
||||
Debug.LogWarning("BuildIdWriter : 工作區有未提交的改動,buildId 加上 -dirty。正式出包請先 commit 再 Build。");
|
||||
return hash + "-dirty";
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
Directory.CreateDirectory(Folder);
|
||||
File.WriteAllText(FilePath, id);
|
||||
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
|
||||
Debug.Log($"BuildIdWriter : buildId = {id}");
|
||||
// 讀 .git/HEAD : 「ref: refs/heads/<分支>」就再讀該分支的檔案 (沒有就找 packed-refs) ; 直接是雜湊 (detached HEAD) 就用它
|
||||
// 回傳前 7 碼,讀不到回傳空字串
|
||||
static string ReadHeadFromFiles()
|
||||
{
|
||||
try
|
||||
{
|
||||
string gitDir = Path.Combine(Path.GetDirectoryName(Application.dataPath), ".git");
|
||||
string head = File.ReadAllText(Path.Combine(gitDir, "HEAD")).Trim();
|
||||
|
||||
string hash = head;
|
||||
if (head.StartsWith("ref:"))
|
||||
{
|
||||
string refName = head.Substring(4).Trim();
|
||||
string refPath = Path.Combine(gitDir, refName.Replace('/', Path.DirectorySeparatorChar));
|
||||
hash = File.Exists(refPath) ? File.ReadAllText(refPath).Trim() : FindPackedRef(gitDir, refName);
|
||||
}
|
||||
|
||||
return IsHash(hash) ? hash.Substring(0, 7) : "";
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogWarning($"BuildIdWriter : 讀取 .git 檔案失敗 ({e.Message})");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
// packed-refs 每行是「<雜湊> <ref 名稱>」,# 開頭是註解,^ 開頭是 tag 指向的 commit
|
||||
static string FindPackedRef(string gitDir, string refName)
|
||||
{
|
||||
string path = Path.Combine(gitDir, "packed-refs");
|
||||
if (!File.Exists(path)) return "";
|
||||
foreach (string raw in File.ReadAllLines(path))
|
||||
{
|
||||
string line = raw.Trim();
|
||||
if (line.Length == 0 || line[0] == '#' || line[0] == '^') continue;
|
||||
int space = line.IndexOf(' ');
|
||||
if (space > 0 && line.Substring(space + 1).Trim() == refName) return line.Substring(0, space);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
static bool IsHash(string s)
|
||||
{
|
||||
if (string.IsNullOrEmpty(s) || s.Length < 40) return false;
|
||||
for (int i = 0; i < 40; i++)
|
||||
{
|
||||
if (!System.Uri.IsHexDigit(s[i])) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static string Git(string arguments)
|
||||
@@ -62,7 +133,7 @@ public class BuildIdWriter : IPreprocessBuildWithReport
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogWarning($"BuildIdWriter : 執行 git 失敗 ({e.Message}),buildId 會是 unknown");
|
||||
Debug.LogWarning($"BuildIdWriter : 執行 git 失敗 ({e.Message}),改讀 .git 檔案");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a00a586eeeb99241b2b77f6cdd35837
|
||||
@@ -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;
|
||||
|
||||
@@ -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 視覺模型」。它直接讀取敵人的骨架位置(完美感知器),只加上三個真實外掛本來就有的限制,**不做插值或預測**:
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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,7 +1,7 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
// 遊戲中顯示目前回合進度 (自動配置 : 第 n / 85 回合,不顯示條件 ; 自由模式 : 已記錄幾回合 ; 測試模式不顯示)
|
||||
// 遊戲中顯示目前回合進度 (自動配置 : 第 n / 總回合數,不顯示條件 ; 自由模式 : 已記錄幾回合 ; 測試模式不顯示)
|
||||
// 掛在 PlayerRig,Text 放在 HUD 上
|
||||
public class RoundProgressHUD : MonoBehaviour
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
|
||||
// 滑鼠型號與 DPI (v1.2.0,選填) : 不知道可以留白,不填也能開始
|
||||
// 存進 GameSettings 的 mouseModel / mouseDpi,每回合的 config 都會帶著 ; 回報率由資料端從 mouse_N.csv 算
|
||||
public class MouseInfo : MonoBehaviour
|
||||
{
|
||||
[Header("UI 參照")]
|
||||
[Tooltip("滑鼠型號 InputField")]
|
||||
public TMP_InputField modelInput;
|
||||
|
||||
[Tooltip("DPI InputField")]
|
||||
public TMP_InputField dpiInput;
|
||||
|
||||
public const int MaxModelLength = 40;
|
||||
public const int MinDpi = 100;
|
||||
public const int MaxDpi = 50000;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (modelInput != null) modelInput.characterLimit = MaxModelLength;
|
||||
if (dpiInput != null)
|
||||
{
|
||||
dpiInput.contentType = TMP_InputField.ContentType.IntegerNumber;
|
||||
dpiInput.characterLimit = 5;
|
||||
}
|
||||
}
|
||||
|
||||
// 沒填為空字串
|
||||
public string GetModel()
|
||||
{
|
||||
if (modelInput == null) return "";
|
||||
string text = modelInput.text.Trim();
|
||||
return text.Length > MaxModelLength ? text.Substring(0, MaxModelLength) : text;
|
||||
}
|
||||
|
||||
// 沒填、不是數字、超出 100~50000 都當沒填 (0)
|
||||
public int GetDpi()
|
||||
{
|
||||
if (dpiInput == null) return 0;
|
||||
if (!int.TryParse(dpiInput.text.Trim(), out int dpi)) return 0;
|
||||
return dpi >= MinDpi && dpi <= MaxDpi ? dpi : 0;
|
||||
}
|
||||
|
||||
// 回填上次的值
|
||||
public void Restore(string model, int dpi)
|
||||
{
|
||||
if (modelInput != null) modelInput.text = model ?? "";
|
||||
if (dpiInput != null) dpiInput.text = dpi > 0 ? dpi.ToString() : "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc3f787234bcacf4e91a4a93a6318931
|
||||
@@ -27,6 +27,13 @@ public class SettingsSaver : MonoBehaviour
|
||||
public Slider sensitivitySlider;
|
||||
public Slider fovSlider;
|
||||
|
||||
[Header("滑鼠與畫質 (v1.2.0)")]
|
||||
[Tooltip("滑鼠型號與 DPI 輸入欄 (選填)")]
|
||||
public MouseInfo mouseInfo;
|
||||
|
||||
[Tooltip("低畫質 Toggle : 勾了就切到最低的畫質等級 (只影響畫面)")]
|
||||
public Toggle lowQualityToggle;
|
||||
|
||||
[Header("輔助設定")]
|
||||
public TMP_Dropdown assistDropdown;
|
||||
public Slider assistStrengthSlider;
|
||||
@@ -103,7 +110,7 @@ public class SettingsSaver : MonoBehaviour
|
||||
RestoreLastSettings();
|
||||
}
|
||||
|
||||
// 回填上次的 ID、靈敏度、FOV (不用每次重打)
|
||||
// 回填上次的 ID、靈敏度、FOV、滑鼠型號與 DPI、低畫質 (不用每次重打)
|
||||
// 自動配置不從檔案回填 : 舊版的設定檔沒有這一項,會變成沒勾 ; 以場景的預設為準,這次執行用過就維持勾選
|
||||
void RestoreLastSettings()
|
||||
{
|
||||
@@ -117,6 +124,8 @@ public class SettingsSaver : MonoBehaviour
|
||||
}
|
||||
if (sensitivitySlider != null) sensitivitySlider.value = (float)last.sensitivity;
|
||||
if (fovSlider != null) fovSlider.value = last.fov;
|
||||
if (mouseInfo != null) mouseInfo.Restore(last.mouseModel, last.mouseDpi);
|
||||
if (lowQualityToggle != null) lowQualityToggle.isOn = last.lowQuality;
|
||||
}
|
||||
|
||||
// 要勾同意書,而且 Raw Input 正常運作 (沒有它就拿不到每一筆的真實時間,資料不能用) ; 測試不受影響
|
||||
@@ -184,7 +193,7 @@ public class SettingsSaver : MonoBehaviour
|
||||
}
|
||||
|
||||
settings.Save();
|
||||
SessionPlan.ApplyFrameRate(settings);
|
||||
SessionPlan.ApplyDisplaySettings(settings); // 畫質 → 幀率 (順序不能反)
|
||||
Debug.Log($"設定已存到 : {GameSettings.FilePath}");
|
||||
|
||||
SceneManager.LoadScene(settings.map);
|
||||
@@ -200,6 +209,13 @@ public class SettingsSaver : MonoBehaviour
|
||||
if (sensitivitySlider != null) s.sensitivity = Math.Round(sensitivitySlider.value * 10.0) / 10.0;
|
||||
if (fovSlider != null) s.fov = Mathf.RoundToInt(fovSlider.value);
|
||||
|
||||
if (mouseInfo != null)
|
||||
{
|
||||
s.mouseModel = mouseInfo.GetModel();
|
||||
s.mouseDpi = mouseInfo.GetDpi();
|
||||
}
|
||||
if (lowQualityToggle != null) s.lowQuality = lowQualityToggle.isOn;
|
||||
|
||||
if (assistDropdown != null) s.assistMode = assistDropdown.value;
|
||||
if (disableHorizontalToggle != null) s.disableHorizontalAssist = disableHorizontalToggle.isOn;
|
||||
if (disableVerticalToggle != null) s.disableVerticalAssist = disableVerticalToggle.isOn;
|
||||
|
||||
Reference in new issue
Block a user