NGUI: Next-Gen UI kit  3.7.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros
UICamera Class Reference

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: More...

Inheritance diagram for UICamera:

Classes

class  MouseOrTouch
 Ambiguous mouse, touch, or controller event. More...
 

Public Types

enum  ControlScheme { ControlScheme.Mouse, ControlScheme.Touch, ControlScheme.Controller }
 
enum  ClickNotification { ClickNotification.None, ClickNotification.Always, ClickNotification.BasedOnDelta }
 Whether the touch event will be sending out the OnClick notification at the end. More...
 
enum  EventType : int { EventType.World_3D, EventType.UI_3D, EventType.World_2D, EventType.UI_2D }
 Camera type controls how raycasts are handled by the UICamera. More...
 

Public Member Functions

delegate bool GetKeyStateFunc (KeyCode key)
 
delegate float GetAxisFunc (string name)
 
delegate void OnScreenResize ()
 
delegate void OnCustomInput ()
 
void ProcessMouse ()
 Update mouse input. More...
 
void ProcessTouches ()
 Update touch-based events. More...
 
void ProcessOthers ()
 Process keyboard and joystick events. More...
 
void ProcessTouch (bool pressed, bool unpressed)
 Process the events of the specified touch. More...
 
void ShowTooltip (bool val)
 Show or hide the tooltip. More...
 

Static Public Member Functions

static bool IsPressed (GameObject go)
 Returns 'true' if any of the active touch, mouse or controller is currently holding the specified object. More...
 
static bool Raycast (Vector3 inPos)
 Returns the object under the specified position. More...
 
static bool IsHighlighted (GameObject go)
 Whether the specified object should be highlighted. More...
 
static UICamera FindCameraForLayer (int layer)
 Find the camera responsible for handling events on objects of the specified layer. More...
 
static void Notify (GameObject go, string funcName, object obj)
 Generic notification function. Used in place of SendMessage to shorten the code and allow for more than one receiver. More...
 
static MouseOrTouch GetMouse (int button)
 Get the details of the specified mouse button. More...
 
static MouseOrTouch GetTouch (int id)
 Get or create a touch event. More...
 
static void RemoveTouch (int id)
 Remove a touch event from the list. More...
 

Public Attributes

EventType eventType = EventType.UI_3D
 Event type – use "UI" for your user interfaces, and "World" for your game camera. This setting changes how raycasts are handled. Raycasts have to be more complicated for UI cameras. More...
 
LayerMask eventReceiverMask = -1
 Which layers will receive events. More...
 
bool debug = false
 If 'true', currently hovered object will be shown in the top left corner. More...
 
bool useMouse = true
 Whether the mouse input is used. More...
 
bool useTouch = true
 Whether the touch-based input is used. More...
 
bool allowMultiTouch = true
 Whether multi-touch is allowed. More...
 
bool useKeyboard = true
 Whether the keyboard events will be processed. More...
 
bool useController = true
 Whether the joystick and controller events will be processed. More...
 
bool stickyTooltip = true
 Whether the tooltip will disappear as soon as the mouse moves (false) or only if the mouse moves outside of the widget's area (true). More...
 
float tooltipDelay = 1f
 How long of a delay to expect before showing the tooltip. More...
 
float mouseDragThreshold = 4f
 How much the mouse has to be moved after pressing a button before it starts to send out drag events. More...
 
float mouseClickThreshold = 10f
 How far the mouse is allowed to move in pixels before it's no longer considered for click events, if the click notification is based on delta. More...
 
float touchDragThreshold = 40f
 How much the mouse has to be moved after pressing a button before it starts to send out drag events. More...
 
float touchClickThreshold = 40f
 How far the touch is allowed to move in pixels before it's no longer considered for click events, if the click notification is based on delta. More...
 
float rangeDistance = -1f
 Raycast range distance. By default it's as far as the camera can see. More...
 
string scrollAxisName = "Mouse ScrollWheel"
 Name of the axis used for scrolling. More...
 
