Guides
Guides
These docs are for v3.1.0. Click to read the latest docs for v3.3.0.

VRTK_ControllerActions

Overview

The Controller Actions script provides helper methods to deal with common controller actions. It deals with actions that can be done to the controller.

The highlighting of the controller is defaulted to use the VRTK_MaterialColorSwapHighlighter if no other highlighter is applied to the Object.

Inspector Parameters

  • Model Element Paths: A collection of strings that determine the path to the controller model sub elements for identifying the model parts at runtime. If the paths are left empty they will default to the model element paths of the selected SDK Bridge.\n\r The available model sub elements are:\n\r Body Model Path: The overall shape of the controller.\r Trigger Model Path: The model that represents the trigger button.\r Grip Left Model Path: The model that represents the left grip button.\r Grip Right Model Path: The model that represents the right grip button.\r Touchpad Model Path: The model that represents the touchpad.\r Button One Model Path: The model that represents button one.\r Button Two Model Path: The model that represents button two.\r System Menu Model Path: The model that represents the system menu button. Start Menu Model Path: The model that represents the start menu button.
  • Element Highlighter Overrides: A collection of highlighter overrides for each controller model sub element. If no highlighter override is given then highlighter on the Controller game object is used.\n\r The available model sub elements are:\n\r Body: The highlighter to use on the overall shape of the controller.\r Trigger: The highlighter to use on the trigger button.\r Grip Left: The highlighter to use on the left grip button.\r Grip Right: The highlighter to use on the right grip button.\r Touchpad: The highlighter to use on the touchpad.\r Button One: The highlighter to use on button one.\r Button Two: The highlighter to use on button two.\r System Menu: The highlighter to use on the system menu button. Start Menu: The highlighter to use on the start menu button.

Class Events

  • ControllerModelVisible - Emitted when the controller model is toggled to be visible.
  • ControllerModelInvisible - Emitted when the controller model is toggled to be invisible.

Unity Events

Adding the VRTK_ControllerActions_UnityEvents component to VRTK_ControllerActions object allows access to UnityEvents that will react identically to the Class Events.

  • OnControllerModelVisible - Emits the ControllerModelVisible class event.
  • OnControllerModelInvisible - Emits the ControllerModelInvisible class event.

Event Payload

  • uint controllerIndex - The index of the controller that was used.

Class Methods

IsControllerVisible/0

public bool IsControllerVisible()

  • Parameters
  • none
  • Returns
  • bool - Is true if the controller model has the renderers that are attached to it are enabled.

The IsControllerVisible method returns true if the controller is currently visible by whether the renderers on the controller are enabled.

ToggleControllerModel/2

public virtual void ToggleControllerModel(bool state, GameObject grabbedChildObject)

  • Parameters
  • bool state - The visibility state to toggle the controller to, true will make the controller visible - false will hide the controller model.
  • GameObject grabbedChildObject - If an object is being held by the controller then this can be passed through to prevent hiding the grabbed game object as well.
  • Returns
  • none

The ToggleControllerModel method is used to turn on or off the controller model by enabling or disabling the renderers on the object. It will also work for any custom controllers. It should also not disable any objects being held by the controller if they are a child of the controller object.

SetControllerOpacity/1

public virtual void SetControllerOpacity(float alpha)

  • Parameters
  • float alpha - The alpha level to apply to opacity of the controller object. 0f to 1f.
  • Returns
  • none

The SetControllerOpacity method allows the opacity of the controller model to be changed to make the controller more transparent. A lower alpha value will make the object more transparent, such as 0.5f will make the controller partially transparent where as 0f will make the controller completely transparent.

HighlightControllerElement/3

public virtual void HighlightControllerElement(GameObject element, Color? highlight, float fadeDuration = 0f)

  • Parameters
  • GameObject element - The element of the controller to apply the highlight to.
  • Color? highlight - The colour of the highlight.
  • float fadeDuration - The duration of fade from white to the highlight colour. Optional parameter defaults to 0f.
  • Returns
  • none

The HighlightControllerElement method allows for an element of the controller to have its colour changed to simulate a highlighting effect of that element on the controller. It's useful for being able to draw a user's attention to a specific button on the controller.

UnhighlightControllerElement/1

public virtual void UnhighlightControllerElement(GameObject element)

  • Parameters
  • GameObject element - The element of the controller to remove the highlight from.
  • Returns
  • none

The UnhighlightControllerElement method is the inverse of the HighlightControllerElement method and resets the controller element to its original colour.

ToggleHighlightControllerElement/4

public virtual void ToggleHighlightControllerElement(bool state, GameObject element, Color? highlight = null, float duration = 0f)

  • Parameters
  • bool state - The highlight colour state, true will enable the highlight on the given element and false will remove the highlight from the given element.
  • GameObject element - The element of the controller to apply the highlight to.
  • Color? highlight - The colour of the highlight.
  • float duration - The duration of fade from white to the highlight colour.
  • Returns
  • none

The ToggleHighlightControllerElement method is a shortcut method that makes it easier to highlight and unhighlight a controller element in a single method rather than using the HighlightControllerElement and UnhighlightControllerElement methods separately.

ToggleHighlightTrigger/3

