This commit is contained in:
Sahik committed 2026-09-08 23:12:06 +08:00
1 parent 53376447b8
commit 42d9b216cc
8 files changed
+215 -5

No files matched your search

@@ -0,0 +1,54 @@
using UnityEngine;
using TMPro;
public class IDManager : MonoBehaviour
{
[Header("UI 參照")]
public TMP_InputField inputField;
public TextMeshProUGUI modeStatusText;
private const int MaxLength = 12;
void Start()
{
if (inputField != null)
{
inputField.characterLimit = MaxLength;
inputField.onValueChanged.AddListener(OnIDChanged);
OnIDChanged(inputField.text);
}
}
void OnIDChanged(string currentText)
{
if (currentText.Length > MaxLength)
{
currentText = currentText.Substring(0, MaxLength);
inputField.text = currentText;
}
if (string.IsNullOrEmpty(currentText.Trim()))
{
if (modeStatusText != null)
{
modeStatusText.text = "匿名模式";
}
}
else
{
if (modeStatusText != null)
{
modeStatusText.text = "具名模式 : " + currentText;
}
}
}
public string GetFinalContributorID()
{
string text = inputField.text.Trim();
if (string.IsNullOrEmpty(text))
{
return "Anonymous";
}
return text;
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: d001489e65da58842bfcddcb83db1c54
@@ -0,0 +1,71 @@
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
});
}
}
}
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 20bda67a74291514cac9cd232e2093ee
@@ -0,0 +1,37 @@
using UnityEngine;
using TMPro;
public class ResolutionDisplay : MonoBehaviour
{
[Header("UI 參照")]
public TextMeshProUGUI resolutionText;
private int lastWidth = 0;
private int lastHeight = 0;
void Update()
{
int currentWidth = Screen.width;
int currentHeight = Screen.height;
if (currentWidth != lastWidth || currentHeight != lastHeight)
{
lastWidth = currentWidth;
lastHeight = currentHeight;
UpdateResolutionText(currentWidth, currentHeight);
}
}
void UpdateResolutionText(int w, int h)
{
if (resolutionText == null) return;
int refreshRate = 60;
if (Screen.currentResolution.refreshRateRatio.value > 0)
{
refreshRate = Mathf.RoundToInt((float)Screen.currentResolution.refreshRateRatio.value);
}
resolutionText.text = $"解析度 : {w}*{h}*{refreshRate}hz";
}
}
@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: dde79346c17b5f2459fc8a237791b65b