AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
InteractiveThemeWidget.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.Collections;
5 using System.Collections.Generic;
6 using UnityEngine;
7 
8 namespace HoloToolkit.Examples.InteractiveElements
9 {
13  public abstract class InteractiveThemeWidget : InteractiveWidget
14  {
15  // checks if the theme has changed since the last SetState was called.
16  protected bool mThemeUpdated;
17 
21  public abstract void SetTheme();
22 
26  public void RefreshIfNeeded()
27  {
28  if (mThemeUpdated)
29  {
30  SetState(State);
31  }
32  }
33 
38  public override void SetState(Interactive.ButtonStateEnum state)
39  {
40  base.SetState(state);
41  mThemeUpdated = false;
42  }
43 
50  {
51  // search locally
52  ColorInteractiveTheme[] colorThemes = InteractiveHost.GetComponentsInChildren<ColorInteractiveTheme>();
53  ColorInteractiveTheme theme = FindColorTheme(colorThemes, tag);
54 
55  // search globally
56  if (theme == null)
57  {
58  colorThemes = FindObjectsOfType<ColorInteractiveTheme>();
59  theme = FindColorTheme(colorThemes, tag);
60  }
61 
62  if (!mThemeUpdated) mThemeUpdated = theme != null;
63 
64  return theme;
65  }
66 
67  // compare theme tags
68  private ColorInteractiveTheme FindColorTheme(ColorInteractiveTheme[] colorThemes, string tag)
69  {
70  for (int i = 0; i < colorThemes.Length; ++i)
71  {
72  if (colorThemes[i].Tag == tag)
73  {
74  return colorThemes[i];
75  }
76  }
77 
78  return null;
79  }
80 
87  {
88  // search locally
89  Vector3InteractiveTheme[] vector3Themes = InteractiveHost.GetComponentsInChildren<Vector3InteractiveTheme>();
90  Vector3InteractiveTheme theme = FindVector3Theme(vector3Themes, tag);
91 
92  // search globally
93  if (theme == null)
94  {
95  vector3Themes = FindObjectsOfType<Vector3InteractiveTheme>();
96  theme = FindVector3Theme(vector3Themes, tag);
97  }
98 
99  if (!mThemeUpdated) mThemeUpdated = theme != null;
100 
101  return theme;
102  }
103 
104  // compare theme tags
106  {
107  for (int i = 0; i < vector3Themes.Length; ++i)
108  {
109  if (vector3Themes[i].Tag == tag)
110  {
111  return vector3Themes[i];
112  }
113  }
114 
115  return null;
116  }
117 
124  {
125  // search locally
126  TextureInteractiveTheme[] textureThemes = InteractiveHost.GetComponentsInChildren<TextureInteractiveTheme>();
127  TextureInteractiveTheme theme = FindTextureTheme(textureThemes, tag);
128 
129  // search globally
130  if (theme == null)
131  {
132  textureThemes = FindObjectsOfType<TextureInteractiveTheme>();
133  theme = FindTextureTheme(textureThemes, tag);
134  }
135 
136  if (!mThemeUpdated) mThemeUpdated = theme != null;
137 
138  return theme;
139  }
140 
141  // compare theme tags
143  {
144  for (int i = 0; i < textureThemes.Length; ++i)
145  {
146  if (textureThemes[i].Tag == tag)
147  {
148  return textureThemes[i];
149  }
150  }
151 
152  return null;
153  }
154  }
155 }
InteractiveState can exist on a child element of the game object containing the Interactive component...
ColorInteractiveTheme GetColorTheme(string tag)
Find a ColorInteractiveTheme by tag
void RefreshIfNeeded()
If the themes have changed since the last SetState was called, update the widget
Vector3InteractiveTheme GetVector3Theme(string tag)
Find a Vector3InteractiveTheme by tag
TextureInteractiveTheme GetTextureTheme(string tag)
Find a TextureInteractiveTheme by tag
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 ...
override void SetState(Interactive.ButtonStateEnum state)
Sets the state of the widget
Vector3InteractiveTheme FindVector3Theme(Vector3InteractiveTheme[] vector3Themes, string tag)
Interactive exposes basic button type events to the Unity Editor and receives messages from the Gestu...
Definition: Interactive.cs:22
TextureInteractiveTheme FindTextureTheme(TextureInteractiveTheme[] textureThemes, string tag)