NGUI的UIINPUT脚本怎么输入中文 NGUI的UIINPUT脚本怎么输入中文

NGUI\uff0cinput\u811a\u672c\u4e0d\u53ef\u4ee5\u8f93\u5165\u4e2d\u6587\u5417

\u4e3b\u8981\u901a\u8fc7\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u5229\u7528unicode\u8fdb\u884c\u89c4\u5219\u5339\u914d\u3002 1\u3001\u8868\u793a\u4e2d\u6587\u7684unicode\u8303\u56f4\u503c:[\u4e00-\u9fa5] 2\u3001\u5b57\u6bcd\u8303\u56f4\u6b63\u5219\u8868\u8fbe\u5f0f[A-Za-z] 3\u3001\u5c062\u4e2a\u6761\u4ef6\u540c\u65f6\u5224\u65ad\uff0c\u90fd\u4e0d\u6ee1\u8db3\u8fd9\u4e2a\u8303\u56f4\u624d\u80fd\u8f93\u5165\u3002 \u793a\u4f8b\uff1a \u6709\u5982\u4e0b\u6587\u672c\u6846\uff1a \u53ef\u4ee5\u7528\u5982\u4e0b\u65b9\u6cd5\u68c0\u6d4b\uff1a function checkTe...

TouchScreenKeyboard\u53ea\u80fd\u7528\u4e8e\u79fb\u52a8\u5e73\u53f0\u3002\u5176\u4ed6\u5e73\u53f0\u7684\u8bdd\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528OnInput\u4e8b\u4ef6\u6765\u5904\u7406\u88ab\u8f93\u5165\u7684\u6587\u5b57\uff0c\u7136\u540e\u5ffd\u7565\u6389\u975e\u6570\u5b57\u7684\u90a3\u4e9b\u3002\u6211\u7528\u7684NGUI\u8fd8\u6ca1\u6709UIInput.Type\u7684\u5c5e\u6027\u3002

可以用组件UIInputValidator达到预期效果,不过为了支持汉字输入,需做一定的修改
修改UIInpurtValidator的代码如下:
首先是在枚举Validation里添加一种过滤规则
[csharp] view plain copy
在CODE上查看代码片派生到我的代码片
public enum Validation
{
<span style="white-space:pre"> </span>None,
Integer,
Float,
Alphanumeric,
Username,
Name,
<span style="color:#ff0000">Chinese,//这个是新添加的</span>
}
然后修改Validate方法如下
[csharp] view plain copy
在CODE上查看代码片派生到我的代码片
char Validate (string text, char ch)
{
// Validation is disabled
if (logic == Validation.None || !enabled) return ch;
<span style="color:#ff0000">if (logic == Validation.Chinese){
if (ch>=0x4e00 && ch<=0x9fa5) return ch;//这个主要是汉字的范围
if (ch >= 'A' && ch <= 'Z') return ch;
if (ch >= 'a' && ch <= 'z') return ch;
if (ch >= '0' && ch <= '9') return ch;
}
else</span> if (logic == Validation.Integer)
{
// Integer number validation
if (ch >= '0' && ch <= '9') return ch;
if (ch == '-' && text.Length == 0) return ch;
}
else if (logic == Validation.Float)
{
// Floating-point number
if (ch >= '0' && ch <= '9') return ch;
if (ch == '-' && text.Length == 0) return ch;
if (ch == '.' && !text.Contains(".")) return ch;
}
else if (logic == Validation.Alphanumeric)
{
// All alphanumeric characters
if (ch >= 'A' && ch <= 'Z') return ch;
if (ch >= 'a' && ch <= 'z') return ch;
if (ch >= '0' && ch <= '9') return ch;
}
else if (logic == Validation.Username)
{
// Lowercase and numbers
if (ch >= 'A' && ch <= 'Z') return (char)(ch - 'A' + 'a');
if (ch >= 'a' && ch <= 'z') return ch;
if (ch >= '0' && ch <= '9') return ch;
}
else if (logic == Validation.Name)
{
char lastChar = (text.Length > 0) ? text[text.Length - 1] : ' ';
if (ch >= 'a' && ch <= 'z')
{
// Space followed by a letter -- make sure it's capitalized
if (lastChar == ' ') return (char)(ch - 'a' + 'A');
return ch;
}
else if (ch >= 'A' && ch <= 'Z')
{
// Uppercase letters are only allowed after spaces (and apostrophes)
if (lastChar != ' ' && lastChar != '\'') return (char)(ch - 'A' + 'a');
return ch;
}
else if (ch == '\'')
{
// Don't allow more than one apostrophe
if (lastChar != ' ' && lastChar != '\'' && !text.Contains("'")) return ch;
}
else if (ch == ' ')
{
// Don't allow more than one space in a row
if (lastChar != ' ' && lastChar != '\'') return ch;
}
}
return (char)0;
}
红色部分为新添加的代码,这样子就可以在u3d编辑器里设置logic的值为Chinese就可以了
如果有需求需要允许一些特殊字符,直接修改Validate方法就可以了

NGUI的UIINPUT脚本怎么输入中文
 TouchScreenKeyboard只能用于移动平台。其他平台的话,你可以使用OnInput事件来处理被输入的文字,然后忽略掉非数字的那些。我用的NGUI还没有UIInput.Type的属性。

扩展阅读:penguin牌子包 ... native ui vue3 ... plague inc内购破解版 ... paperpass免费入口 ... mac蜜桃奶茶314 ... abode flash player ... plague1.18破解版 ... plague inc evolved ... plague解药汉化破解版 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网