NGUI的UICamera

 
 
1. UICamera脚本需要挂接在所有的和UI有关的摄像机上,这样才能够有通知事件。
2. UICamera脚本实际做的事是发送NGUI事件给所有被它所附加的摄像机所看见的对象。除此之外,它不对UI做任何事情了。
3. 你能在场景里拥有多个UICamera脚本。大多游戏会有一个camera绘制挂件,另一个camera绘制游戏对象。
4. EventType 基于深度还是基于与摄像机的距离来排序事件
UICamera的第一个选项,Event Type决定了脚本怎样排列它下面鼠标和触摸事件的顺序。如果设置为UI模式,那么它将一直基于挂件的depth--就和绘制顺序一样。改变选项为World模式,只有在你添加UICamera到你的MainCamera上面的时候才应该这么做。这样做将通过点击到的对象到摄像机的距离排序。
5. Debug选项能用于调试当前鼠标下面是什么。如果当你点击一些按钮的时候,你不知道当前和鼠标事件交互的是什么对象,只要打开这个选项,你就能在顶部看到它。
6. EventMask定义了一些层级,只有该设置里允许的层级里的东西才能够接收到UICamera发送的NGUI事件通知。
 
实践
在MainCamera上添加UICamera脚本,设置debug开启,在场景中加入一个Cube并且具有collider(是否IsTrigger不关键),因为这个摄像机主要拍摄3D场景,所以设置为3Dworld。在UIRoot下的摄像机设置为UI(目的是让事件发送的先后以Depth为根据)。
7. 悬浮提示是否会有粘滞性
Stick Tooltip选项用于调整tooltip的行为。如果关闭,tooltip将会在鼠标再次移动的时候立刻隐藏。如果打开,tooltip将保持打开,知道鼠标离开同一个对象。 
8. 第二次以后附上的UICamera将会继承第一台主UICamera的其余属性
9. Tooltip  Delay控制鼠标悬停在某个对象上而且在OnTooltip通知发送到那个对象之前的时间间隔。这个值的单位是秒。
10. Raycast Range控制了射线的长度,大部分情况下这个值可以无视。这个值是使用世界单位的,所以如果你摄像机的near clip是0.3而far clipping是1000,你可能发现一些很远的对象没有响应点击,不妨设置这个值为2000试试(要比你camera的摄像机的far和near平面之差更大)。设置为-1表示无穷远。
11. 事件源可以设置鼠标、键盘、触摸事件。
12. Threshold中,鼠标拖拽的触发阈值。
 
13. 直接将这些事件写在物体(或UI)的脚本里,就可以在相对应的时机里触发它们。这些事件的完整目录见后面附录。
OnSelect(true) 发生在当鼠标首次点击某UI时。
OnDrag(delta)当该物体被拖拽时调用
OnDragOver(draggedObject)当该物体面前通过着另一个被拖拽物体时,调用
OnDragOut (draggedObject) 脱出时调用
OnTooltip (show) 长时间悬浮时调用
OnScroll (float delta) 鼠标滚轮滚动时调用
OnKey (KeyCode key) 按键时调用
 
 
 
 
——————————————————附录————————————————————————
/// <summary>
/// This script should be attached to each camera that's used to draw the objects with
/// UI components on them. This may mean only one camera (main camera or your UI camera),
/// or multiple cameras if you happen to have multiple viewports. Failing to attach this
/// script simply means that objects drawn by this camera won't receive UI notifications:
///
/// * OnHover (isOver) is sent when the mouse hovers over a collider or moves away.
/// * OnPress (isDown) is sent when a mouse button gets pressed on the collider.
/// * OnSelect (selected) is sent when a mouse button is first pressed on an object. Repeated presses won't result in an OnSelect(true).
/// * OnClick () is sent when a mouse is pressed and released on the same object.
///   UICamera.currentTouchID tells you which button was clicked.
/// * OnDoubleClick () is sent when the click happens twice within a fourth of a second.
///   UICamera.currentTouchID tells you which button was clicked.
///
/// * OnDragStart () is sent to a game object under the touch just before the OnDrag() notifications begin.
/// * OnDrag (delta) is sent to an object that's being dragged.
/// * OnDragOver (draggedObject) is sent to a game object when another object is dragged over its area.
/// * OnDragOut (draggedObject) is sent to a game object when another object is dragged out of its area.
/// * OnDragEnd () is sent to a dragged object when the drag event finishes.
///
/// * OnTooltip (show) is sent when the mouse hovers over a collider for some time without moving.
/// * OnScroll (float delta) is sent out when the mouse scroll wheel is moved.
/// * OnKey (KeyCode key) is sent when keyboard or controller input is used.
/// </summary>
 
 
原文地址:https://www.cnblogs.com/JackSamuel/p/9591858.html