Skip to content

Commit f041cda

Browse files
Merge pull request #832 from killerantz/dev/interactiveThemeWidgetFixes
Dev/interactive theme widget fixes
2 parents 53243e3 + 620472f commit f041cda

File tree

10 files changed

+227
-22
lines changed

10 files changed

+227
-22
lines changed

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

Lines changed: 23 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
{
@@ -38,6 +39,10 @@ public class ButtonThemeWidget : InteractiveThemeWidget
3839
// material
3940
private Material mMaterial;
4041

42+
private string mCheckColorThemeTag = "";
43+
private string mCheckPositionThemeTag = "";
44+
private string mCheckScaleThemeTag = "";
45+
4146
/// <summary>
4247
/// Get animaiton components
4348
/// </summary>
@@ -67,20 +72,29 @@ private void Awake()
6772
}
6873

6974
private void Start()
75+
{
76+
SetTheme();
77+
RefreshIfNeeded();
78+
}
79+
80+
public override void SetTheme()
7081
{
7182
if (ColorThemeTag != "")
7283
{
7384
mColorTheme = GetColorTheme(ColorThemeTag);
85+
mCheckColorThemeTag = ColorThemeTag;
7486
}
7587

7688
if (PositionThemeTag != "")
7789
{
7890
mPositionTheme = GetVector3Theme(PositionThemeTag);
91+
mCheckPositionThemeTag = PositionThemeTag;
7992
}
8093

8194
if (ScaleThemeTag != "")
8295
{
8396
mScaleTheme = GetVector3Theme(ScaleThemeTag);
97+
mCheckScaleThemeTag = ScaleThemeTag;
8498
}
8599
}
86100

@@ -131,6 +145,15 @@ public override void SetState(Interactive.ButtonStateEnum state)
131145
}
132146
}
133147

148+
private void Update()
149+
{
150+
if(!mCheckScaleThemeTag.Equals(ScaleThemeTag) || !mCheckPositionThemeTag.Equals(PositionThemeTag) || !mCheckColorThemeTag.Equals(ColorThemeTag))
151+
{
152+
SetTheme();
153+
RefreshIfNeeded();
154+
}
155+
}
156+
134157
/// <summary>
135158
/// clean up if material was created dynamically
136159
/// </summary>

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

Lines changed: 21 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 ButtonThemeWidgetLabel : InteractiveThemeWidget
3031

3132
// the TextMesh
3233
private TextMesh mText;
34+
35+
private string mCheckColorThemeTag = "";
36+
private string mCheckPositionThemeTag = "";
3337

3438
/// <summary>
3539
/// Get the TextMesh and position animation component
@@ -45,15 +49,23 @@ private void Awake()
4549
}
4650

4751
private void Start()
52+
{
53+
SetTheme();
54+
RefreshIfNeeded();
55+
}
56+
57+
public override void SetTheme()
4858
{
4959
if (ColorThemeTag != "")
5060
{
5161
mColorTheme = GetColorTheme(ColorThemeTag);
62+
mCheckColorThemeTag = ColorThemeTag;
5263
}
5364

5465
if (PositionThemeTag != "")
5566
{
5667
mPositionTheme = GetVector3Theme(PositionThemeTag);
68+
mCheckPositionThemeTag = PositionThemeTag;
5769
}
5870
}
5971

@@ -105,5 +117,14 @@ public override void SetState(Interactive.ButtonStateEnum state)
105117
}
106118
}
107119
}
120+
121+
private void Update()
122+
{
123+
if (!mCheckPositionThemeTag.Equals(PositionThemeTag) || !mCheckColorThemeTag.Equals(ColorThemeTag))
124+
{
125+
SetTheme();
126+
RefreshIfNeeded();
127+
}
128+
}
108129
}
109130
}

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

Lines changed: 26 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,12 @@ 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+
private ColorInteractiveTheme mInnerColorTheme;
3233
private ColorInteractiveTheme mOuterColorTheme;
33-
34+
35+
private string mCheckInnerColorThemeTag = "";
36+
private string mCheckOuterColorThemeTag = "";
37+
3438
/// <summary>
3539
/// set the ColorBlender
3640
/// </summary>
@@ -52,15 +56,23 @@ private void Awake()
5256
/// get the themes
5357
/// </summary>
5458
private void Start()
59+
{
60+
SetTheme();
61+
RefreshIfNeeded();
62+
}
63+
64+
public override void SetTheme()
5565
{
5666
if (InnerColorThemeTag != "")
5767
{
58-
mInnterColorTheme = GetColorTheme(InnerColorThemeTag);
68+
mInnerColorTheme = GetColorTheme(InnerColorThemeTag);
69+
mCheckInnerColorThemeTag = InnerColorThemeTag;
5970
}
6071

6172
if (OuterColorThemeTag != "")
6273
{
6374
mOuterColorTheme = GetColorTheme(OuterColorThemeTag);
75+
mCheckOuterColorThemeTag = OuterColorThemeTag;
6476
}
6577
}
6678

