AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
MaterialColorThemeWidget.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
5 using System.Collections;
6 using System.Collections.Generic;
7 using UnityEngine;
8 using System;
9 
10 namespace HoloToolkit.Examples.InteractiveElements
11 {
16  {
17  [Tooltip("A tag for finding the theme in the scene")]
18  public string ThemeTag = "defaultColor";
19 
20  [Tooltip("A component for color transitions: optional")]
22 
23  private ColorInteractiveTheme mColorTheme;
24  private Material mMaterial;
25 
26  private string mCheckThemeTag = "";
27 
28  void Awake()
29  {
30  // get the color blender
31  if (ColorBlender == null)
32  {
33  ColorBlender = GetComponent<ColorTransition>();
34  }
35 
36  // get the renderer and material
37  Renderer renderer = GetComponent<Renderer>();
38  if (renderer != null)
39  {
40  mMaterial = renderer.material;
41  }
42 
43  if (mMaterial != null && mColorTheme != null)
44  {
45  mMaterial.color = mColorTheme.GetThemeValue(State);
46  }
47  }
48 
49  private void Start()
50  {
51  if (mColorTheme == null)
52  {
53  SetTheme();
54  }
55 
56  RefreshIfNeeded();
57  }
58 
59  public override void SetTheme()
60  {
61  mColorTheme = GetColorTheme(ThemeTag);
62  mCheckThemeTag = ThemeTag;
63  }
64 
69  public override void SetState(Interactive.ButtonStateEnum state)
70  {
71  base.SetState(state);
72 
73  if (mColorTheme != null)
74  {
75  if (ColorBlender != null)
76  {
77  ColorBlender.StartTransition(mColorTheme.GetThemeValue(state));
78  }
79  else if (mMaterial != null)
80  {
81  mMaterial.color = mColorTheme.GetThemeValue(state);
82  }
83  }
84  }
85 
86  private void Update()
87  {
88  if (!mCheckThemeTag.Equals(ThemeTag))
89  {
90  SetTheme();
91  RefreshIfNeeded();
92  }
93  }
94 
98  private void OnDestroy()
99  {
100  if (mMaterial != null)
101  {
102  GameObject.Destroy(mMaterial);
103  }
104  }
105  }
106 }
Type GetThemeValue(Interactive.ButtonStateEnum state)
ButtonStateEnum
A button typically has 8 potential states. We can update visual feedback based on state change...
Definition: Interactive.cs:80
override void SetState(Interactive.ButtonStateEnum state)
Set or fade the colors
Changes the color of a material based on the Interactive state and the assigned theme ...
A version of InteractiveWidget that uses an InteractiveTheme to define each state ...
override void SetTheme()
Sets the themes based on the Theme Tags
void StartTransition(Color color, string name="")
Fades the color of a material called by name
Interactive exposes basic button type events to the Unity Editor and receives messages from the Gestu...
Definition: Interactive.cs:22
A color blending animation component, handles multiple materials