This commit is contained in:
Sahik committed 2026-10-27 16:51:24 +08:00
1 parent 9f928d391a
commit 48290de35e
13 files changed
+158 -58

No files matched your search

@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: aeeadfd0421657043b047d23f2112940
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 19f3b9a0980eb604497d2db8c8e4ea0e
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 794ee5cb61c74864fa0ba7639fed2e73
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 718863dcff53b784aa0ffc114381cdd7
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 518d1c1a2372e38479ca8a25bc9b0ee8
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 0aab1b18335e60849a9f0e022e548980
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+2 -2
View File
@@ -323,8 +323,8 @@ MonoBehaviour:
m_EditorClassIdentifier: Assembly-CSharp::AimAssist
perceptor: {fileID: 3127315678899527277}
playerLook: {fileID: 879551139689297706}
minFov: 5
maxFov: 30
minFov: 15
maxFov: 15
trackSpeed: {x: 2, y: 30}
--- !u!114 &132788102679742450
MonoBehaviour:
@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: 58f7e79a87c79824597746e8c1bfe400
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -1,7 +0,0 @@
fileFormatVersion: 2
guid: f58d25b9e504a4f41ab4a71cf87c1845
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
+105
View File
@@ -0,0 +1,105 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.LowLevel;
// Unity 內建輸入 vs Raw Input 對照工具 (開發用,不要放進正式場景)
// 同一段滑鼠移動,同時用兩條路徑收事件 : Unity Input System 的逐筆事件 (eventPtr.time) 與 RawMouseInput (QPC 時間戳)
// 掛在 Test 場景的任一物件上,移動滑鼠幾秒後按 F10,桌面會出現 unity_probe.csv 與 raw_probe.csv,給 Tools/plot_input_histogram.py 畫圖 3.4
public class InputCompareProbe : MonoBehaviour
{
[Tooltip("按 F10 存檔時保留最近幾秒")]
public float keepSeconds = 10f;
private struct Ev { public double t; public float dx, dy; }
private readonly List<Ev> unityHistory = new List<Ev>();
private readonly List<Ev> rawHistory = new List<Ev>();
private int unityThisSecond, rawThisSecond, unityPerSecond, rawPerSecond;
private float secondTimer;
private string saveMessage = "";
void OnEnable()
{
// 預設 Input System 會把同一幀內的滑鼠事件合併成一筆,關掉才拿得到每一筆
InputSystem.settings.disableRedundantEventsMerging = true;
InputSystem.onEvent += OnInputEvent;
}
void OnDisable()
{
InputSystem.onEvent -= OnInputEvent;
}
void OnInputEvent(InputEventPtr eventPtr, InputDevice device)
{
if (!eventPtr.IsA<StateEvent>() && !eventPtr.IsA<DeltaStateEvent>()) return;
if (!(device is Mouse mouse)) return;
if (!mouse.delta.ReadValueFromEvent(eventPtr, out Vector2 delta)) return;
if (delta == Vector2.zero) return; // 只算有位移的回報,跟 Raw Input 一樣
unityHistory.Add(new Ev { t = eventPtr.time, dx = delta.x, dy = delta.y });
unityThisSecond++;
}
void Update()
{
foreach (RawMouseInput.Event e in RawMouseInput.FrameEvents)
{
rawHistory.Add(new Ev { t = e.t, dx = e.dx, dy = e.dy });
rawThisSecond++;
}
double cut = Time.realtimeSinceStartupAsDouble - keepSeconds;
Trim(unityHistory, cut);
Trim(rawHistory, cut);
secondTimer += Time.unscaledDeltaTime;
if (secondTimer >= 1f)
{
unityPerSecond = unityThisSecond; rawPerSecond = rawThisSecond;
unityThisSecond = rawThisSecond = 0; secondTimer = 0f;
}
if (Keyboard.current != null && Keyboard.current.f10Key.wasPressedThisFrame) Save();
}
static void Trim(List<Ev> list, double cut)
{
int remove = 0;
while (remove < list.Count && list[remove].t < cut) remove++;
if (remove > 0) list.RemoveRange(0, remove);
}
void Save()
{
string desktop = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop);
Write(Path.Combine(desktop, "unity_probe.csv"), unityHistory);
Write(Path.Combine(desktop, "raw_probe.csv"), rawHistory);
saveMessage = $"已存 Unity {unityHistory.Count} 筆、Raw {rawHistory.Count} 筆到桌面";
}
static void Write(string path, List<Ev> list)
{
StringBuilder sb = new StringBuilder("t,dx,dy\n");
foreach (Ev e in list)
{
sb.Append(e.t.ToString("F6", CultureInfo.InvariantCulture)).Append(',')
.Append(e.dx.ToString(CultureInfo.InvariantCulture)).Append(',')
.Append(e.dy.ToString(CultureInfo.InvariantCulture)).Append('\n');
}
File.WriteAllText(path, sb.ToString());
}
void OnGUI()
{
float y = Screen.height - 80;
GUI.Box(new Rect(10, y - 5, 640, 80), "");
GUI.Label(new Rect(20, y, 620, 22), $"Unity Input System : {unityPerSecond} 筆/秒 Raw Input : {rawPerSecond} 筆/秒 ({RawMouseInput.Status})");
GUI.Label(new Rect(20, y + 20, 620, 22), $"保留最近 {keepSeconds:F0} 秒 : Unity {unityHistory.Count} 筆、Raw {rawHistory.Count} 筆");
GUI.Label(new Rect(20, y + 40, 620, 22), string.IsNullOrEmpty(saveMessage) ? "移動滑鼠幾秒後按 F10 存到桌面 (unity_probe.csv / raw_probe.csv)" : saveMessage);
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 8295b3ab5b13e99469d2aa0dda56b5f9