Guides
Guides

VRTK_MaterialColorSwapHighlighter

extends VRTK_BaseHighlighter

Overview

Swaps the texture colour on the Renderers material for the given highlight colour.

Due to the way the object material is interacted with, changing the material colour will break Draw Call Batching in Unity whilst the object is highlighted. The Draw Call Batching will resume on the original material when the item is no longer highlighted.

Script Usage:

  • Place the VRTK_MaterialColorSwapHighlighter script on either:
    • The GameObject of the Interactable Object to highlight.
    • Any other scene GameObject and then link that GameObject to the Interactable Objects Object Highlighter parameter to denote use of the highlighter.
  • Ensure the Active parameter is checked.

Inspector Parameters

  • Emission Darken: The emission colour of the texture will be the highlight colour but this percent darker.
  • Custom Material: A custom material to use on the highlighted object.

Class Methods

Initialise/3

public override void Initialise(Color? color = null, GameObject affectObject = null, Dictionary<string, object> options = null)

  • Parameters
    • Color? color - Not used.
    • GameObject affectObject - An optional GameObject to specify which object to apply the highlighting to.
    • Dictionary<string, object> options - A dictionary array containing the highlighter options:\r * <'resetMainTexture', bool> - Determines if the default main texture should be cleared on highlight. true to reset the main default texture, false to not reset it.
  • Returns
    • none

The Initialise method sets up the highlighter for use.

ResetHighlighter/0

public override void ResetHighlighter()

  • Parameters
    • none
  • Returns
    • none

The ResetHighlighter method stores the object's materials and shared materials prior to highlighting.

Highlight/2

public override void Highlight(Color? color, float duration = 0f)

  • Parameters
    • Color? color - The colour to highlight to.
    • float duration - The time taken to fade to the highlighted colour.
  • Returns
    • none

The Highlight method initiates the change of colour on the object and will fade to that colour (from a base white colour) for the given duration.

Unhighlight/2

public override void Unhighlight(Color? color = null, float duration = 0f)

  • Parameters
    • Color? color - Not used.
    • float duration - Not used.
  • Returns
    • none

The Unhighlight method returns the object back to it's original colour.

Example

VRTK/Examples/005_Controller_BasicObjectGrabbing demonstrates the solid highlighting on the green cube, red cube and flying saucer when the controller touches it.

VRTK/Examples/035_Controller_OpacityAndHighlighting demonstrates the solid highlighting if the right controller collides with the green box or if any of the buttons are pressed.