Last active
October 13, 2022 16:44
-
-
Save yoko57822/fb613eb5061b4ffefd0b12260eda2eee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEngine.UI; | |
using System.Text.RegularExpressions; | |
//This script should be specified as 'On Value Changed' of InputField. | |
public class InputFilter : MonoBehaviour | |
{ | |
[Header("Unity Setting")] | |
[Tooltip("Set Your InputField")] | |
[SerializeField] InputField _InputField; | |
[Range(1, 300)] | |
[Tooltip("InputField Text Limit")] | |
[SerializeField] int Text_Limit = 30; | |
[Header("Filter Setting")] | |
[Tooltip("Filtering Korean")] public bool Korean = false; | |
[Space(1.2f)] | |
[Tooltip("Filtering English")] public bool English = false; | |
[Space(1.2f)] | |
[Tooltip("Filtering Number")] public bool Number = false; | |
[System.Serializable] | |
public struct ETC | |
{ | |
[Tooltip("Yes.. Real Gap.")]public bool Not_Filter_Gap; | |
[Space(-2f)] | |
[Header("Korean Setting")] | |
public bool Not_Filter_JA; | |
[Tooltip("Not Filtering Korean Vowels(if ㅏ,ㅣ,ㅜ,ㅔ,ㅗ)")] | |
public bool Not_Filter_MO; | |
[Space(5f)] | |
[Header("English Setting")] | |
[Tooltip("Not Filtering Upper Case(if A,B,C)")] | |
public bool Filter_Upper; | |
[Tooltip("Not Filtering Lower Case(if a, b, c)")] | |
public bool Filter_Lower; | |
} | |
public ETC _ETC = new ETC(); | |
string Filter_Option = ""; | |
void Start() | |
{ | |
_InputField.characterLimit = Text_Limit; | |
Filter_Option_Check(); | |
} | |
void Filter_Option_Check() | |
{ | |
string K = "", E = "", N = "", G = ""; | |
if (!Korean) | |
if (_ETC.Not_Filter_JA && _ETC.Not_Filter_MO) | |
K = "가-힣ㄱ-ㅎㅏ-ㅣ"; | |
else if (_ETC.Not_Filter_JA) | |
K = "가-힣ㄱ-ㅎ"; | |
else if (_ETC.Not_Filter_MO) | |
K = "가-힣ㅏ-ㅣ"; | |
else | |
K = "가-힣"; | |
if (!English) | |
if (_ETC.Filter_Lower && _ETC.Filter_Upper) | |
{ | |
E = ""; | |
English = true; | |
} | |
else if (_ETC.Filter_Lower) | |
E = "A-Z"; | |
else if (_ETC.Filter_Upper) | |
E = "a-z"; | |
else | |
E = "a-zA-Z"; | |
if (!Number) | |
N = "0-9"; | |
if (_ETC.Not_Filter_Gap) | |
G = " "; | |
Filter_Option = "[^" + N + E + K + G + "]"; | |
} | |
public void Text_Filtering() | |
{ | |
Debug.Log("Filtering Warking"); | |
_InputField.onValueChanged.AddListener((word) => _InputField.text = Regex.Replace(word, @Filter_Option, "")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment