看了UICamera的源码就显而易见了:

UICamera
« on: November 21, 2013, 12:21:48 AM »

Overview

UICamera is a somewhat poorly named component. In fact, its name is kept only for backwards compatibility purposes.

What the UICamera script actually does is sends out NGUI events to all the objects seen by the camera it's attached to. It doesn't have to have anything to do with UI though. In fact, if you wish to receive NGUI events on your in-game objects such as OnPress, OnClick, OnDrag etc, then all you need to do is attach the UICamera script to your main camera.

You can have several UICamera scripts in the scene. Most games will have one on the camera that draws the widgets, and another on the camera that draws the game.

NOTE: For UICamera to work, "Raycasts Hit Triggers" (基于射线碰撞测试,可以理解为什么需要box colider了)must be checked in the Physics settings.

   

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.

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.

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.

Allow Multi-Touch option controls whether multiple touches will be supported. If turned off, multiple touches will all be treated as a single touch.

Sticky Tooltip option fine-tunes the tooltip behaviour. If off, the tooltip will hide as soon as the mouse moves again. If on, the tooltip will remain open while the mouse is over the same object.

Tooltip Delay controls the delay between the mouse stopping movement over some object and the OnTooltip notification being sent to that object. This value is in seconds.

Raycast Range controls the length of the raycast, and in most cases this value can be safely ignored. This value is in world units, so if your camera has the near clip of 0.3 and far clipping of 1000, you and you are finding that some far-away objects are not responding to clicks, set this value to something like 2000 (something greater than the difference between your camera's far and near clipping planes).

Event Sources section controls what kind of event types will be processed. If one of the options is turned off, those events will no longer be processed. Some platforms force-disable specific events under the hood. For example targeting consoles will automatically turn off mouse and touch events.

Thresholds section lets you fine-tune how the mouse and touch events behave by tweaking the thresholds of click, drag and tap events. These values are in pixels.

Axes and Keys section lets you choose which axes result in which movement. These axes should match the names in your project's Input Manager.

Pro-Tip #1

UICamera sends out the following events to colliders:

  • 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 a game object. Repeated presses on the same object won't result in a new OnSelect.
  • OnClick () is sent with the same conditions as OnSelect, with the added check to see if the mouse has not moved much. 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.
  • OnInput (text) is sent when typing (after selecting a collider by clicking on it).
  • 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.

转载于:https://www.cnblogs.com/wonderKK/p/3931902.html

UICamera(NGUI Event system)原理相关推荐

  1. The Event System

    The Event System 在Qt中,事件是继承了虚拟类QEvent的对象,它代表了程序所发生的事情或者程序需要知道的一个外部活动的结果.事件可以被任意 QObject子类的实例接收和处理,是与 ...

  2. 3dsmax Node Event System

    Node Event System 3dsmax 节点事件系统 https://help.autodesk.com/view/MAXDEV/2022/ENU/?guid=GUID-7C91D285-5 ...

  3. A Type-Safe Event System for Unity3D

    转载自:http://www.willrmiller.com/?p=87 The Event Listener pattern is an extremely common design patter ...

  4. Qt事件体系概述(The Event System)

    本文译自https://doc.qt.io/qt-5/eventsandfilters.html,是意译. 目录 事件的发送(How Events are delivered) 事件类型(Event ...

  5. Node.js的事件轮询Event Loop原理解释

    事件轮询主要是针对事件队列进行轮询,事件生产者将事件排队放入队列中,队列另外一端有一个线程称为事件消费者会不断查询队列中是否有事件,如果有事件,就立即会执行,为了防止执行过程中有堵塞操作影响当前线程读 ...

  6. SAP UI5 subscribe event实现原理

    Created by Wang, Jerry, last modified on Feb 05, 2015 要获取更多Jerry的原创文章,请关注公众号"汪子熙":

  7. NGUI所见即所得之深入剖析UIPanel,UIWidget,UIDrawCall底层原理

    NGUI所见即所得之深入剖析UIPanel,UIWidget,UIDrawCall底层原理 By D.S.Qiu 尊重他人的劳动,支持原创,转载请注明出处:http.dsqiu.iteye.com 之 ...

  8. NGUI基本控件的使用教程与实例

    NGUI教程:步骤1-Scene 1.创建一个新的场景(New Scene). 2.选择并删除场景里的MainCamera. 3.在NGUI菜单下选择Create a New UI,会打开UI创建向导 ...

  9. 界面插件NGUI的使用教程与实例

    原文地址:http://www.tasharen.com/?page_id=185 NGUI下载地址:点我传送 NGUI教程:步骤1-Scene 1.创建一个新的场景(New Scene). 2.选择 ...

最新文章

  1. php PDO php.ini
  2. Vue页面跳转后不显示问题
  3. java B2B2C源码电子商务平台 --zuul跨域访问问题
  4. java的获取声音振幅_录音获取声音振幅波形显示
  5. LockSupport HotSpot里park/unpark的实现
  6. oracle 命令行执行sql文件
  7. 颜色空间——Gamma与线性颜色空间
  8. 解决 此 Flash Player 与您的地区不相容 问题
  9. ST-LINK烧录stm32程序步骤
  10. Android自定义View里面获取宽高及dp和px间的转换
  11. android 动态修改logo,关于app动态修改logo的问题
  12. 微型计算机电路试卷,微机原理试卷及答案2
  13. 黑客张福:互联网是黑暗的森林
  14. python中如何查一个函数的用法_Python常见内置函数用法(三)
  15. 计算机应用知识试题 上学吧,自考计算机应用高分技巧,自考计算机应用作答技巧...
  16. php 模拟微信登录,PHP 模拟登录微信公众平台
  17. 越南语常用的计数词,多少钱用越南语怎么说
  18. 第一次使用虚拟机(VMware)
  19. android博客集合
  20. 嵌入式软件测试的基本方法

热门文章

  1. C# 使用Bitmap类进行图片裁剪
  2. AI算力霸主诞生!英伟达发布首款安培架构GPU,性能提升20倍
  3. 今日上新:两个图像领域的现金奖励实时竞赛
  4. 实用教程!使用YOLOv3训练自己数据的目标检测
  5. HTML MySQL实现登录注册_servlet+html+mysql实现登录注册功能
  6. 次世代游戏设计的相关介绍
  7. 大神交流经验!浙大吴飞与贾扬清经典十问!
  8. 从 AI、芯片到量子计算,阿里达摩院发布 2020 十大科技趋势
  9. java w732_技术联盟W732系统下载
  10. yolo算法的优缺点分析_YOLO算法详细解析(一)