@@ -57,14 +57,12 @@ private void Update()
57
57
58
58
listInputDevicesTextMesh . text = $ "Detected { sourceCount } input source{ ( sourceCount > 1 ? "s:" : sourceCount != 0 ? ":" : "s" ) } \n ";
59
59
60
+ bool collectionNeedsUpdating = false ;
61
+
60
62
for ( int i = displayFeatureUsagesTextMeshes . Count ; i < sourceCount ; i ++ )
61
63
{
62
64
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 ;
68
66
}
69
67
70
68
for ( int i = 0 ; i < displayFeatureUsagesTextMeshes . Count ; i ++ )
@@ -80,15 +78,15 @@ private void Update()
80
78
if ( textMesh . transform . parent . gameObject . activeSelf )
81
79
{
82
80
textMesh . transform . parent . gameObject . SetActive ( false ) ;
83
- gridObjectCollection . UpdateCollection ( ) ;
81
+ collectionNeedsUpdating = true ;
84
82
}
85
83
continue ;
86
84
}
87
85
88
86
if ( ! textMesh . transform . parent . gameObject . activeSelf )
89
87
{
90
88
textMesh . transform . parent . gameObject . SetActive ( true ) ;
91
- gridObjectCollection . UpdateCollection ( ) ;
89
+ collectionNeedsUpdating = true ;
92
90
}
93
91
94
92
InputDevice inputDevice = inputDevices [ i ] ;
@@ -169,6 +167,11 @@ private void Update()
169
167
}
170
168
}
171
169
}
170
+
171
+ if ( collectionNeedsUpdating )
172
+ {
173
+ gridObjectCollection . UpdateCollection ( ) ;
174
+ }
172
175
#else
173
176
listInputDevicesTextMesh . text = $ "This feature is only supported on Unity 2019.3 or newer.";
174
177
#endif // UNITY_2019_3_OR_NEWER
0 commit comments