startUI告一段落
This commit is contained in:
1 parent
f8154f92b3
commit
da28b62f7f
34 files changed
+17562
-8231
No files matched your search
@@ -0,0 +1,34 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
// 模擬視覺模型從擷取畫面到輸出的延遲 (ms)
|
||||
public class AssistDelay : MonoBehaviour
|
||||
{
|
||||
[Header("UI 參照")]
|
||||
[Tooltip("Slider")]
|
||||
public Slider targetSlider;
|
||||
|
||||
[Tooltip("Text (TMP)")]
|
||||
public TextMeshProUGUI valueDisplayText;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (targetSlider != null)
|
||||
{
|
||||
targetSlider.wholeNumbers = true; // 每 1ms 一個階梯
|
||||
|
||||
UpdateDisplayText(targetSlider.value);
|
||||
|
||||
targetSlider.onValueChanged.AddListener(UpdateDisplayText);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateDisplayText(float val)
|
||||
{
|
||||
if (valueDisplayText != null)
|
||||
{
|
||||
valueDisplayText.text = $"模型辨識延遲 : {Mathf.RoundToInt(val)}ms";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a2d18eba6835c547bf28091724887c3
|
||||
@@ -12,9 +12,9 @@ public class AssistIntro : MonoBehaviour
|
||||
|
||||
private readonly string[] intros = new string[]
|
||||
{
|
||||
" 不使用任何瞄準輔助,使用你最純粹的反應力與控制力瞄準。如果可以的話,無輔助與有輔助的測試次數請盡量控制在 1 : 1。",
|
||||
" 依照敵方在螢幕上的座標,直接移動準心以實現瞄準。輔助強度為移動量,如設定 100% 會形成暴力鎖。",
|
||||
" 依照敵方在螢幕上與你準心的距離,動態更改你的靈敏度(接近敵方時降低靈敏度)以吸附準心。輔助強度為靈敏度降低程度。"
|
||||
" 不使用任何瞄準輔助,紀錄純淨的軌跡資料,使用你最純粹的反應力與控制力瞄準。如果可以的話,無輔助與有輔助的測試次數請盡量控制在 1 : 1。",
|
||||
" 計算準心到敵方的向量,依照輔助強度的比例加到你的滑鼠移動上,把準心往敵方拉。輔助強度越高拉得越用力,100% 接近暴力鎖。敵方被擋住太多時不會觸發。",
|
||||
" 依照敵方在螢幕上與你準心的距離,動態調整你的靈敏度(靠近敵方時降低、遠離時提高)。輔助強度為靈敏度變化程度。敵方被擋住太多時不會觸發。"
|
||||
};
|
||||
|
||||
void Start()
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
// 通用 : Dropdown 換選項時,同步更換示意圖與介紹文字
|
||||
// 地圖、武器各掛一份,圖片與文字直接在 Inspector 填 (順序要跟 Dropdown 的選項一致)
|
||||
public class DropdownPreview : MonoBehaviour
|
||||
{
|
||||
[Header("UI 參照")]
|
||||
[Tooltip("Dropdown")]
|
||||
public TMP_Dropdown targetDropdown;
|
||||
|
||||
[Tooltip("示意圖 Image")]
|
||||
public Image previewImage;
|
||||
|
||||
[Tooltip("介紹 Text (TMP)")]
|
||||
public TextMeshProUGUI introText;
|
||||
|
||||
[Header("內容 (順序對應 Dropdown 選項)")]
|
||||
public Sprite[] previews;
|
||||
|
||||
[TextArea(2, 5)]
|
||||
public string[] intros;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (targetDropdown != null)
|
||||
{
|
||||
UpdatePreview(targetDropdown.value);
|
||||
|
||||
targetDropdown.onValueChanged.AddListener(UpdatePreview);
|
||||
}
|
||||
}
|
||||
|
||||
void UpdatePreview(int index)
|
||||
{
|
||||
if (previewImage != null && previews != null && index >= 0 && index < previews.Length)
|
||||
{
|
||||
previewImage.sprite = previews[index];
|
||||
}
|
||||
|
||||
if (introText != null && intros != null && index >= 0 && index < intros.Length)
|
||||
{
|
||||
introText.text = intros[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b44182b3e69fa5c48808cc503cdaa65e
|
||||
@@ -0,0 +1,61 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.InputSystem;
|
||||
|
||||
// 按 Esc 跳出「確認退出」視窗,再按一次 Esc 或按取消就關閉
|
||||
public class ExitConfirm : MonoBehaviour
|
||||
{
|
||||
[Header("UI 參照")]
|
||||
[Tooltip("確認退出的視窗 (Panel)")]
|
||||
public GameObject exitPanel;
|
||||
|
||||
[Tooltip("確定退出 Button")]
|
||||
public Button confirmButton;
|
||||
|
||||
[Tooltip("取消 Button")]
|
||||
public Button cancelButton;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (exitPanel != null)
|
||||
{
|
||||
exitPanel.SetActive(false);
|
||||
}
|
||||
|
||||
if (confirmButton != null)
|
||||
{
|
||||
confirmButton.onClick.AddListener(QuitGame);
|
||||
}
|
||||
|
||||
if (cancelButton != null)
|
||||
{
|
||||
cancelButton.onClick.AddListener(ClosePanel);
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Keyboard.current != null && Keyboard.current.escapeKey.wasPressedThisFrame && exitPanel != null)
|
||||
{
|
||||
exitPanel.SetActive(!exitPanel.activeSelf);
|
||||
}
|
||||
}
|
||||
|
||||
void ClosePanel()
|
||||
{
|
||||
if (exitPanel != null)
|
||||
{
|
||||
exitPanel.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
void QuitGame()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
// 在編輯器裡 Application.Quit 沒有作用,改成停止播放
|
||||
UnityEditor.EditorApplication.isPlaying = false;
|
||||
#else
|
||||
Application.Quit();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 740c69205780eb745ace1bf66b48af99
|
||||
@@ -18,7 +18,6 @@ public class Fov : MonoBehaviour
|
||||
{
|
||||
if (targetSlider != null)
|
||||
{
|
||||
// 與 Apex 相同的範圍
|
||||
targetSlider.minValue = 70f;
|
||||
targetSlider.maxValue = 110f;
|
||||
targetSlider.wholeNumbers = true;
|
||||
|
||||
@@ -8,7 +8,12 @@ public class Movement : MonoBehaviour
|
||||
[Tooltip("Text (TMP)")]
|
||||
public TextMeshProUGUI movementVectorText;
|
||||
private Vector2 smoothedDelta = Vector2.zero;
|
||||
private const float alpha = 0.1f; // 數值越大 越貼最新數值
|
||||
private const float alpha = 0.1f;
|
||||
|
||||
[Header("顯示")]
|
||||
[Tooltip("文字更新間隔 (秒),計算仍然每幀進行")]
|
||||
public float updateInterval = 0.5f;
|
||||
private float displayTimer = 0f;
|
||||
|
||||
void Update()
|
||||
{
|
||||
@@ -30,6 +35,10 @@ public class Movement : MonoBehaviour
|
||||
smoothedDelta = Vector2.zero;
|
||||
}
|
||||
|
||||
displayTimer += Time.unscaledDeltaTime;
|
||||
if (displayTimer < updateInterval) return;
|
||||
displayTimer = 0f;
|
||||
|
||||
if (movementVectorText != null)
|
||||
{
|
||||
string xStr = (smoothedDelta.x >= 0 ? "+" : "") + smoothedDelta.x.ToString("F1");
|
||||
|
||||
@@ -32,6 +32,15 @@ public class Polling : MonoBehaviour
|
||||
private float timeSinceLastEvent = 0f;
|
||||
private const float idleTimeout = 2f; // 超過 2 秒沒動就歸零
|
||||
|
||||
[Header("顯示")]
|
||||
[Tooltip("文字更新間隔 (秒),偵測仍然每幀進行")]
|
||||
public float updateInterval = 0.5f;
|
||||
private float displayTimer = 0f;
|
||||
private int shownHz = -1; // 上次顯示的數值,沒變就不重設文字
|
||||
|
||||
// 與 hook 交換用的暫存 List,避免每幀 new 一個新的
|
||||
private List<double> currentBatch = new List<double>();
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
stopwatch.Start();
|
||||
@@ -77,11 +86,13 @@ public class Polling : MonoBehaviour
|
||||
|
||||
void Update()
|
||||
{
|
||||
List<double> currentBatch;
|
||||
// 把 hook 收集的資料換過來,hook 改寫進清空的那一份
|
||||
currentBatch.Clear();
|
||||
lock (lockObj)
|
||||
{
|
||||
currentBatch = new List<double>(intervals);
|
||||
intervals.Clear();
|
||||
List<double> temp = intervals;
|
||||
intervals = currentBatch;
|
||||
currentBatch = temp;
|
||||
}
|
||||
|
||||
if (currentBatch.Count > 0)
|
||||
@@ -103,9 +114,8 @@ public class Polling : MonoBehaviour
|
||||
|
||||
if (smoothedMs > 0)
|
||||
{
|
||||
double rawHz = 1000.0 / smoothedMs;
|
||||
int standardHz = SnapToStandardPollingRate(rawHz);
|
||||
recentRates.Add(standardHz);
|
||||
// 直接用實測值,不對齊到 250 / 500 / 1000... 等標準值
|
||||
recentRates.Add((int)Math.Round(1000.0 / smoothedMs));
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -119,48 +129,30 @@ public class Polling : MonoBehaviour
|
||||
smoothedMs = 0;
|
||||
}
|
||||
|
||||
// 更新 UI
|
||||
if (pollingDisplay != null)
|
||||
int maxHz = 0;
|
||||
if (recentRates.Count > 0)
|
||||
{
|
||||
if (recentRates.Count > 0)
|
||||
foreach (int rate in recentRates)
|
||||
{
|
||||
int maxHz = recentRates[0];
|
||||
foreach (int rate in recentRates)
|
||||
{
|
||||
if (rate >= maxHz) maxHz = rate;
|
||||
}
|
||||
|
||||
pollingDisplay.text = $"滑鼠回報率: {maxHz} Hz";
|
||||
|
||||
if (recentRates.Count > 60)
|
||||
{
|
||||
recentRates.RemoveAt(0);
|
||||
}
|
||||
if (rate >= maxHz) maxHz = rate;
|
||||
}
|
||||
else
|
||||
{
|
||||
pollingDisplay.text = "滑鼠回報率: 0 Hz";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int SnapToStandardPollingRate(double rawHz)
|
||||
{
|
||||
int[] standardRates = {63, 125, 250, 500, 1000, 2000, 4000, 8000, 16000};
|
||||
int closestRate = standardRates[0];
|
||||
double minDifference = double.MaxValue;
|
||||
|
||||
foreach (int rate in standardRates)
|
||||
{
|
||||
double diff = Math.Abs(rawHz - rate);
|
||||
if (diff < minDifference)
|
||||
if (recentRates.Count > 60)
|
||||
{
|
||||
minDifference = diff;
|
||||
closestRate = rate;
|
||||
recentRates.RemoveAt(0);
|
||||
}
|
||||
}
|
||||
|
||||
return closestRate;
|
||||
// 每 updateInterval 秒才更新一次文字,數值沒變就不重設
|
||||
displayTimer += Time.unscaledDeltaTime;
|
||||
if (displayTimer < updateInterval) return;
|
||||
displayTimer = 0f;
|
||||
|
||||
if (pollingDisplay != null && maxHz != shownHz)
|
||||
{
|
||||
pollingDisplay.text = $"滑鼠回報率: {maxHz} Hz";
|
||||
shownHz = maxHz;
|
||||
}
|
||||
}
|
||||
|
||||
#region Win32 API 匯入
|
||||
|
||||
@@ -4,6 +4,8 @@ using UnityEngine.UI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using TMPro;
|
||||
|
||||
// 流程 : 勾同意書 → 按開始 → 跳出地圖/武器選擇視窗 → 按確認 → 存 JSON → 切到選擇的地圖場景
|
||||
// 測試 : 按測試 → 用目前設定存 JSON → 直接進測試場景 (不記錄資料,不需勾同意書)
|
||||
public class SettingsSaver : MonoBehaviour
|
||||
{
|
||||
[Header("開始與同意書")]
|
||||
@@ -23,13 +25,46 @@ public class SettingsSaver : MonoBehaviour
|
||||
public Slider assistStrengthSlider;
|
||||
public Toggle disableHorizontalToggle;
|
||||
public Toggle disableVerticalToggle;
|
||||
public Slider assistDelaySlider;
|
||||
public Toggle delayJitterToggle;
|
||||
|
||||
[Header("場景")]
|
||||
[Tooltip("要切換到的場景名稱 (需加入 Build Profiles 的場景清單)")]
|
||||
public string gameSceneName = "InGame";
|
||||
[Header("地圖與武器選擇視窗")]
|
||||
[Tooltip("按開始後跳出的視窗 (Panel)")]
|
||||
public GameObject selectPanel;
|
||||
|
||||
[Tooltip("確認開始 Button")]
|
||||
public Button confirmButton;
|
||||
|
||||
[Tooltip("取消 Button")]
|
||||
public Button cancelButton;
|
||||
|
||||
public TMP_Dropdown mapDropdown;
|
||||
public TMP_Dropdown weaponDropdown;
|
||||
|
||||
[Header("選項名稱 (順序對應 Dropdown 選項)")]
|
||||
[Tooltip("地圖的場景名稱 (需加入 Build Profiles 的場景清單)")]
|
||||
public string[] mapSceneNames = { "Forest", "Basement", "Desert" };
|
||||
|
||||
[Tooltip("武器名稱,會存進 JSON")]
|
||||
public string[] weaponNames = { "M1911", "AK74", "Uzi", "Benelli_M4" };
|
||||
|
||||
[Header("測試")]
|
||||
[Tooltip("測試 Button")]
|
||||
public Button testButton;
|
||||
|
||||
[Tooltip("測試場景名稱 (需加入 Build Profiles 的場景清單)")]
|
||||
public string testSceneName = "Test";
|
||||
|
||||
[Tooltip("測試時使用的武器")]
|
||||
public string testWeapon = "M1911";
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (selectPanel != null)
|
||||
{
|
||||
selectPanel.SetActive(false);
|
||||
}
|
||||
|
||||
if (consentToggle != null)
|
||||
{
|
||||
consentToggle.onValueChanged.AddListener(OnConsentChanged);
|
||||
@@ -40,6 +75,21 @@ public class SettingsSaver : MonoBehaviour
|
||||
{
|
||||
startButton.onClick.AddListener(OnStartClicked);
|
||||
}
|
||||
|
||||
if (confirmButton != null)
|
||||
{
|
||||
confirmButton.onClick.AddListener(OnConfirmClicked);
|
||||
}
|
||||
|
||||
if (cancelButton != null)
|
||||
{
|
||||
cancelButton.onClick.AddListener(OnCancelClicked);
|
||||
}
|
||||
|
||||
if (testButton != null)
|
||||
{
|
||||
testButton.onClick.AddListener(OnTestClicked);
|
||||
}
|
||||
}
|
||||
|
||||
void OnConsentChanged(bool isOn)
|
||||
@@ -54,18 +104,47 @@ public class SettingsSaver : MonoBehaviour
|
||||
{
|
||||
if (consentToggle != null && !consentToggle.isOn) return;
|
||||
|
||||
if (selectPanel != null)
|
||||
{
|
||||
selectPanel.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
void OnCancelClicked()
|
||||
{
|
||||
if (selectPanel != null)
|
||||
{
|
||||
selectPanel.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
void OnConfirmClicked()
|
||||
{
|
||||
SaveAndLoad(CollectSettings());
|
||||
}
|
||||
|
||||
void OnTestClicked()
|
||||
{
|
||||
GameSettings settings = CollectSettings();
|
||||
settings.map = testSceneName;
|
||||
settings.weapon = testWeapon;
|
||||
settings.isTest = true;
|
||||
|
||||
SaveAndLoad(settings);
|
||||
}
|
||||
|
||||
void SaveAndLoad(GameSettings settings)
|
||||
{
|
||||
if (!Application.CanStreamedLevelBeLoaded(settings.map))
|
||||
{
|
||||
Debug.LogError($"找不到場景 \"{settings.map}\",請確認已加入 Build Profiles 的場景清單");
|
||||
return;
|
||||
}
|
||||
|
||||
settings.Save();
|
||||
Debug.Log($"設定已存到 : {GameSettings.FilePath}");
|
||||
|
||||
if (Application.CanStreamedLevelBeLoaded(gameSceneName))
|
||||
{
|
||||
SceneManager.LoadScene(gameSceneName);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError($"找不到場景 \"{gameSceneName}\",請確認已加入 Build Profiles 的場景清單");
|
||||
}
|
||||
SceneManager.LoadScene(settings.map);
|
||||
}
|
||||
|
||||
GameSettings CollectSettings()
|
||||
@@ -83,9 +162,17 @@ public class SettingsSaver : MonoBehaviour
|
||||
{
|
||||
s.assistStrength = Mathf.RoundToInt(assistStrengthSlider.value);
|
||||
}
|
||||
if (assistDelaySlider != null && s.assistMode != 0)
|
||||
{
|
||||
s.assistDelayMs = Mathf.RoundToInt(assistDelaySlider.value);
|
||||
if (delayJitterToggle != null) s.assistDelayJitter = delayJitterToggle.isOn;
|
||||
}
|
||||
if (disableHorizontalToggle != null) s.disableHorizontalAssist = disableHorizontalToggle.isOn;
|
||||
if (disableVerticalToggle != null) s.disableVerticalAssist = disableVerticalToggle.isOn;
|
||||
|
||||
s.map = PickName(mapSceneNames, mapDropdown);
|
||||
s.weapon = PickName(weaponNames, weaponDropdown);
|
||||
|
||||
s.screenWidth = Screen.width;
|
||||
s.screenHeight = Screen.height;
|
||||
s.refreshRate = Mathf.RoundToInt((float)Screen.currentResolution.refreshRateRatio.value);
|
||||
@@ -93,4 +180,13 @@ public class SettingsSaver : MonoBehaviour
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
// 依 Dropdown 目前的選項取出對應名稱,沒接 Dropdown 就用第一個
|
||||
string PickName(string[] names, TMP_Dropdown dropdown)
|
||||
{
|
||||
if (names == null || names.Length == 0) return "";
|
||||
|
||||
int index = dropdown != null ? dropdown.value : 0;
|
||||
return names[Mathf.Clamp(index, 0, names.Length - 1)];
|
||||
}
|
||||
}
|
||||
@@ -2,14 +2,13 @@ using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
// 掛在開始按鈕上 : 按鈕反灰時,滑鼠移上去會顯示提示
|
||||
public class StartButtonHint : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
|
||||
{
|
||||
[Header("UI 參照")]
|
||||
[Tooltip("開始 Button")]
|
||||
public Button targetButton;
|
||||
|
||||
[Tooltip("提示物件 (例如寫著「請閱讀資訊欄並勾選同意書」的 Text 或 Panel)")]
|
||||
[Tooltip("提示物件")]
|
||||
public GameObject hintObject;
|
||||
|
||||
void Start()
|
||||
|
||||
Reference in new issue
Block a user