string verticalAxisName = "Vertical"
 Name of the axis used to send up and down key events. More...
 
string horizontalAxisName = "Horizontal"
 Name of the axis used to send left and right key events. More...
 
KeyCode submitKey0 = KeyCode.Return
 Various keys used by the camera. More...
 
KeyCode submitKey1 = KeyCode.JoystickButton0
 
KeyCode cancelKey0 = KeyCode.Escape
 
KeyCode cancelKey1 = KeyCode.JoystickButton1
 

Static Public Attributes

static BetterList< UICameralist = new BetterList<UICamera>()
 List of all active cameras in the scene. More...
 
static GetKeyStateFunc GetKeyDown = Input.GetKeyDown
 GetKeyDown function – return whether the specified key was pressed this Update(). More...
 
static GetKeyStateFunc GetKeyUp = Input.GetKeyUp
 GetKeyDown function – return whether the specified key was released this Update(). More...
 
static GetKeyStateFunc GetKey = Input.GetKey
 GetKey function – return whether the specified key is currently held. More...
 
static GetAxisFunc GetAxis = Input.GetAxis
 GetAxis function – return the state of the specified axis. More...
 
static OnScreenResize onScreenResize
 Delegate triggered when the screen size changes for any reason. Subscribe to it if you don't want to compare Screen.width and Screen.height each frame. More...
 
static OnCustomInput onCustomInput
 Custom input processing logic, if desired. For example: WP7 touches. Use UICamera.current to get the current camera. More...
 
static bool showTooltips = true
 Whether tooltips will be shown or not. More...
 
static Vector2 lastTouchPosition = Vector2.zero
 Position of the last touch (or mouse) event. More...
 
static Vector3 lastWorldPosition = Vector3.zero
 Position of the last touch (or mouse) event in the world. More...
 
static RaycastHit lastHit
 Last raycast hit prior to sending out the event. This is useful if you want detailed information about what was actually hit in your OnClick, OnHover, and other event functions. Note that this is not going to be valid if you're using 2D colliders. More...
 
static UICamera current = null
 UICamera that sent out the event. More...
 
static Camera currentCamera = null
 Last camera active prior to sending out the event. This will always be the camera that actually sent out the event. More...
 
static ControlScheme currentScheme = ControlScheme.Mouse
 Current control scheme. Set automatically when events arrive. More...
 
static int currentTouchID = -1
 ID of the touch or mouse operation prior to sending out the event. Mouse ID is '-1' for left, '-2' for right mouse button, '-3' for middle. More...
 
static KeyCode currentKey = KeyCode.None
 Key that triggered the event, if any. More...
 
static MouseOrTouch currentTouch = null
 Current touch, set before any event function gets called. More...
 
static bool inputHasFocus = false
 Whether an input field currently has focus. More...
 
static GameObject genericEventHandler
 If set, this game object will receive all events regardless of whether they were handled or not. More...
 
static GameObject fallThrough
 If events don't get handled, they will be forwarded to this game object. More...
 
static MouseOrTouch controller = new MouseOrTouch()
 
static bool isDragging = false
 Set to 'true' just before OnDrag-related events are sent. No longer needed, but kept for backwards compatibility. More...
 
static GameObject hoveredObject
 The object hit by the last Raycast that was the result of a mouse or touch event. More...
 

Static Protected Member Functions

static void SetSelection (GameObject go, ControlScheme scheme)
 Change the selection. More...
 

Properties

bool stickyPress [get]
 
static Ray currentRay [get]
 Ray projected into the screen underneath the current touch. More...
 
Camera cachedCamera [get]
 Caching is always preferable for performance. More...
 
static GameObject selectedObject [get, set]
 Option to manually set the selected game object. More...
 
static int touchCount [get]
 Number of active touches from all sources. More...
 
static int dragCount [get]
 Number of active drag events from all sources. More...
 
static Camera mainCamera [get]
 Convenience function that returns the main HUD camera. More...
 
