unity3d 5 InputField 불법 경로 파일 이름 문자 입력 필터
3142 단어 unity3d여과파일 경로불법 문자InputField
void Start() {
if (this.Button == null) {
this.Button = this.GetComponentInChildren<UI_ButtonClick>();
}
if (this.InputText == null) {
this.InputText = this.GetComponentInChildren<InputField>();
}
this.Button.OnClickEvent += Button_OnClickEvent;
this.InputText.onValidateInput = _OnValidateInput;
this.InputText.onEndEdit.AddListener(input_OnEndEdit);
}
char _OnValidateInput(string text, int charIndex, char addedChar) {
if (!_isValidChar(addedChar)) return '\0';//
return addedChar;
}
//
private bool _isValidChar(char addedChar) {
//char[] invalid1 =System.IO.Path.GetInvalidFileNameChars();
//for (int i = 0; i < invalid1.Length; i++) {
// if (invalid1[i] == addedChar) {
// return false;
// }
//}
//char[] invalid2=System.IO.Path.GetInvalidPathChars();
//for (int i = 0; i < invalid2.Length; i++) {
// if (invalid2[i] == addedChar) {
// return false;
// }
//}
for (int i = 0; i < InvalidFilePathNameChars.Length; i++) {
if (((int)addedChar) == (int)InvalidFilePathNameChars[i]) {
return false;
}
}
for (int i = 0; i < InvalidCustomChars.Length; i++) {
if (addedChar == InvalidCustomChars[i]) {
return false;
}
}
return true;
}
/// <summary>
/// char
/// GetInvalidFileNameChars(),GetInvalidPathChars()
/// </summary>
private static readonly byte[] InvalidFilePathNameChars = new byte[]{
34,60,62,124,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,
21,22,23,24,25,26,27,28,29,30,31,58,42,63,92,47
};
/// <summary>
///
/// </summary>
private static readonly char[] InvalidCustomChars = new char[]{
'\'','"','~','`','!','@','#','$','%','^','&','*','(',')','+','=','>','<',
'|','{','}','/','\\',':',';',',','?'
};
/// <summary>
/// Unicode
/// </summary>
/// <param name="code"> Unicode</param>
/// <returns></returns>
protected static bool IsChineseLetter(int code) {
int chfrom = System.Convert.ToInt32("4e00", 16); // (0x4e00~0x9fff) int(chfrom~chend)
int chend = System.Convert.ToInt32("9fff", 16);
if (code >= chfrom && code <= chend) {
return true; // code true
}
else {
return false; // code false
}
return false;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Unity용 VLC 소개 - Android 에디션숙련된 Unity 개발자는 유명한 Big Buck Bunny 비디오를 재생하는 VLC 플러그인을 보여주기 위해 편집된 유명한 Unity 장면 을 인식할 것입니다. 이 Unity 플러그인을 사용하면 Unity 기반 A...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.