Skip to content

Commit 0e2df25

Browse files
committed
Fixing widgets not updating states when Interactive has selection on start.
1 parent d383aca commit 0e2df25

File tree

10 files changed

+244
-539
lines changed

10 files changed

+244
-539
lines changed

Assets/HoloToolkit-Examples/InteractiveElements/Scenes/WidgetBugFixes.unity

Lines changed: 0 additions & 515 deletions
This file was deleted.

Assets/HoloToolkit-Examples/InteractiveElements/Scripts/Controls/ButtonThemeWidget.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEngine;
55
using System.Collections;
66
using HoloToolkit.Examples.Prototyping;
7+
using System;
78

89
namespace HoloToolkit.Examples.InteractiveElements
910
{
@@ -30,6 +31,9 @@ public class ButtonThemeWidget : InteractiveThemeWidget
3031
[Tooltip("scale animation component: optional")]
3132
public ScaleToValue ScaleSize;
3233

34+
[Tooltip("Upate the widget's theme and refresh if the theme tag changes")]
35+
public bool WatchForThemeChange = false;
36+
3337
// themes
3438
private ColorInteractiveTheme mColorTheme;
3539
private Vector3InteractiveTheme mPositionTheme;
@@ -38,6 +42,10 @@ public class ButtonThemeWidget : InteractiveThemeWidget
3842
// material
3943
private Material mMaterial;
4044

45+
private string mCheckColorThemeTag;
46+
private string mCheckPositionThemeTag;
47+
private string mCheckScaleThemeTag;
48+
4149
/// <summary>
4250
/// Get animaiton components
4351
/// </summary>
@@ -67,20 +75,29 @@ private void Awake()
6775
}
6876

6977
private void Start()
78+
{
79+
SetTheme();
80+
RefreshIfNeeded();
81+
}
82+
83+
public override void SetTheme()
7084
{
7185
if (ColorThemeTag != "")
7286
{
7387
mColorTheme = GetColorTheme(ColorThemeTag);
88+
mCheckColorThemeTag = ColorThemeTag;
7489
}
7590

7691
if (PositionThemeTag != "")
7792
{
7893
mPositionTheme = GetVector3Theme(PositionThemeTag);
94+
mCheckPositionThemeTag = PositionThemeTag;
7995
}
8096

8197
if (ScaleThemeTag != "")
8298
{
8399
mScaleTheme = GetVector3Theme(ScaleThemeTag);
100+
mCheckScaleThemeTag = ScaleThemeTag;
84101
}
85102
}
86103

@@ -131,6 +148,15 @@ public override void SetState(Interactive.ButtonStateEnum state)
131148
}
132149
}
133150

151+
private void Update()
152+
{
153+
if(WatchForThemeChange && (!mCheckScaleThemeTag.Equals(ScaleThemeTag) || !mCheckPositionThemeTag.Equals(PositionThemeTag) || !mCheckColorThemeTag.Equals(ColorThemeTag)))
154+
{
155+
SetTheme();
156+
RefreshIfNeeded();
157+
}
158+
}
159+
134160
/// <summary>
135161
/// clean up if material was created dynamically
136162
/// </summary>

Assets/HoloToolkit-Examples/InteractiveElements/Scripts/Controls/ButtonThemeWidgetLabel.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEngine;
55
using System.Collections;
66
using HoloToolkit.Examples.Prototyping;
7+
using System;
78

89
namespace HoloToolkit.Examples.InteractiveElements
910
{
@@ -24,12 +25,18 @@ public class ButtonThemeWidgetLabel : InteractiveThemeWidget
2425
[Tooltip("position animation component: optional")]
2526
public MoveToPosition MovePosition;
2627

28+
[Tooltip("Upate the widget's theme and refresh if the theme tag changes")]
29+
public bool WatchForThemeChange = false;
30+
2731
// themes
2832
private ColorInteractiveTheme mColorTheme;
2933
private Vector3InteractiveTheme mPositionTheme;
3034

3135
// the TextMesh
3236
private TextMesh mText;
37+
38+
private string mCheckColorThemeTag;
39+
private string mCheckPositionThemeTag;
3340

3441
/// <summary>
3542
/// Get the TextMesh and position animation component
@@ -45,15 +52,23 @@ private void Awake()
4552
}
4653

