Uicamera (ngui Event System) Principle

Source: Internet
Author: User

After reading the uicamera source code, it is obvious:

 

Uicamera « On:November 21,201 3, 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. 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" (based on the ray collision test, you can understand why the box colider is required) must be checked in the physics settings.



The first option on the uicamera, Event TypeIs what determines how the script sorts whats underneath the mouse and touch events. If it's set UIMode, then it's always based on widget's depth -- just like the draw order. changing this option WorldMode is something you shoshould do if your uicamera is attached to your main camera. Doing so will sort the hit objects by their distance to the camera.

Event maskIs what determines which game object layers will be capable of login ing 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 LayerOf your game object containing the UI hierarchy, Make sure to adjust the event maskOr you will suddenly find your UI no longer responding to events.

DebugOption 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-touchOption controls whether multiple touches will be supported. If turned off, multiple touches will all be treated as a single touch.

Sticky tooltipOption 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 DelayControls the delay between the mouse stopping movement over some object and OntooltipNotification being sent to that object. This value is in seconds.

Raycast rangeControls 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 sourcesSection 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 tables les will automatically turn off mouse and touch events.



ThresholdsSection 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 keysSection lets you choose which axes result in which movement. These axes shocould match the names in your project's Input Manager.

Pro-Tip #1

Uicamera sends out the following events to colcyclers:
  • 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 () ications 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.

Uicamera (ngui Event System) Principle

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.