{"__v":0,"_id":"58796781cd4a9c37007c971d","category":{"version":"58796781cd4a9c37007c96ef","project":"571fa55ca0acd42000af9545","_id":"58796781cd4a9c37007c96f9","__v":0,"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-01-01T17:00:24.070Z","from_sync":false,"order":11,"slug":"ui","title":"UI"},"parentDoc":null,"project":"571fa55ca0acd42000af9545","user":"571fa519db52d01700f5cf3d","version":{"__v":4,"_id":"58796781cd4a9c37007c96ef","project":"571fa55ca0acd42000af9545","createdAt":"2017-01-13T23:49:21.393Z","releaseDate":"2017-01-13T23:49:21.393Z","categories":["58796781cd4a9c37007c96f0","58796781cd4a9c37007c96f1","58796781cd4a9c37007c96f2","58796781cd4a9c37007c96f3","58796781cd4a9c37007c96f4","58796781cd4a9c37007c96f5","58796781cd4a9c37007c96f6","58796781cd4a9c37007c96f7","58796781cd4a9c37007c96f8","58796781cd4a9c37007c96f9","58796781cd4a9c37007c96fa","58796781cd4a9c37007c96fb","58796781cd4a9c37007c96fc","58796781cd4a9c37007c96fd","58796781cd4a9c37007c96fe","58796781cd4a9c37007c96ff","58796781cd4a9c37007c9700","58b157ca1756cf370022f90d","58b1596f5dae732f00adeca2","58b1605a5dae732f00adecb1"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"Mukota","version_clean":"3.1.0","version":"3.1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-01-01T17:01:04.245Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"body":"## Overview\n\nThe UI Pointer provides a mechanism for interacting with Unity UI elements on a world canvas. The UI Pointer can be attached to any game object the same way in which a Base Pointer can be and the UI Pointer also requires a controller to initiate the pointer activation and pointer click states.\n\nThe simplest way to use the UI Pointer is to attach the script to a game controller along with a Simple Pointer as this provides visual feedback as to where the UI ray is pointing.\n\nThe UI pointer is activated via the `Pointer` alias on the `Controller Events` and the UI pointer click state is triggered via the `UI Click` alias on the `Controller Events`.\n\n## Inspector Parameters\n\n * **Activation Button:** The button used to activate/deactivate the UI raycast for the pointer.\n * **Activation Mode:** Determines when the UI pointer should be active.\n * **Selection Button:** The button used to execute the select action at the pointer's target position.\n * **Click Method:** Determines when the UI Click event action should happen.\n * **Attempt Click On Deactivate:** Determines whether the UI click action should be triggered when the pointer is deactivated. If the pointer is hovering over a clickable element then it will invoke the click action on that element. Note: Only works with `Click Method =  Click_On_Button_Up`\n * **Click After Hover Duration:** The amount of time the pointer can be over the same UI element before it automatically attempts to click it. 0f means no click attempt will be made.\n * **Controller:** The controller that will be used to toggle the pointer. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime.\n * **Pointer Origin Transform:** A custom transform to use as the origin of the pointer. If no pointer origin transform is provided then the transform the script is attached to is used.\n\n## Class Variables\n\n * `public enum ActivationMethods` - Methods of activation.\n  * `HoldButton` - Only activates the UI Pointer when the Pointer button on the controller is pressed and held down.\n  * `ToggleButton` - Activates the UI Pointer on the first click of the Pointer button on the controller and it stays active until the Pointer button is clicked again.\n  * `AlwaysOn` - The UI Pointer is always active regardless of whether the Pointer button on the controller is pressed or not.\n * `public enum ClickMethods` - Methods of when to consider a UI Click action\n  * `ClickOnButtonUp` - Consider a UI Click action has happened when the UI Click alias button is released.\n  * `ClickOnButtonDown` - Consider a UI Click action has happened when the UI Click alias button is pressed.\n * `public GameObject autoActivatingCanvas` - The GameObject of the front trigger activator of the canvas currently being activated by this pointer. Default: `null`\n * `public bool collisionClick` - Determines if the UI Pointer has collided with a valid canvas that has collision click turned on. Default: `false`\n\n## Class Events\n\n * `UIPointerElementEnter` - Emitted when the UI Pointer is colliding with a valid UI element.\n * `UIPointerElementExit` - Emitted when the UI Pointer is no longer colliding with any valid UI elements.\n * `UIPointerElementClick` - Emitted when the UI Pointer has clicked the currently collided UI element.\n * `UIPointerElementDragStart` - Emitted when the UI Pointer begins dragging a valid UI element.\n * `UIPointerElementDragEnd` - Emitted when the UI Pointer stops dragging a valid UI element.\n\n## Unity Events\n\nAdding the `VRTK_UIPointer_UnityEvents` component to `VRTK_UIPointer` object allows access to `UnityEvents` that will react identically to the Class Events.\n\n * `OnUIPointerElementEnter` - Emits the UIPointerElementEnter class event.\n * `OnUIPointerElementExit` - Emits the UIPointerElementExit class event.\n * `OnUIPointerElementClick` - Emits the UIPointerElementClick class event.\n * `OnUIPointerElementDragStart` - Emits the UIPointerElementDragStart class event.\n * `OnUIPointerElementDragEnd` - Emits the UIPointerElementDragEnd class event.\n\n## Event Payload\n\n * `uint controllerIndex` - The index of the controller that was used.\n * `bool isActive` - The state of whether the UI Pointer is currently active or not.\n * `GameObject currentTarget` - The current UI element that the pointer is colliding with.\n * `GameObject previousTarget` - The previous UI element that the pointer was colliding with.\n\n## Class Methods\n\n### SetEventSystem/1\n\n  > `public virtual VRTK_VRInputModule SetEventSystem(EventSystem eventSystem)`\n\n  * Parameters\n   * `EventSystem eventSystem` - The global Unity event system to be used by the UI pointers.\n  * Returns\n   * `VRTK_VRInputModule` - A custom input module that is used to detect input from VR pointers.\n\nThe SetEventSystem method is used to set up the global Unity event system for the UI pointer. It also handles disabling the existing Standalone Input Module that exists on the EventSystem and adds a custom VRTK Event System VR Input component that is required for interacting with the UI with VR inputs.\n\n### RemoveEventSystem/0\n\n  > `public virtual void RemoveEventSystem()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * _none_\n\nThe RemoveEventSystem resets the Unity EventSystem back to the original state before the VRTK_VRInputModule was swapped for it.\n\n### PointerActive/0\n\n  > `public virtual bool PointerActive()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `bool` - Returns true if the ui pointer should be currently active.\n\nThe PointerActive method determines if the ui pointer beam should be active based on whether the pointer alias is being held and whether the Hold Button To Use parameter is checked.\n\n### SelectionButtonActive/0\n\n  > `public virtual bool SelectionButtonActive()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `bool` - Returns true if the selection button is active.\n\nThe SelectionButtonActive method is used to determine if the configured selection button is currently in the active state.\n\n### ValidClick/2\n\n  > `public virtual bool ValidClick(bool checkLastClick, bool lastClickState = false)`\n\n  * Parameters\n   * `bool checkLastClick` - If this is true then the last frame's state of the UI Click button is also checked to see if a valid click has happened.\n   * `bool lastClickState` - This determines what the last frame's state of the UI Click button should be in for it to be a valid click.\n  * Returns\n   * `bool` - Returns true if the UI Click button is in a valid state to action a click, returns false if it is not in a valid state.\n\nThe ValidClick method determines if the UI Click button is in a valid state to register a click action.\n\n### GetOriginPosition/0\n\n  > `public virtual Vector3 GetOriginPosition()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `Vector3` - A Vector3 of the pointer transform position\n\nThe GetOriginPosition method returns the relevant transform position for the pointer based on whether the pointerOriginTransform variable is valid.\n\n### GetOriginForward/0\n\n  > `public virtual Vector3 GetOriginForward()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `Vector3` - A Vector3 of the pointer transform forward\n\nThe GetOriginPosition method returns the relevant transform forward for the pointer based on whether the pointerOriginTransform variable is valid.\n\n## Example\n\n`VRTK/Examples/034_Controls_InteractingWithUnityUI` uses the `VRTK_UIPointer` script on the right Controller to allow for the interaction with Unity UI elements using a Simple Pointer beam. The left Controller controls a Simple Pointer on the headset to demonstrate gaze interaction with Unity UI elements.","excerpt":"","slug":"vrtk_uipointer","type":"basic","title":"VRTK_UIPointer"}
## Overview The UI Pointer provides a mechanism for interacting with Unity UI elements on a world canvas. The UI Pointer can be attached to any game object the same way in which a Base Pointer can be and the UI Pointer also requires a controller to initiate the pointer activation and pointer click states. The simplest way to use the UI Pointer is to attach the script to a game controller along with a Simple Pointer as this provides visual feedback as to where the UI ray is pointing. The UI pointer is activated via the `Pointer` alias on the `Controller Events` and the UI pointer click state is triggered via the `UI Click` alias on the `Controller Events`. ## Inspector Parameters * **Activation Button:** The button used to activate/deactivate the UI raycast for the pointer. * **Activation Mode:** Determines when the UI pointer should be active. * **Selection Button:** The button used to execute the select action at the pointer's target position. * **Click Method:** Determines when the UI Click event action should happen. * **Attempt Click On Deactivate:** Determines whether the UI click action should be triggered when the pointer is deactivated. If the pointer is hovering over a clickable element then it will invoke the click action on that element. Note: Only works with `Click Method = Click_On_Button_Up` * **Click After Hover Duration:** The amount of time the pointer can be over the same UI element before it automatically attempts to click it. 0f means no click attempt will be made. * **Controller:** The controller that will be used to toggle the pointer. If the script is being applied onto a controller then this parameter can be left blank as it will be auto populated by the controller the script is on at runtime. * **Pointer Origin Transform:** A custom transform to use as the origin of the pointer. If no pointer origin transform is provided then the transform the script is attached to is used. ## Class Variables * `public enum ActivationMethods` - Methods of activation. * `HoldButton` - Only activates the UI Pointer when the Pointer button on the controller is pressed and held down. * `ToggleButton` - Activates the UI Pointer on the first click of the Pointer button on the controller and it stays active until the Pointer button is clicked again. * `AlwaysOn` - The UI Pointer is always active regardless of whether the Pointer button on the controller is pressed or not. * `public enum ClickMethods` - Methods of when to consider a UI Click action * `ClickOnButtonUp` - Consider a UI Click action has happened when the UI Click alias button is released. * `ClickOnButtonDown` - Consider a UI Click action has happened when the UI Click alias button is pressed. * `public GameObject autoActivatingCanvas` - The GameObject of the front trigger activator of the canvas currently being activated by this pointer. Default: `null` * `public bool collisionClick` - Determines if the UI Pointer has collided with a valid canvas that has collision click turned on. Default: `false` ## Class Events * `UIPointerElementEnter` - Emitted when the UI Pointer is colliding with a valid UI element. * `UIPointerElementExit` - Emitted when the UI Pointer is no longer colliding with any valid UI elements. * `UIPointerElementClick` - Emitted when the UI Pointer has clicked the currently collided UI element. * `UIPointerElementDragStart` - Emitted when the UI Pointer begins dragging a valid UI element. * `UIPointerElementDragEnd` - Emitted when the UI Pointer stops dragging a valid UI element. ## Unity Events Adding the `VRTK_UIPointer_UnityEvents` component to `VRTK_UIPointer` object allows access to `UnityEvents` that will react identically to the Class Events. * `OnUIPointerElementEnter` - Emits the UIPointerElementEnter class event. * `OnUIPointerElementExit` - Emits the UIPointerElementExit class event. * `OnUIPointerElementClick` - Emits the UIPointerElementClick class event. * `OnUIPointerElementDragStart` - Emits the UIPointerElementDragStart class event. * `OnUIPointerElementDragEnd` - Emits the UIPointerElementDragEnd class event. ## Event Payload * `uint controllerIndex` - The index of the controller that was used. * `bool isActive` - The state of whether the UI Pointer is currently active or not. * `GameObject currentTarget` - The current UI element that the pointer is colliding with. * `GameObject previousTarget` - The previous UI element that the pointer was colliding with. ## Class Methods ### SetEventSystem/1 > `public virtual VRTK_VRInputModule SetEventSystem(EventSystem eventSystem)` * Parameters * `EventSystem eventSystem` - The global Unity event system to be used by the UI pointers. * Returns * `VRTK_VRInputModule` - A custom input module that is used to detect input from VR pointers. The SetEventSystem method is used to set up the global Unity event system for the UI pointer. It also handles disabling the existing Standalone Input Module that exists on the EventSystem and adds a custom VRTK Event System VR Input component that is required for interacting with the UI with VR inputs. ### RemoveEventSystem/0 > `public virtual void RemoveEventSystem()` * Parameters * _none_ * Returns * _none_ The RemoveEventSystem resets the Unity EventSystem back to the original state before the VRTK_VRInputModule was swapped for it. ### PointerActive/0 > `public virtual bool PointerActive()` * Parameters * _none_ * Returns * `bool` - Returns true if the ui pointer should be currently active. The PointerActive method determines if the ui pointer beam should be active based on whether the pointer alias is being held and whether the Hold Button To Use parameter is checked. ### SelectionButtonActive/0 > `public virtual bool SelectionButtonActive()` * Parameters * _none_ * Returns * `bool` - Returns true if the selection button is active. The SelectionButtonActive method is used to determine if the configured selection button is currently in the active state. ### ValidClick/2 > `public virtual bool ValidClick(bool checkLastClick, bool lastClickState = false)` * Parameters * `bool checkLastClick` - If this is true then the last frame's state of the UI Click button is also checked to see if a valid click has happened. * `bool lastClickState` - This determines what the last frame's state of the UI Click button should be in for it to be a valid click. * Returns * `bool` - Returns true if the UI Click button is in a valid state to action a click, returns false if it is not in a valid state. The ValidClick method determines if the UI Click button is in a valid state to register a click action. ### GetOriginPosition/0 > `public virtual Vector3 GetOriginPosition()` * Parameters * _none_ * Returns * `Vector3` - A Vector3 of the pointer transform position The GetOriginPosition method returns the relevant transform position for the pointer based on whether the pointerOriginTransform variable is valid. ### GetOriginForward/0 > `public virtual Vector3 GetOriginForward()` * Parameters * _none_ * Returns * `Vector3` - A Vector3 of the pointer transform forward The GetOriginPosition method returns the relevant transform forward for the pointer based on whether the pointerOriginTransform variable is valid. ## Example `VRTK/Examples/034_Controls_InteractingWithUnityUI` uses the `VRTK_UIPointer` script on the right Controller to allow for the interaction with Unity UI elements using a Simple Pointer beam. The left Controller controls a Simple Pointer on the headset to demonstrate gaze interaction with Unity UI elements.