@@ -72,15 +84,24 @@ public override void SetState(Interactive.ButtonStateEnum state)
7284
{
7385
base.SetState(state);
7486

75-
if (mInnterColorTheme != null)
87+
if (mInnerColorTheme != null)
7688
{
77-
ColorBlender.StartTransition(mInnterColorTheme.GetThemeValue(state), InnerMaterial.name);
89+
ColorBlender.StartTransition(mInnerColorTheme.GetThemeValue(state), InnerMaterial.name);
7890
}
7991

8092
if (mOuterColorTheme != null)
8193
{
8294
ColorBlender.StartTransition(mOuterColorTheme.GetThemeValue(state), OuterMaterial.name);
8395
}
8496
}
97+
98+
private void Update()
99+
{
100+
if (!mCheckOuterColorThemeTag.Equals(OuterColorThemeTag) || !mCheckInnerColorThemeTag.Equals(InnerColorThemeTag))
101+
{
102+
SetTheme();
103+
RefreshIfNeeded();
104+
}
105+
}
85106
}
86107
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ public override void ManipulationUpdate(Vector3 startGesturePosition, Vector3 cu
151151

152152
// get the current delta
153153
float delta = (CurrentDistance > 0) ? CurrentPercentage : -CurrentPercentage;
154-
print(delta);
155154

156155
// combine the delta with the current slider position so the slider does not start over every time
157156
mDeltaValue = Mathf.Clamp01(delta + mCachedValue);

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

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,37 @@ 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;
17+
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()
27+
{
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;
42+
}
43+
1544
/// <summary>
1645
/// Find a ColorInteractiveTheme by tag
1746
/// </summary>
@@ -30,6 +59,8 @@ public ColorInteractiveTheme GetColorTheme(string tag)
3059
theme = FindColorTheme(colorThemes, tag);
3160
}
3261

62+
if (!mThemeUpdated) mThemeUpdated = theme != null;
63+
3364
return theme;
3465
}
3566

@@ -65,6 +96,8 @@ public Vector3InteractiveTheme GetVector3Theme(string tag)
6596
theme = FindVector3Theme(vector3Themes, tag);
6697
}
6798

99+
if (!mThemeUpdated) mThemeUpdated = theme != null;
100+
68101
return theme;
69102
}
70103

@@ -100,6 +133,8 @@ public TextureInteractiveTheme GetTextureTheme(string tag)
100133
theme = FindTextureTheme(textureThemes, tag);
101134
}
102135

136+
if (!mThemeUpdated) mThemeUpdated = theme != null;
137+
103138
return theme;
104139
}
105140

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

Lines changed: 26 additions & 3 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,10 @@ 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+
private ColorInteractiveTheme mColorTheme;
24+
private Material mMaterial;
25+
26+
private string mCheckThemeTag = "";
2427

2528
void Awake()
2629
{
@@ -39,13 +42,24 @@ void Awake()
3942

4043
if (mMaterial != null && mColorTheme != null)
4144
{
42-
mMaterial.color = mColorTheme.GetThemeValue(Interactive.ButtonStateEnum.Default);
45+
mMaterial.color = mColorTheme.GetThemeValue(State);
4346
}
4447
}
4548

4649
private void Start()
50+
{
51+
if (mColorTheme == null)
52+
{
53+
SetTheme();
54+
}
55+
56+
RefreshIfNeeded();
57+
}
58+
59+
public override void SetTheme()
4760
{
4861
mColorTheme = GetColorTheme(ThemeTag);
62+
mCheckThemeTag = ThemeTag;
4963
}
5064

5165
/// <summary>
@@ -69,6 +83,15 @@ public override void SetState(Interactive.ButtonStateEnum state)
6983
}
7084
}
7185

86+
private void Update()
87+
{
88+
if (!mCheckThemeTag.Equals(ThemeTag))
89+
{
90+
SetTheme();
91+
RefreshIfNeeded();
92+
}
93+
}
94+
7295
/// <summary>
7396
/// Clean up the materal is created dynamically
7497
/// </summary>

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

Lines changed: 23 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
{
@@ -20,6 +21,8 @@ public class PositionThemeWidget : InteractiveThemeWidget
2021

2122
private Vector3InteractiveTheme mPositionTheme;
2223

24+
private string mCheckThemeTag = "";
25+
2326
/// <summary>
2427
/// Get Move to Position
2528
/// </summary>
@@ -35,8 +38,19 @@ private void Awake()
3538
/// Get the theme
3639
/// </summary>
3740
private void Start()
41+
{
42+
if (mPositionTheme == null)
43+
{
44+
SetTheme();
45+
}
46+
47+
RefreshIfNeeded();
48+
}
49+
50+
public override void SetTheme()
3851
{
3952
mPositionTheme = GetVector3Theme(ThemeTag);
53+
mCheckThemeTag = ThemeTag;
4054
}
4155

4256
/// <summary>
@@ -60,5 +74,14 @@ public override void SetState(Interactive.ButtonStateEnum state)
6074
}
6175
}
6276
}
77+
78+
private void Update()
79+
{
80+
if (!mCheckThemeTag.Equals(ThemeTag))
81+
{
82+
SetTheme();
83+
RefreshIfNeeded();
84+
}
85+
}
6386
}
6487
}

0 commit comments

Comments
 (0)