4754
private void Start()
55+
{
56+
SetTheme();
57+
RefreshIfNeeded();
58+
}
59+
60+
public override void SetTheme()
4861
{
4962
if (ColorThemeTag != "")
5063
{
5164
mColorTheme = GetColorTheme(ColorThemeTag);
65+
mCheckColorThemeTag = ColorThemeTag;
5266
}
5367

5468
if (PositionThemeTag != "")
5569
{
5670
mPositionTheme = GetVector3Theme(PositionThemeTag);
71+
mCheckPositionThemeTag = PositionThemeTag;
5772
}
5873
}
5974

@@ -105,5 +120,14 @@ public override void SetState(Interactive.ButtonStateEnum state)
105120
}
106121
}
107122
}
123+
124+
private void Update()
125+
{
126+
if (WatchForThemeChange && (!mCheckPositionThemeTag.Equals(PositionThemeTag) || !mCheckColorThemeTag.Equals(ColorThemeTag)))
127+
{
128+
SetTheme();
129+
RefreshIfNeeded();
130+
}
131+
}
108132
}
109133
}

Assets/HoloToolkit-Examples/InteractiveElements/Scripts/Controls/ButtonThemeWidgetOutline.cs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using UnityEngine;
55
using System.Collections;
66
using HoloToolkit.Examples.Prototyping;
7+
using System;
78

89
namespace HoloToolkit.Examples.InteractiveElements
910
{
@@ -28,9 +29,15 @@ public class ButtonThemeWidgetOutline : InteractiveThemeWidget
2829
[Tooltip("A color tween component : required, but could be on a different object")]
2930
public ColorTransition ColorBlender;
3031

31-
private ColorInteractiveTheme mInnterColorTheme;
32+
[Tooltip("Upate the widget's theme and refresh if the theme tag changes")]
33+
public bool WatchForThemeChange = false;
34+
35+
private ColorInteractiveTheme mInnerColorTheme;
3236
private ColorInteractiveTheme mOuterColorTheme;
33-
37+
38+
private string mCheckInnerColorThemeTag;
39+
private string mCheckOuterColorThemeTag;
40+
3441
/// <summary>
3542
/// set the ColorBlender
3643
/// </summary>
@@ -52,15 +59,23 @@ private void Awake()
5259
/// get the themes
5360
/// </summary>
5461
private void Start()
62+
{
63+
SetTheme();
64+
RefreshIfNeeded();
65+
}
66+
67+
public override void SetTheme()
5568
{
5669
if (InnerColorThemeTag != "")
5770
{
58-
mInnterColorTheme = GetColorTheme(InnerColorThemeTag);
71+
mInnerColorTheme = GetColorTheme(InnerColorThemeTag);
72+
mCheckInnerColorThemeTag = InnerColorThemeTag;
5973
}
6074

6175
if (OuterColorThemeTag != "")
6276
{
6377
mOuterColorTheme = GetColorTheme(OuterColorThemeTag);
78+
mCheckOuterColorThemeTag = OuterColorThemeTag;
6479
}
6580
}
6681

@@ -72,15 +87,24 @@ public override void SetState(Interactive.ButtonStateEnum state)
7287
{
7388
base.SetState(state);
7489

75-
if (mInnterColorTheme != null)
90+
if (mInnerColorTheme != null)
7691
{
77-
ColorBlender.StartTransition(mInnterColorTheme.GetThemeValue(state), InnerMaterial.name);
92+
ColorBlender.StartTransition(mInnerColorTheme.GetThemeValue(state), InnerMaterial.name);
7893
}
7994

8095
if (mOuterColorTheme != null)
8196
{
8297
ColorBlender.StartTransition(mOuterColorTheme.GetThemeValue(state), OuterMaterial.name);
8398
}
8499
}
100+
101+
private void Update()
102+
{
103+
if (WatchForThemeChange && (!mCheckOuterColorThemeTag.Equals(OuterColorThemeTag) || !mCheckInnerColorThemeTag.Equals(InnerColorThemeTag)))
104+
{
105+
SetTheme();
106+
RefreshIfNeeded();
107+
}
108+
}
85109
}
86110
}

