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. The paths 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.\rTrigger Model Path
: The model that represents the trigger button.\rGrip Left Model Path
: The model that represents the left grip button.\rGrip Right Model Path
: The model that represents the right grip button.\rTouchpad Model Path
: The model that represents the touchpad.\rApp Menu Model Path
: The model that represents the application menu button.\rSystem 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.\rTrigger
: The highlighter to use on the trigger button.\rGrip Left
: The highlighter to use on the left grip button.\rGrip Right
: The highlighter to use on the right grip button.\rTouchpad
: The highlighter to use on the touchpad.\rApp Menu
: The highlighter to use on the application menu button.\rSystem 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
to1f
.- 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 to0f
.- 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 andfalse
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 andfalse
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 andfalse
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 andfalse
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.
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 andfalse
will remove the highlight from the application menu.Color? highlight
- The colour to highlight the application menu with.float duration
- The duration of fade from white to the highlight colour.- Returns
- none
The ToggleHighlightApplicationMenu method is a shortcut method that makes it easier to toggle the highlight state of the controller application menu 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 andfalse
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 controllerfalse
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(ushort strength)
- Parameters
ushort strength
- The intensity of the rumble of the controller motor.0
to3999
.- 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
to3999
.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.
Updated less than a minute ago