AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
ButtonThemeWidgetLabel.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 UnityEngine;
5 using System.Collections;
7 using System;
8 
9 namespace HoloToolkit.Examples.InteractiveElements
10 {
15  {
16  [Tooltip("LabelTheme for switching the default and selected labels")]
18 
19  [Tooltip("tag for the color theme")]
20  public string ColorThemeTag = "defaultColor";
21 
22  [Tooltip("tag for the position theme")]
23  public string PositionThemeTag = "defaultPosition";
24 
25  [Tooltip("position animation component: optional")]
27 
28  // themes
29  private ColorInteractiveTheme mColorTheme;
30  private Vector3InteractiveTheme mPositionTheme;
31 
32  // the TextMesh
33  private TextMesh mText;
34 
35  private string mCheckColorThemeTag = "";
36  private string mCheckPositionThemeTag = "";
37 
41  private void Awake()
42  {
43  if (MovePosition == null)
44  {
45  MovePosition = GetComponent<MoveToPosition>();
46  }
47 
48  mText = this.gameObject.GetComponent<TextMesh>();
49  }
50 
51  private void Start()
52  {
53  SetTheme();
54  RefreshIfNeeded();
55  }
56 
57  public override void SetTheme()
58  {
59  if (ColorThemeTag != "")
60  {
61  mColorTheme = GetColorTheme(ColorThemeTag);
62  mCheckColorThemeTag = ColorThemeTag;
63  }
64 
65  if (PositionThemeTag != "")
66  {
67  mPositionTheme = GetVector3Theme(PositionThemeTag);
68  mCheckPositionThemeTag = PositionThemeTag;
69  }
70  }
71 
76  public override void SetState(Interactive.ButtonStateEnum state)
77  {
78  base.SetState(state);
79 
80  if (mText != null)
81  {
82  if (mColorTheme != null)
83  {
84  mText.color = mColorTheme.GetThemeValue(state);
85  }
86 
87  if (ButtonLabels != null)
88  {
89  if (InteractiveHost.IsSelected)
90  {
91  if (ButtonLabels.Selected != "")
92  {
93  mText.text = ButtonLabels.Selected;
94  }
95  else
96  {
97  mText.text = ButtonLabels.Default;
98  }
99  }
100  else
101  {
102  mText.text = ButtonLabels.Default;
103  }
104  }
105  }
106 
107  if (mPositionTheme != null)
108  {
109  if (MovePosition != null)
110  {
111  MovePosition.TargetValue = mPositionTheme.GetThemeValue(state);
112  MovePosition.StartRunning();
113  }
114  else
115  {
116  transform.localPosition = mPositionTheme.GetThemeValue(state);
117  }
118  }
119  }
120 
121  private void Update()
122  {
123  if (!mCheckPositionThemeTag.Equals(PositionThemeTag) || !mCheckColorThemeTag.Equals(ColorThemeTag))
124  {
125  SetTheme();
126  RefreshIfNeeded();
127  }
128  }
129  }
130 }
Type GetThemeValue(Interactive.ButtonStateEnum state)
A position animation component that supports easing and local position The animation can be triggered...
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 ...
A theme for handling the label string on the toggle button
Definition: LabelTheme.cs:13
override void SetState(Interactive.ButtonStateEnum state)
Set colors, position and label text
override void SetTheme()
Sets the themes based on the Theme Tags
Interactive exposes basic button type events to the Unity Editor and receives messages from the Gestu...
Definition: Interactive.cs:22
updates the button label color, position, and text based on Interactive state