Assets/HoloToolkit-Examples/InteractiveElements/Scripts/Widgets/InteractiveThemeWidget.cs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,35 @@ namespace HoloToolkit.Examples.InteractiveElements
1010
/// <summary>
1111
/// A version of InteractiveWidget that uses an InteractiveTheme to define each state
1212
/// </summary>
13-
public class InteractiveThemeWidget : InteractiveWidget
13+
public abstract class InteractiveThemeWidget : InteractiveWidget
1414
{
15+
// checks if the theme has changed since the last SetState was called.
16+
protected bool mThemeUpdated;
1517

16-
public virtual void SetTheme(object theme)
18+
/// <summary>
19+
/// Sets the themes based on the Theme Tags
20+
/// </summary>
21+
public abstract void SetTheme();
22+
23+
/// <summary>
24+
/// If the themes have changed since the last SetState was called, update the widget
25+
/// </summary>
26+
public void RefreshIfNeeded()
1727
{
18-
// use abstract class
28+
if (mThemeUpdated)
29+
{
30+
SetState(State);
31+
}
32+
}
33+
34+
/// <summary>
35+
/// Sets the state of the widget
36+
/// </summary>
37+
/// <param name="state"></param>
38+
public override void SetState(Interactive.ButtonStateEnum state)
39+
{
40+
base.SetState(state);
41+
mThemeUpdated = false;
1942
}
2043

2144
/// <summary>
@@ -36,6 +59,8 @@ public ColorInteractiveTheme GetColorTheme(string tag)
3659
theme = FindColorTheme(colorThemes, tag);
3760
}
3861

62+
if (!mThemeUpdated) mThemeUpdated = theme != null;
63+
3964
return theme;
4065
}
4166

@@ -71,6 +96,8 @@ public Vector3InteractiveTheme GetVector3Theme(string tag)
7196
theme = FindVector3Theme(vector3Themes, tag);
7297
}
7398

99+
if (!mThemeUpdated) mThemeUpdated = theme != null;
100+
74101
return theme;
75102
}
76103

@@ -106,6 +133,8 @@ public TextureInteractiveTheme GetTextureTheme(string tag)
106133
theme = FindTextureTheme(textureThemes, tag);
107134
}
108135

136+
if (!mThemeUpdated) mThemeUpdated = theme != null;
137+
109138
return theme;
110139
}
111140

Assets/HoloToolkit-Examples/InteractiveElements/Scripts/Widgets/MaterialColorThemeWidget.cs

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections;
66
using System.Collections.Generic;
77
using UnityEngine;
8+
using System;
89

910
namespace HoloToolkit.Examples.InteractiveElements
1011
{
@@ -19,8 +20,13 @@ public class MaterialColorThemeWidget : InteractiveThemeWidget
1920
[Tooltip("A component for color transitions: optional")]
2021
public ColorTransition ColorBlender;
2122

22-
protected ColorInteractiveTheme mColorTheme;
23-
protected Material mMaterial;
23+
[Tooltip("Upate the widget's theme and refresh if the theme tag changes")]
24+
public bool WatchForThemeChange = false;
25+
26+
private ColorInteractiveTheme mColorTheme;
27+
private Material mMaterial;
28+
29+
private string mCheckThemeTag;
2430

2531
void Awake()
2632
{
@@ -47,9 +53,16 @@ private void Start()
4753
{
4854
if (mColorTheme == null)
4955
{
50-
mColorTheme = GetColorTheme(ThemeTag);
51-
SetState(State);
56+
SetTheme();
5257
}
58+
59+
RefreshIfNeeded();
60+
}
61+
62+
public override void SetTheme()
63+
{
64+
mColorTheme = GetColorTheme(ThemeTag);
65+
mCheckThemeTag = ThemeTag;
5366
}
5467

5568
/// <summary>
@@ -73,6 +86,15 @@ public override void SetState(Interactive.ButtonStateEnum state)
7386
}
7487
}
7588

89+
private void Update()
90+
{
91+
if (WatchForThemeChange && (!mCheckThemeTag.Equals(ThemeTag)))
92+
{
93+
SetTheme();
94+
RefreshIfNeeded();
95+
}
96+
}
97+
7698
/// <summary>
7799
/// Clean up the materal is created dynamically
78100
/// </summary>

0 commit comments

Comments
 (0)