AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
TextureThemeWidget.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 
4 using System;
5 using System.Collections;
6 using System.Collections.Generic;
7 using UnityEngine;
8 
9 namespace HoloToolkit.Examples.InteractiveElements
10 {
15  {
16  [Tooltip("A tag for finding the theme in the scene")]
17  public string ThemeTag = "defaultTexture";
18 
19  [Tooltip("The target object with the material to swap textures on : optional, leave blank for self")]
20  public GameObject Target;
21 
22  // The theme with the texture states
23  private TextureInteractiveTheme mTextureTheme;
24 
25  // material to swap the texture on
26  private Material mMaterial;
27 
28  private string mCheckThemeTag = "";
29 
30  void Awake()
31  {
32  // set the target
33  if (Target == null)
34  {
35  Target = this.gameObject;
36  }
37 
38  // set the renderer
39  Renderer renderer = Target.GetComponent<Renderer>();
40 
41  if (renderer != null)
42  {
43  mMaterial = renderer.material;
44  if (mTextureTheme != null)
45  {
46  SetTexture(State);
47  }
48  }
49  else
50  {
51  Debug.LogError("A Renderer does not exist on the Target!");
52  Destroy(this);
53  }
54  }
55 
59  private void Start()
60  {
61  if (mTextureTheme == null)
62  {
63  SetTheme();
64  }
65 
66  RefreshIfNeeded();
67  }
68 
69  public override void SetTheme()
70  {
71  mTextureTheme = GetTextureTheme(ThemeTag);
72  mCheckThemeTag = ThemeTag;
73  }
74 
79  public override void SetState(Interactive.ButtonStateEnum state)
80  {
81  base.SetState(state);
82 
83  SetTexture(state);
84  }
85 
90  private void SetTexture(Interactive.ButtonStateEnum state)
91  {
92  if (mTextureTheme != null)
93  {
94  mMaterial.SetTexture("_MainTex", mTextureTheme.GetThemeValue(state));
95  }
96  }
97 
98  private void Update()
99  {
100  if(!mCheckThemeTag.Equals(ThemeTag))
101  {
102  SetTheme();
103  RefreshIfNeeded();
104  }
105  }
106 
110  private void OnDestroy()
111  {
112  if (mMaterial != null)
113  {
114  Destroy(mMaterial);
115  }
116  }
117  }
118 }
Type GetThemeValue(Interactive.ButtonStateEnum state)
override void SetTheme()
Sets the themes based on the Theme Tags
ButtonStateEnum
A button typically has 8 potential states. We can update visual feedback based on state change...
Definition: Interactive.cs:80
A version of InteractiveWidget that uses an InteractiveTheme to define each state ...
An Interactive Theme Widget for swapping textures based on interactive state
Interactive exposes basic button type events to the Unity Editor and receives messages from the Gestu...
Definition: Interactive.cs:22
override void SetState(Interactive.ButtonStateEnum state)
From InteractiveWidget