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() : ""; } }