public virtual void ToggleHighlightTrigger(bool state, Color? highlight = null, float duration = 0f)

  • Parameters
  • bool state - The highlight colour state, true will enable the highlight on the trigger and false will remove the highlight from the trigger.
  • Color? highlight - The colour to highlight the trigger with.
  • float duration - The duration of fade from white to the highlight colour.
  • Returns
  • none

The ToggleHighlightTrigger method is a shortcut method that makes it easier to toggle the highlight state of the controller trigger element.

ToggleHighlightGrip/3

public virtual void ToggleHighlightGrip(bool state, Color? highlight = null, float duration = 0f)

  • Parameters
  • bool state - The highlight colour state, true will enable the highlight on the grip and false will remove the highlight from the grip.
  • Color? highlight - The colour to highlight the grip with.
  • float duration - The duration of fade from white to the highlight colour.
  • Returns
  • none

The ToggleHighlightGrip method is a shortcut method that makes it easier to toggle the highlight state of the controller grip element.

ToggleHighlightTouchpad/3

public virtual void ToggleHighlightTouchpad(bool state, Color? highlight = null, float duration = 0f)

  • Parameters
  • bool state - The highlight colour state, true will enable the highlight on the touchpad and false will remove the highlight from the touchpad.
  • Color? highlight - The colour to highlight the touchpad with.
  • float duration - The duration of fade from white to the highlight colour.
  • Returns
  • none

The ToggleHighlightTouchpad method is a shortcut method that makes it easier to toggle the highlight state of the controller touchpad element.

ToggleHighlightButtonOne/3

public virtual void ToggleHighlightButtonOne(bool state, Color? highlight = null, float duration = 0f)

  • Parameters
  • bool state - The highlight colour state, true will enable the highlight on button one and false will remove the highlight from button one.
  • Color? highlight - The colour to highlight button one with.
  • float duration - The duration of fade from white to the highlight colour.
  • Returns
  • none

The ToggleHighlightButtonOne method is a shortcut method that makes it easier to toggle the highlight state of the button one controller element.

ToggleHighlightButtonTwo/3

public virtual void ToggleHighlightButtonTwo(bool state, Color? highlight = null, float duration = 0f)

  • Parameters
  • bool state - The highlight colour state, true will enable the highlight on button two and false will remove the highlight from button two.
  • Color? highlight - The colour to highlight button two with.
  • float duration - The duration of fade from white to the highlight colour.
  • Returns
  • none

The ToggleHighlightButtonTwo method is a shortcut method that makes it easier to toggle the highlight state of the button two controller element.

ToggleHighlightStartMenu/3

public virtual void ToggleHighlightStartMenu(bool state, Color? highlight = null, float duration = 0f)

  • Parameters
  • bool state - The highlight colour state, true will enable the highlight on the start menu and false will remove the highlight from the start menu.
  • Color? highlight - The colour to highlight the start menu with.
  • float duration - The duration of fade from white to the highlight colour.
  • Returns
  • none

The ToggleHighlightStartMenu method is a shortcut method that makes it easier to toggle the highlight state of the start menu controller element.

ToggleHighlighBody/3

public virtual void ToggleHighlighBody(bool state, Color? highlight = null, float duration = 0f)

  • Parameters
  • bool state - The highlight colour state, true will enable the highlight on the body and false will remove the highlight from the body.
  • Color? highlight - The colour to highlight the body with.
  • float duration - The duration of fade from white to the highlight colour.
  • Returns
  • none

The ToggleHighlighBody method is a shortcut method that makes it easier to toggle the highlight state of the controller body element.

ToggleHighlightController/3

public virtual void ToggleHighlightController(bool state, Color? highlight = null, float duration = 0f)

  • Parameters
  • bool state - The highlight colour state, true will enable the highlight on the entire controller false will remove the highlight from the entire controller.
  • Color? highlight - The colour to highlight the entire controller with.
  • float duration - The duration of fade from white to the highlight colour.
  • Returns
  • none

The ToggleHighlightController method is a shortcut method that makes it easier to toggle the highlight state of the entire controller.

TriggerHapticPulse/1

public virtual void TriggerHapticPulse(float strength)

  • Parameters
  • float strength - The intensity of the rumble of the controller motor. 0 to 1.
  • Returns
  • none

The TriggerHapticPulse/1 method calls a single haptic pulse call on the controller for a single tick.

TriggerHapticPulse/3

public virtual void TriggerHapticPulse(float strength, float duration, float pulseInterval)

  • Parameters
  • float strength - The intensity of the rumble of the controller motor. 0 to 1.
  • float duration - The length of time the rumble should continue for.
  • float pulseInterval - The interval to wait between each haptic pulse.
  • Returns
  • none

The TriggerHapticPulse/3 method calls a haptic pulse for a specified amount of time rather than just a single tick. Each pulse can be separated by providing a pulseInterval to pause between each haptic pulse.

InitaliseHighlighters/0

public virtual void InitaliseHighlighters()

  • Parameters
  • none
  • Returns
  • none

The InitaliseHighlighters method sets up the highlighters on the controller model.

Example

VRTK/Examples/016_Controller_HapticRumble demonstrates the ability to hide a controller model and make the controller vibrate for a given length of time at a given intensity.

VRTK/Examples/035_Controller_OpacityAndHighlighting demonstrates the ability to change the opacity of a controller model and to highlight specific elements of a controller such as the buttons or even the entire controller model.