Files
Cielonos/Assets/Scripts/Settings/UI/SettingsEntryIntInput.cs
SoulliesOfficial 6d7ebc5825 Passion & UI
2026-06-12 17:11:39 -04:00

46 lines
1.2 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using TMPro;
using UnityEngine;
namespace Cielonos.Settings.UI
{
/// <summary>
/// 不带 [Range] 特性的 int 字段的设置条目 — 使用 TMP_InputField整数模式
/// </summary>
public class SettingsEntryIntInput : SettingsEntryBase
{
[SerializeField] private TMP_InputField inputField;
protected override void SetupUI()
{
if (inputField == null) return;
inputField.contentType = TMP_InputField.ContentType.IntegerNumber;
inputField.onEndEdit.AddListener(OnInputEndEdit);
}
public override void RefreshValue()
{
if (inputField != null)
inputField.SetTextWithoutNotify(GetFieldValue().ToString());
}
private void OnInputEndEdit(string text)
{
if (int.TryParse(text, out int value))
{
SetFieldValue(value);
}
else
{
RefreshValue();
}
}
private void OnDestroy()
{
if (inputField != null)
inputField.onEndEdit.RemoveListener(OnInputEndEdit);
}
}
}