Skip to content

Commit 3798211

Browse files
committed
Rework collection updating to one place
1 parent 9bf6d19 commit 3798211

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

Assets/MRTK/Tools/RuntimeTools/Tools/InputFeatureUsageTool/ListInputFeatureUsages.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,12 @@ private void Update()
5757

5858
listInputDevicesTextMesh.text = $"Detected {sourceCount} input source{(sourceCount > 1 ? "s:" : sourceCount != 0 ? ":" : "s")}\n";
5959

60+
bool collectionNeedsUpdating = false;
61+
6062
for (int i = displayFeatureUsagesTextMeshes.Count; i < sourceCount; i++)
6163
{
6264
displayFeatureUsagesTextMeshes.Add(Instantiate(displayFeatureUsagesPrefab, gameObject.transform).GetComponentInChildren<TextMesh>());
63-
// For optimal performance, only update the collection when adding the final text panel
64-
if (i == sourceCount - 1)
65-
{
66-
gridObjectCollection.UpdateCollection();
67-
}
65+
collectionNeedsUpdating = true;
6866
}
6967

7068
for (int i = 0; i < displayFeatureUsagesTextMeshes.Count; i++)
@@ -80,15 +78,15 @@ private void Update()
8078
if (textMesh.transform.parent.gameObject.activeSelf)
8179
{
8280
textMesh.transform.parent.gameObject.SetActive(false);
83-
gridObjectCollection.UpdateCollection();
81+
collectionNeedsUpdating = true;
8482
}
8583
continue;
8684
}
8785

8886
if (!textMesh.transform.parent.gameObject.activeSelf)
8987
{
9088
textMesh.transform.parent.gameObject.SetActive(true);
91-
gridObjectCollection.UpdateCollection();
89+
collectionNeedsUpdating = true;
9290
}
9391

9492
InputDevice inputDevice = inputDevices[i];
@@ -169,6 +167,11 @@ private void Update()
169167
}
170168
}
171169
}
170+
171+
if (collectionNeedsUpdating)
172+
{
173+
gridObjectCollection.UpdateCollection();
174+
}
172175
#else
173176
listInputDevicesTextMesh.text = $"This feature is only supported on Unity 2019.3 or newer.";
174177
#endif // UNITY_2019_3_OR_NEWER

0 commit comments

Comments
 (0)