Guides
These docs are for v3.0.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 System Menu Model Path: The model that represents the system 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 System Menu: The highlighter to use on the system 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 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 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 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 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 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 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 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 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 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 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.

ToggleHighlighBody/3

public 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 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 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 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 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.