static UICamera eventHandler [get]
 Event handler for all types of events. More...
 

Detailed Description

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.

Member Enumeration Documentation

Whether the touch event will be sending out the OnClick notification at the end.

Enumerator
None 
Always 
BasedOnDelta 
Enumerator
Mouse 
Touch 
Controller 
enum UICamera.EventType : int

Camera type controls how raycasts are handled by the UICamera.

Enumerator
World_3D 
UI_3D 
World_2D 
UI_2D 

Member Function Documentation

static UICamera UICamera.FindCameraForLayer ( int  layer)
static

Find the camera responsible for handling events on objects of the specified layer.

delegate float UICamera.GetAxisFunc ( string  name)
delegate bool UICamera.GetKeyStateFunc ( KeyCode  key)
static MouseOrTouch UICamera.GetMouse ( int  button)
static

Get the details of the specified mouse button.

static MouseOrTouch UICamera.GetTouch ( int  id)
static

Get or create a touch event.

static bool UICamera.IsHighlighted ( GameObject  go)
static

Whether the specified object should be highlighted.

static bool UICamera.IsPressed ( GameObject  go)
static

Returns 'true' if any of the active touch, mouse or controller is currently holding the specified object.

static void UICamera.Notify ( GameObject  go,
string  funcName,
object  obj 
)
static

Generic notification function. Used in place of SendMessage to shorten the code and allow for more than one receiver.

delegate void UICamera.OnCustomInput ( )
delegate void UICamera.OnScreenResize ( )
void UICamera.ProcessMouse ( )

Update mouse input.

void UICamera.ProcessOthers ( )

Process keyboard and joystick events.

void UICamera.ProcessTouch ( bool  pressed,
bool  unpressed 
)

Process the events of the specified touch.

void UICamera.ProcessTouches ( )

Update touch-based events.

static bool UICamera.Raycast ( Vector3  inPos)
static

Returns the object under the specified position.

static void UICamera.RemoveTouch ( int  id)
static

Remove a touch event from the list.

static void UICamera.SetSelection ( GameObject  go,
ControlScheme  scheme 
)
staticprotected

Change the selection.

void UICamera.ShowTooltip ( bool  val)

Show or hide the tooltip.

Member Data Documentation

bool UICamera.allowMultiTouch = true

Whether multi-touch is allowed.

KeyCode UICamera.cancelKey0 = KeyCode.Escape
KeyCode UICamera.cancelKey1 = KeyCode.JoystickButton1
MouseOrTouch UICamera.controller = new MouseOrTouch()
static
UICamera UICamera.current = null
static

UICamera that sent out the event.

Camera UICamera.currentCamera = null
static

Last camera active prior to sending out the event. This will always be the camera that actually sent out the event.

KeyCode UICamera.currentKey = KeyCode.None
static

Key that triggered the event, if any.

ControlScheme UICamera.currentScheme = ControlScheme.Mouse
static

Current control scheme. Set automatically when events arrive.

MouseOrTouch UICamera.currentTouch = null
static

Current touch, set before any event function gets called.

int UICamera.currentTouchID = -1
static

ID of the touch or mouse operation prior to sending out the event. Mouse ID is '-1' for left, '-2' for right mouse button, '-3' for middle.

bool UICamera.debug = false

If 'true', currently hovered object will be shown in the top left corner.

LayerMask UICamera.eventReceiverMask = -1

Which layers will receive events.

EventType UICamera.eventType = EventType.UI_3D

Event type – use "UI" for your user interfaces, and "World" for your game camera. This setting changes how raycasts are handled. Raycasts have to be more complicated for UI cameras.

GameObject UICamera.fallThrough
static

If events don't get handled, they will be forwarded to this game object.

GameObject UICamera.genericEventHandler
static

If set, this game object will receive all events regardless of whether they were handled or not.

GetAxisFunc UICamera.GetAxis = Input.GetAxis
static

GetAxis function – return the state of the specified axis.

GetKeyStateFunc UICamera.GetKey = Input.GetKey
static

