Guides
These docs are for v2.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.

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 visibile - 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 = 0f - 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 it's 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 it's 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 fadeDuration = 0f - The duration of fade from white to the highlight colour. Optional parameter defaults to 0f.
  • 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 seperately.

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 fadeDuration = 0f - The duration of fade from white to the highlight colour. Optional parameter defaults to 0f.
  • 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 fadeDuration = 0f - The duration of fade from white to the highlight colour. Optional parameter defaults to 0f.
  • 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 fadeDuration = 0f - The duration of fade from white to the highlight colour. Optional parameter defaults to 0f.
  • Returns
  • none

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

ToggleHighlightApplicationMenu/3

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

  • Parameters
  • bool state - The highlight colour state, true will enable the highlight on the application menu and false will remove the highlight from the application menu.
  • Color? highlight - The colour to highlight the application menu with.
  • float fadeDuration = 0f - The duration of fade from white to the highlight colour. Optional parameter defaults to 0f.
  • Returns
  • none

The ToggleHighlightApplicationMenu method is a shortcut method that makes it easier to toggle the highlight state of the controller application menu 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 fadeDuration = 0f - The duration of fade from white to the highlight colour. Optional parameter defaults to 0f.
  • 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(ushort strength)

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

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

TriggerHapticPulse/3

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

  • Parameters
  • ushort strength - The intensity of the rumble of the controller motor. 0 to 3999.
  • 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.

Example

SteamVR_Unity_Toolkit/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.

SteamVR_Unity_Toolkit/Examples/035_Controller_OpacityAndHighlightingdemonstrates 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.