{"_id":"58796782cd4a9c37007c9741","version":{"_id":"58796781cd4a9c37007c96ef","__v":4,"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"},"project":"571fa55ca0acd42000af9545","__v":0,"parentDoc":null,"user":"571fa519db52d01700f5cf3d","category":{"_id":"58796781cd4a9c37007c96f4","project":"571fa55ca0acd42000af9545","__v":0,"version":"58796781cd4a9c37007c96ef","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2017-01-01T16:45:52.489Z","from_sync":false,"order":6,"slug":"interactions","title":"Interactions"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2017-01-01T16:46:41.736Z","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 Controller Actions script provides helper methods to deal with common controller actions. It deals with actions that can be done to the controller.\n\nThe highlighting of the controller is defaulted to use the `VRTK_MaterialColorSwapHighlighter` if no other highlighter is applied to the Object.\n\n## Inspector Parameters\n\n * **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.\n * **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.\n\n## Class Events\n\n * `ControllerModelVisible` - Emitted when the controller model is toggled to be visible.\n * `ControllerModelInvisible` - Emitted when the controller model is toggled to be invisible.\n\n## Unity Events\n\nAdding the `VRTK_ControllerActions_UnityEvents` component to `VRTK_ControllerActions` object allows access to `UnityEvents` that will react identically to the Class Events.\n\n * `OnControllerModelVisible` - Emits the ControllerModelVisible class event.\n * `OnControllerModelInvisible` - Emits the ControllerModelInvisible class event.\n\n## Event Payload\n\n * `uint controllerIndex` - The index of the controller that was used.\n\n## Class Methods\n\n### IsControllerVisible/0\n\n  > `public bool IsControllerVisible()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * `bool` - Is true if the controller model has the renderers that are attached to it are enabled.\n\nThe IsControllerVisible method returns true if the controller is currently visible by whether the renderers on the controller are enabled.\n\n### ToggleControllerModel/2\n\n  > `public virtual void ToggleControllerModel(bool state, GameObject grabbedChildObject)`\n\n  * Parameters\n   * `bool state` - The visibility state to toggle the controller to, `true` will make the controller visible - `false` will hide the controller model.\n   * `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.\n  * Returns\n   * _none_\n\nThe 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.\n\n### SetControllerOpacity/1\n\n  > `public virtual void SetControllerOpacity(float alpha)`\n\n  * Parameters\n   * `float alpha` - The alpha level to apply to opacity of the controller object. `0f` to `1f`.\n  * Returns\n   * _none_\n\nThe 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.\n\n### HighlightControllerElement/3\n\n  > `public virtual void HighlightControllerElement(GameObject element, Color? highlight, float fadeDuration = 0f)`\n\n  * Parameters\n   * `GameObject element` - The element of the controller to apply the highlight to.\n   * `Color? highlight` - The colour of the highlight.\n   * `float fadeDuration` - The duration of fade from white to the highlight colour. Optional parameter defaults to `0f`.\n  * Returns\n   * _none_\n\nThe 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.\n\n### UnhighlightControllerElement/1\n\n  > `public virtual void UnhighlightControllerElement(GameObject element)`\n\n  * Parameters\n   * `GameObject element` - The element of the controller to remove the highlight from.\n  * Returns\n   * _none_\n\nThe UnhighlightControllerElement method is the inverse of the HighlightControllerElement method and resets the controller element to its original colour.\n\n### ToggleHighlightControllerElement/4\n\n  > `public virtual void ToggleHighlightControllerElement(bool state, GameObject element, Color? highlight = null, float duration = 0f)`\n\n  * Parameters\n   * `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.\n   * `GameObject element` - The element of the controller to apply the highlight to.\n   * `Color? highlight` - The colour of the highlight.\n   * `float duration` - The duration of fade from white to the highlight colour.\n  * Returns\n   * _none_\n\nThe 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.\n\n### ToggleHighlightTrigger/3\n\n  > `public virtual void ToggleHighlightTrigger(bool state, Color? highlight = null, float duration = 0f)`\n\n  * Parameters\n   * `bool state` - The highlight colour state, `true` will enable the highlight on the trigger and `false` will remove the highlight from the trigger.\n   * `Color? highlight` - The colour to highlight the trigger with.\n   * `float duration` - The duration of fade from white to the highlight colour.\n  * Returns\n   * _none_\n\nThe ToggleHighlightTrigger method is a shortcut method that makes it easier to toggle the highlight state of the controller trigger element.\n\n### ToggleHighlightGrip/3\n\n  > `public virtual void ToggleHighlightGrip(bool state, Color? highlight = null, float duration = 0f)`\n\n  * Parameters\n   * `bool state` - The highlight colour state, `true` will enable the highlight on the grip and `false` will remove the highlight from the grip.\n   * `Color? highlight` - The colour to highlight the grip with.\n   * `float duration` - The duration of fade from white to the highlight colour.\n  * Returns\n   * _none_\n\nThe ToggleHighlightGrip method is a shortcut method that makes it easier to toggle the highlight state of the controller grip element.\n\n### ToggleHighlightTouchpad/3\n\n  > `public virtual void ToggleHighlightTouchpad(bool state, Color? highlight = null, float duration = 0f)`\n\n  * Parameters\n   * `bool state` - The highlight colour state, `true` will enable the highlight on the touchpad and `false` will remove the highlight from the touchpad.\n   * `Color? highlight` - The colour to highlight the touchpad with.\n   * `float duration` - The duration of fade from white to the highlight colour.\n  * Returns\n   * _none_\n\nThe ToggleHighlightTouchpad method is a shortcut method that makes it easier to toggle the highlight state of the controller touchpad element.\n\n### ToggleHighlightButtonOne/3\n\n  > `public virtual void ToggleHighlightButtonOne(bool state, Color? highlight = null, float duration = 0f)`\n\n  * Parameters\n   * `bool state` - The highlight colour state, `true` will enable the highlight on button one and `false` will remove the highlight from button one.\n   * `Color? highlight` - The colour to highlight button one with.\n   * `float duration` - The duration of fade from white to the highlight colour.\n  * Returns\n   * _none_\n\nThe ToggleHighlightButtonOne method is a shortcut method that makes it easier to toggle the highlight state of the button one controller element.\n\n### ToggleHighlightButtonTwo/3\n\n  > `public virtual void ToggleHighlightButtonTwo(bool state, Color? highlight = null, float duration = 0f)`\n\n  * Parameters\n   * `bool state` - The highlight colour state, `true` will enable the highlight on button two and `false` will remove the highlight from button two.\n   * `Color? highlight` - The colour to highlight button two with.\n   * `float duration` - The duration of fade from white to the highlight colour.\n  * Returns\n   * _none_\n\nThe ToggleHighlightButtonTwo method is a shortcut method that makes it easier to toggle the highlight state of the button two controller element.\n\n### ToggleHighlightStartMenu/3\n\n  > `public virtual void ToggleHighlightStartMenu(bool state, Color? highlight = null, float duration = 0f)`\n\n  * Parameters\n   * `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.\n   * `Color? highlight` - The colour to highlight the start menu with.\n   * `float duration` - The duration of fade from white to the highlight colour.\n  * Returns\n   * _none_\n\nThe ToggleHighlightStartMenu method is a shortcut method that makes it easier to toggle the highlight state of the start menu controller element.\n\n### ToggleHighlighBody/3\n\n  > `public virtual void ToggleHighlighBody(bool state, Color? highlight = null, float duration = 0f)`\n\n  * Parameters\n   * `bool state` - The highlight colour state, `true` will enable the highlight on the body and `false` will remove the highlight from the body.\n   * `Color? highlight` - The colour to highlight the body with.\n   * `float duration` - The duration of fade from white to the highlight colour.\n  * Returns\n   * _none_\n\nThe ToggleHighlighBody method is a shortcut method that makes it easier to toggle the highlight state of the controller body element.\n\n### ToggleHighlightController/3\n\n  > `public virtual void ToggleHighlightController(bool state, Color? highlight = null, float duration = 0f)`\n\n  * Parameters\n   * `bool state` - The highlight colour state, `true` will enable the highlight on the entire controller `false` will remove the highlight from the entire controller.\n   * `Color? highlight` - The colour to highlight the entire controller with.\n   * `float duration` - The duration of fade from white to the highlight colour.\n  * Returns\n   * _none_\n\nThe ToggleHighlightController method is a shortcut method that makes it easier to toggle the highlight state of the entire controller.\n\n### TriggerHapticPulse/1\n\n  > `public virtual void TriggerHapticPulse(float strength)`\n\n  * Parameters\n   * `float strength` - The intensity of the rumble of the controller motor. `0` to `1`.\n  * Returns\n   * _none_\n\nThe TriggerHapticPulse/1 method calls a single haptic pulse call on the controller for a single tick.\n\n### TriggerHapticPulse/3\n\n  > `public virtual void TriggerHapticPulse(float strength, float duration, float pulseInterval)`\n\n  * Parameters\n   * `float strength` - The intensity of the rumble of the controller motor. `0` to `1`.\n   * `float duration` - The length of time the rumble should continue for.\n   * `float pulseInterval` - The interval to wait between each haptic pulse.\n  * Returns\n   * _none_\n\nThe 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.\n\n### InitaliseHighlighters/0\n\n  > `public virtual void InitaliseHighlighters()`\n\n  * Parameters\n   * _none_\n  * Returns\n   * _none_\n\nThe InitaliseHighlighters method sets up the highlighters on the controller model.\n\n## Example\n\n`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.\n\n`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.","excerpt":"","slug":"vrtk_controlleractions","type":"basic","title":"VRTK_ControllerActions"}

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.