Skip to content

Commit 7fb4dba

Browse files
jonathoncobbVictor JiakeveleighRogPodge
authored
Add synchronous CloseImmediate() functions to IProgressIndicator (#10323)
* Add synchronous CloseImmediate() functions to IProgressIndicator Some UI in our application cannot be easily deactivated asynchronously. In particular, we determine the visibility of a child window based on if there are any active `GameObject` children. We've added a synchronous `CloseImmediate()` function to turn the `GameObject off immediately and set the appropriate state. * Add inheritdoc tags * orb color setting cleanup Co-authored-by: Victor Jia <[email protected]> Co-authored-by: Kurtis <[email protected]> Co-authored-by: Roger Liu <[email protected]>
1 parent 92009fc commit 7fb4dba

File tree

4 files changed

+69
-2
lines changed

4 files changed

+69
-2
lines changed

Assets/MRTK/SDK/Features/UX/Scripts/ProgressIndicators/IProgressIndicator.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,10 @@ public interface IProgressIndicator
4444
/// </summary>
4545
Task CloseAsync();
4646

47+
/// <summary>
48+
/// Closes the progress indicator immediately. No fade out animation. All gameObjects for the progress indicator are reset to the correct values.
49+
/// </summary>
50+
void CloseImmediate();
51+
4752
}
4853
}

Assets/MRTK/SDK/Features/UX/Scripts/ProgressIndicators/ProgressIndicatorLoadingBar.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,18 @@ public async Task CloseAsync()
9898
gameObject.SetActive(false);
9999
}
100100

101+
/// <inheritdoc/>
102+
public void CloseImmediate()
103+
{
104+
if (state != ProgressIndicatorState.Open)
105+
{
106+
throw new System.Exception("Can't close in state " + state);
107+
}
108+
109+
state = ProgressIndicatorState.Closed;
110+
gameObject.SetActive(false);
111+
}
112+
101113
/// <inheritdoc/>
102114
public async Task AwaitTransitionAsync()
103115
{

Assets/MRTK/SDK/Features/UX/Scripts/ProgressIndicators/ProgressIndicatorObjectDisplay.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,30 @@ public async Task CloseAsync()
145145
gameObject.SetActive(false);
146146
}
147147

148+
/// <inheritdoc/>
149+
public void CloseImmediate()
150+
{
151+
if (closeCurve.length == 0)
152+
{
153+
Debug.LogWarning("Open curve length is zero - this may result in an infinite loop.");
154+
}
155+
156+
float minScale = closeCurve.Evaluate(Mathf.Infinity);
157+
if (minScale > 0)
158+
{
159+
Debug.LogWarning("Open curve value never reaches 0 - this may result in an infinite loop.");
160+
}
161+
162+
if (state != ProgressIndicatorState.Open)
163+
{
164+
throw new System.Exception("Can't close in state " + state);
165+
}
166+
167+
scaleTargetObject.transform.localScale = Vector3.zero;
168+
state = ProgressIndicatorState.Closed;
169+
gameObject.SetActive(false);
170+
}
171+
148172
/// <inheritdoc/>
149173
public async Task AwaitTransitionAsync()
150174
{

Assets/MRTK/SDK/Features/UX/Scripts/ProgressIndicators/ProgressIndicatorOrbsRotator.cs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,19 @@ public async Task CloseAsync()
9191
}
9292

9393
state = ProgressIndicatorState.Closed;
94+
gameObject.SetActive(false);
95+
}
96+
97+
/// <inheritdoc/>
98+
public void CloseImmediate()
99+
{
100+
if (state != ProgressIndicatorState.Open)
101+
{
102+
throw new System.Exception("Can't close in state " + state);
103+
}
94104

105+
StopOrbsImmediately();
106+
state = ProgressIndicatorState.Closed;
95107
gameObject.SetActive(false);
96108
}
97109

@@ -130,7 +142,7 @@ private void StartOrbs()
130142

131143
for (int i = 0; i < orbs.Length; ++i)
132144
{
133-
propertyBlocks[i].SetColor("_Color", new Color(1, 1, 1, 1));
145+
propertyBlocks[i].SetColor("_Color", Color.white);
134146
dots[i].SetPropertyBlock(propertyBlocks[i]);
135147
orbs[i].transform.localRotation = Quaternion.identity;
136148
}
@@ -142,6 +154,20 @@ public void StopOrbs()
142154
rotationWhenStopped = angles[0];
143155
}
144156

157+
private void StopOrbsImmediately()
158+
{
159+
for (int i = 0; i < orbs.Length; ++i)
160+
{
161+
Color orbColor = propertyBlocks[i].GetColor("_Color");
162+
orbColor.a = 0.0f;
163+
propertyBlocks[i].SetColor("_Color", orbColor);
164+
dots[i].SetPropertyBlock(propertyBlocks[i]);
165+
orbs[i].transform.localRotation = Quaternion.identity;
166+
}
167+
168+
hasAnimationFinished = true;
169+
}
170+
145171
private void Awake()
146172
{
147173
angles = new float[orbs.Length];
@@ -151,7 +177,7 @@ private void Awake()
151177
for (int i = 0; i < orbs.Length; ++i)
152178
{
153179
propertyBlocks[i] = new MaterialPropertyBlock();
154-
propertyBlocks[i].SetColor("_Color", new Color(1, 1, 1, 1));
180+
propertyBlocks[i].SetColor("_Color", Color.white);
155181
dots[i] = orbs[i].transform.GetChild(0).gameObject.GetComponent<Renderer>();
156182
dots[i].SetPropertyBlock(propertyBlocks[i]);
157183
angles[i] = 0;

0 commit comments

Comments
 (0)