GetKey function – return whether the specified key is currently held.

GetKeyStateFunc UICamera.GetKeyDown = Input.GetKeyDown
static

GetKeyDown function – return whether the specified key was pressed this Update().

GetKeyStateFunc UICamera.GetKeyUp = Input.GetKeyUp
static

GetKeyDown function – return whether the specified key was released this Update().

string UICamera.horizontalAxisName = "Horizontal"

Name of the axis used to send left and right key events.

GameObject UICamera.hoveredObject
static

The object hit by the last Raycast that was the result of a mouse or touch event.

bool UICamera.inputHasFocus = false
static

Whether an input field currently has focus.

bool UICamera.isDragging = false
static

Set to 'true' just before OnDrag-related events are sent. No longer needed, but kept for backwards compatibility.

RaycastHit UICamera.lastHit
static

Last raycast hit prior to sending out the event. This is useful if you want detailed information about what was actually hit in your OnClick, OnHover, and other event functions. Note that this is not going to be valid if you're using 2D colliders.

Vector2 UICamera.lastTouchPosition = Vector2.zero
static

Position of the last touch (or mouse) event.

Vector3 UICamera.lastWorldPosition = Vector3.zero
static

Position of the last touch (or mouse) event in the world.

BetterList<UICamera> UICamera.list = new BetterList<UICamera>()
static

List of all active cameras in the scene.

float UICamera.mouseClickThreshold = 10f

How far the mouse is allowed to move in pixels before it's no longer considered for click events, if the click notification is based on delta.

float UICamera.mouseDragThreshold = 4f

How much the mouse has to be moved after pressing a button before it starts to send out drag events.

OnCustomInput UICamera.onCustomInput
static

Custom input processing logic, if desired. For example: WP7 touches. Use UICamera.current to get the current camera.

OnScreenResize UICamera.onScreenResize
static

Delegate triggered when the screen size changes for any reason. Subscribe to it if you don't want to compare Screen.width and Screen.height each frame.

float UICamera.rangeDistance = -1f

Raycast range distance. By default it's as far as the camera can see.

string UICamera.scrollAxisName = "Mouse ScrollWheel"

Name of the axis used for scrolling.

bool UICamera.showTooltips = true
static

Whether tooltips will be shown or not.

bool UICamera.stickyTooltip = true

Whether the tooltip will disappear as soon as the mouse moves (false) or only if the mouse moves outside of the widget's area (true).

KeyCode UICamera.submitKey0 = KeyCode.Return

Various keys used by the camera.

KeyCode UICamera.submitKey1 = KeyCode.JoystickButton0
float UICamera.tooltipDelay = 1f

How long of a delay to expect before showing the tooltip.

float UICamera.touchClickThreshold = 40f

How far the touch is allowed to move in pixels before it's no longer considered for click events, if the click notification is based on delta.

float UICamera.touchDragThreshold = 40f

How much the mouse has to be moved after pressing a button before it starts to send out drag events.

bool UICamera.useController = true

Whether the joystick and controller events will be processed.

bool UICamera.useKeyboard = true

Whether the keyboard events will be processed.

bool UICamera.useMouse = true

Whether the mouse input is used.

bool UICamera.useTouch = true

Whether the touch-based input is used.

string UICamera.verticalAxisName = "Vertical"

Name of the axis used to send up and down key events.

Property Documentation

Camera UICamera.cachedCamera
get

Caching is always preferable for performance.

Ray UICamera.currentRay
staticget

Ray projected into the screen underneath the current touch.

int UICamera.dragCount
staticget

Number of active drag events from all sources.

UICamera UICamera.eventHandler
staticget

Event handler for all types of events.

Camera UICamera.mainCamera
staticget

Convenience function that returns the main HUD camera.

GameObject UICamera.selectedObject
staticgetset

Option to manually set the selected game object.

bool UICamera.stickyPress
get
int UICamera.touchCount
staticget

Number of active touches from all sources.


The documentation for this class was generated from the following file: