This commit is contained in:
Sahik committed 2026-09-14 22:42:35 +08:00
1 parent d3aff16344
commit 74bf542515
20 files changed
+1416 -166

No files matched your search

@@ -0,0 +1,42 @@
using UnityEngine;
using TMPro;
public class AssistIntro : MonoBehaviour
{
[Header("UI 參照")]
[Tooltip("Dropdown")]
public TMP_Dropdown assistDropdown;
[Tooltip("Text (TMP)")]
public TextMeshProUGUI introDisplayText;
private readonly string[] intros = new string[]
{
" 不使用任何瞄準輔助,使用你最純粹的反應力與控制力瞄準。如果可以的話,無輔助與有輔助的測試次數請盡量控制在 1 : 1。",
" 依照敵方在螢幕上的座標,直接移動準心以實現瞄準。輔助強度為移動量,如設定 100% 會形成暴力鎖。",
" 依照敵方在螢幕上與你準心的距離,動態更改你的靈敏度(接近敵方時降低靈敏度)以吸附準心。輔助強度為靈敏度降低程度。"
};
void Start()
{
if (assistDropdown != null)
{
UpdateIntro(assistDropdown.value);
assistDropdown.onValueChanged.AddListener(OnDropdownChanged);
}
}
void OnDropdownChanged(int index)
{
UpdateIntro(index);
}
void UpdateIntro(int index)
{
if (introDisplayText != null && index >= 0 && index < intros.Length)
{
introDisplayText.text = intros[index];
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: eb773ea3cff4cd3458860b9d3eab1303
@@ -0,0 +1,45 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class AssistStrength : MonoBehaviour
{
[Header("UI 參照")]
[Tooltip("Slider")]
public Slider targetSlider;
[Tooltip("Text (TMP)")]
public TextMeshProUGUI valueDisplayText;
void Start()
{
if (targetSlider != null)
{
// 設定拉桿的屬性
targetSlider.minValue = 1f;
targetSlider.maxValue = 100f;
targetSlider.wholeNumbers = true; // 每 1 一個階梯,使用整數
// 初始化顯示
UpdateDisplayText(targetSlider.value);
// 註冊拉桿數值改變事件
targetSlider.onValueChanged.AddListener(OnSliderValueChanged);
}
}
void OnSliderValueChanged(float rawValue)
{
int steppedValue = Mathf.RoundToInt(rawValue);
UpdateDisplayText(steppedValue);
}
void UpdateDisplayText(float val)
{
if (valueDisplayText != null)
{
int intVal = Mathf.RoundToInt(val);
valueDisplayText.text = $"輔助強度 : {intVal}%";
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e5ffef45c6a94f543a4f4bb8b1ed2f48
@@ -0,0 +1,41 @@
using UnityEngine;
using TMPro;
using UnityEngine.InputSystem;
public class Movement : MonoBehaviour
{
[Header("UI 參照")]
[Tooltip("Text (TMP)")]
public TextMeshProUGUI movementVectorText;
private Vector2 smoothedDelta = Vector2.zero;
private const float alpha = 0.1f; // 數值越大 越貼最新數值
void Update()
{
if (Mouse.current != null)
{
Vector2 currentDelta = Mouse.current.delta.ReadValue();
if (smoothedDelta == Vector2.zero)
{
smoothedDelta = currentDelta;
}
else
{
smoothedDelta = (alpha * currentDelta) + ((1.0f - alpha) * smoothedDelta);
}
}
else
{
smoothedDelta = Vector2.zero;
}
if (movementVectorText != null)
{
string xStr = (smoothedDelta.x >= 0 ? "+" : "") + smoothedDelta.x.ToString("F1");
string yStr = (smoothedDelta.y >= 0 ? "+" : "") + smoothedDelta.y.ToString("F1");
movementVectorText.text = $"移動向量: X: {xStr}, Y: {yStr}";
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0baddb7dc6fc5184997d41c4fe35bb25
@@ -0,0 +1,180 @@
using UnityEngine;
using TMPro;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Collections.Generic;
public class Polling : MonoBehaviour
{
[Header("UI 參照")]
[Tooltip("Text (TMP) ")]
public TextMeshProUGUI pollingDisplay;
private const int WH_MOUSE_LL = 14;
private const int WM_MOUSEMOVE = 0x0200;
private delegate IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam);
private static LowLevelMouseProc _proc;
private static IntPtr _hookID = IntPtr.Zero;
private static Stopwatch stopwatch = new Stopwatch();
private static long lastTicks = 0;
private static List<double> intervals = new List<double>();
private static readonly object lockObj = new object();
// EMA
private double smoothedMs = 0;
private const double alpha = 0.25;
// 無動作計時
private List<int> recentRates = new List<int>();
private float timeSinceLastEvent = 0f;
private const float idleTimeout = 2f; // 超過 2 秒沒動就歸零
void OnEnable()
{
stopwatch.Start();
_proc = HookCallback;
_hookID = SetHook(_proc);
}
void OnDisable()
{
UnhookWindowsHookEx(_hookID);
}
private IntPtr SetHook(LowLevelMouseProc proc)
{
using (Process curProcess = Process.GetCurrentProcess())
using (ProcessModule curModule = curProcess.MainModule)
{
return SetWindowsHookEx(WH_MOUSE_LL, proc, GetModuleHandle(curModule.ModuleName), 0);
}
}
private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
{
if (nCode >= 0 && wParam == (IntPtr)WM_MOUSEMOVE)
{
long currentTicks = stopwatch.ElapsedTicks;
if (lastTicks != 0)
{
double ms = (double)(currentTicks - lastTicks) / Stopwatch.Frequency * 1000.0;
lock (lockObj)
{
if (ms > 0.001 && ms < 100.0)
{
intervals.Add(ms);
}
}
}
lastTicks = currentTicks;
}
return CallNextHookEx(_hookID, nCode, wParam, lParam);
}
void Update()
{
List<double> currentBatch;
lock (lockObj)
{
currentBatch = new List<double>(intervals);
intervals.Clear();
}
if (currentBatch.Count > 0)
{
timeSinceLastEvent = 0f;
double sum = 0;
foreach (var val in currentBatch) sum += val;
double batchAvgMs = sum / currentBatch.Count;
if (smoothedMs == 0)
{
smoothedMs = batchAvgMs;
}
else
{
smoothedMs = (alpha * batchAvgMs) + ((1.0 - alpha) * smoothedMs);
}
if (smoothedMs > 0)
{
double rawHz = 1000.0 / smoothedMs;
int standardHz = SnapToStandardPollingRate(rawHz);
recentRates.Add(standardHz);
}
}
else
{
timeSinceLastEvent += Time.unscaledDeltaTime;
}
if (timeSinceLastEvent >= idleTimeout)
{
recentRates.Clear();
smoothedMs = 0;
}
// 更新 UI
if (pollingDisplay != null)
{
if (recentRates.Count > 0)
{
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);
}
}
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)
{
minDifference = diff;
closestRate = rate;
}
}
return closestRate;
}
#region Win32 API 匯入
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr SetWindowsHookEx(int idHook, LowLevelMouseProc lpfn, IntPtr hMod, uint dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool UnhookWindowsHookEx(IntPtr hk);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr CallNextHookEx(IntPtr hk, int nCode, IntPtr wParam, IntPtr lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr GetModuleHandle(string lpModuleName);
#endregion
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: dbfae505c051b8241a378b2712dd7b5d
@@ -1,71 +0,0 @@
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
using System.Collections.Generic;
public class MouseTrailLogger : MonoBehaviour
{
// 定義單筆數據結構:包含時間戳記與當下的微小位移量
[System.Serializable]
public struct MouseSample
{
public double timestamp; // 作業系統級別的時間戳記(秒,可換算為 ms)
public Vector2 delta; // 該瞬間的滑鼠位移量 (Delta)
}
private List<MouseSample> recordedSamples = new List<MouseSample>();
private bool isRecording = false;
void OnEnable()
{
// 註冊 Input System 的底層事件攔截器
InputSystem.onEvent += OnDataEvent;
}
void OnDisable()
{
// 記得取消註冊,避免記憶體洩漏
InputSystem.onEvent -= OnDataEvent;
}
public void StartRecording()
{
recordedSamples.Clear();
isRecording = true;
}
public void StopRecording()
{
isRecording = false;
// 這裡可以把 recordedSamples 序列化成 JSON 準備上傳到 GitHub 或後端
}
private void OnDataEvent(InputEventPtr eventPtr, InputDevice device)
{
if (!isRecording) return;
// 檢查這個事件是否由「滑鼠」發出,且是否包含狀態更新
if (device is Mouse mouse)
{
// 判斷事件類型是否為滑鼠動態 (State Event)
if (eventPtr.IsA<StateEvent>() || eventPtr.IsA<DeltaStateEvent>())
{
// 取得該事件發生時作業系統的高精度時間戳記 (Unscaled Time)
double eventTime = eventPtr.time;
// 讀取當下的滑鼠位移量
Vector2 mouseDelta = mouse.delta.ReadValue();
// 只有當滑鼠真有移動時才記錄,避免無效資料浪費記憶體
if (mouseDelta != Vector2.zero)
{
recordedSamples.Add(new MouseSample
{
timestamp = eventTime,
delta = mouseDelta
});
}
}
}
}
}
@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 20bda67a74291514cac9cd232e2093ee
@@ -0,0 +1,42 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Sensitivity : MonoBehaviour
{
[Header("UI 參照")]
[Tooltip("Slider")]
public Slider targetSlider;
[Tooltip("Text (TMP)")]
public TextMeshProUGUI valueDisplayText;
void Start()
{
if (targetSlider != null)
{
targetSlider.minValue = 0.1f;
targetSlider.maxValue = 10.0f;
targetSlider.wholeNumbers = false;
UpdateDisplayText(targetSlider.value);
targetSlider.onValueChanged.AddListener(OnSliderValueChanged);
}
}
void OnSliderValueChanged(float rawValue)
{
float steppedValue = Mathf.Round(rawValue * 10f) / 10f;
UpdateDisplayText(steppedValue);
}
void UpdateDisplayText(float val)
{
if (valueDisplayText != null)
{
valueDisplayText.text = $"靈敏度 : {val:F1}";
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0c0bf45cb5cebd14190d7c1e7ec7f6d7