NGUI 官网地址 : http://www.tasharen.com/forum/index.php?board=12.0
NGUI的插件可以单独QQ[3156593446]我,或者自行baidu下载。
UICamera
Event Type :
官网描述:
The first option on the UICamera,
Event Type
is what determines how the script sorts whats underneath the mouse and touch events. If it's set to
UI
mode, then it's always based on widget's depth -- just like the draw order. Changing this option to
World
mode is something you should do if your UICamera is attached to your Main Camera. Doing so will sort the hit objects by their distance to the camera.
UICamera的第一个参数, 事件类型决定了脚本如何对鼠标和触屏事件进行排序, 如果设置成ui模式, 那么他们处理事件的方式是根据组件的深度, 就好比回执顺序一样。 如果改成world模式,那么则会根据距离朱摄像机的远近来进行排序。
3D UI vs 2D UI : 碰撞器是用3D的,还是2D的
3D UI vs 3D World : 3D UI 是通过camera的深度depth来计算, 3D World是通过距离摄像机的深远来操作。
Event Mask:
官网描述
Event Mask
is what determines which game object layers will be capable of receiving events. In most cases you can leave this on "Everything", as this value is combined with the UnityEngine.Camera's Culling Mask, but you can fine-tune it if you wish. If you ever change the
Layer
of your game object containing the UI hierarchy,
make sure to adjust the Event Mask
or you will suddenly find your UI no longer responding to events.
Event Mask 用来决定哪个游戏对象层级将会接受事件。
Debug
官网描述
Debug
option can be used to debug what's currently under the mouse. If you can't figure out what's intercepting mouse events when you click on some button, just turn on this option and you will be able to see it in the top-right corner.
可以帮你定位当前hover和select的是哪个游戏对象
UIEventListener : 用来接收uicamera分发的代理接口。里面包含了很多的代理接口,例如onclick, onhover,onpress.....
UICamera UIEventListener事件处理的核心原理 :
uicamera 调用raycast 发出射线检测和获取发出事件的游戏对象,然后通过sendmessage分发onclick事件,然后通过uieventlistener监听接收onclick的委托事件,委托事件如果注册,则执行注册的委托事件吗,如果没有注册,那么什么都不做。
举例 :
uicamera:Notify
uicamera:set_hoveredObject
uicamera.processmouse
uicamera.processtouches
uicamera.update
go是被点中的游戏对象,在他上面挂接了脚本UIEventListener。OnClick就在这个脚本中,OnClick是一个代理接口,在程序初始化的时候已经对代理接口进行了初始化,那么当事件分发到UIEventListener的OnClick的时候,程序会直接调用OnClick的代理接口