NGUI 使用EventDelegate.Add与UIInput.onSubmit、UIInput.onChange限定编辑框中的内容
2020-02-17 00:43
447 查看
Unity中,使用NGUI,通常为某个控件(如按钮)绑定事件(单击、双击、拖拽、滚轮、选择等)都是用UIEventListener,比如:
1 public void Bind() 2 { 3 UIEventListener.Get(clickButton.gameObject).onClick = OnClick; 4 } 5 6 void OnClickButton(GameObjcect go) 7 { 8 }
前阵子有个需求,需要用户单击编辑框显示手机输入法之后,在输入数字中,不能输入超过5000的值且不小于1的值,如果只是限制类型的话,那么单单使用UIInput就可以了,但限制值的大小,我就没看到UIInput组件在Unity编辑器中有相应的属性可以设置!
这个时候就可以用EventDelegate.Add,与UIInput.onChange或者UIInput.onSubmit组合,如果使用UIInput.OnChange的话,比如:
1 EventDelegate.Add(xInput.onSubmit, OnSubmitX); 2 3 void OnSubmitX() 4 { 5 string inputString = mXLabel.text;//xInput组件在mXLabel中 6 //非空判断 7 //... 8 9 int x = Convert.ToInt32(inputString); 10 if (x < 1) 11 //...做其他相关的事情 12 x = 1; 13 if (x > 5000) 14 //...做其他相关的事情 15 x = 5000; 16 mXLabel.text = x.tostring(); 17 }
就可以在用户提交该输入结果后,在OnSubmitX函数里获取到该输入结果,然后进行判断,大于或小于限定的值就将其设置为最小或者最大值!然后才提交到UILabel中进行显示
当然也可以使用UIInput.onChange!具体方法都差不多!
转载于:https://www.cnblogs.com/AlphaAI/p/4139970.html
- 点赞
- 收藏
- 分享
- 文章举报
相关文章推荐
- NGUI 灰化按钮或图标
- (1366, "Incorrect string value: '\\xE5\\x93\\x88\\xE5\\x93\\x88' for column 'body' at row 1")
- 利用selenuim自动登录csdn
- 让JPA 飞 - QueryDSL
- The cast to value type 'System.Decimal' failed because the materialized value is null. Either the re...
- [Form builder]:about SYSTEM.MESSAGE_LEVEL
- [Form Builder]:CREATE_GROUP Built-in
- [Form Builder]APP_ITEM_PROPERTY.SET_PROPERTY 用法
- [Form Builder]NAME_IN()与COPY()
- [Form Builer]Locking Mode and LOCK_RECORD
- [Form Builder]内置函数execute_trigger、do_key详解
- torque脚本编程
- easyui局部刷新
- element-ui 使用时遇到的一些坑
- 使用Microsoft BizTalk Adapter for mySAP Business Suite需要注意的一些限制点
- material-UI库:mat-error校验失效
- Application(basic)----Easyui
- application(expand)--easyui
- portal---easyui
- 2019牛客暑期多校训练营(第一场)A Equivalent Prefixes (单调栈)