using System; using System.Collections; using System.Collections.Generic; using System.Globalization; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { [RequireComponent(typeof(InputField))] public class InputSpecialWordLimit : MonoBehaviour { [SerializeField, Header("是否限制空格")] bool m_SpaceLimit = false; private void Awake() { var _input = GetComponent(); _input.onValidateInput = OnValidateInput; } private char OnValidateInput(string text, int charIndex, char addedChar) { DebugEx.Log(char.GetUnicodeCategory(addedChar)); if (char.GetUnicodeCategory(addedChar) == UnicodeCategory.Surrogate || char.GetUnicodeCategory(addedChar) == UnicodeCategory.OtherSymbol || char.GetUnicodeCategory(addedChar) == UnicodeCategory.OtherNumber || char.GetUnicodeCategory(addedChar) == UnicodeCategory.MathSymbol || char.GetUnicodeCategory(addedChar) == UnicodeCategory.OtherNotAssigned || addedChar == '\n' || (m_SpaceLimit && (addedChar == ' ') || (addedChar == ' '))) { return (char)0; } return addedChar; } } }