@@ -22,8 +22,8 @@ public class TransformTree : ICellPoolDataSource<TransformCell>
22
22
// - Remove(object)
23
23
// - set_Item[object]
24
24
// These two methods have extremely bad performance due to using IndexOfKey(), which iterates the whole dictionary.
25
- // Currently we do not use either of these methods, so everything should be constant time hash lookups.
26
- // We DO make use of get_Item[object], get_Item[index], Add, Insert and RemoveAt, which OrderedDictionary perfectly meets our needs for.
25
+ // Currently we do not use either of these methods, so everything should be constant time lookups.
26
+ // We DO make use of get_Item[object], get_Item[index], Add, Insert, Contains and RemoveAt, which OrderedDictionary meets our needs for.
27
27
/// <summary>
28
28
/// Key: UnityEngine.Transform instance ID<br/>
29
29
/// Value: CachedTransform
@@ -182,25 +182,25 @@ public void RefreshData(bool andRefreshUI, bool jumpToTop, bool stopExistingCoro
182
182
traversedThisFrame . Reset ( ) ;
183
183
traversedThisFrame . Start ( ) ;
184
184
185
- IEnumerable < GameObject > rootObjects = GetRootEntriesMethod . Invoke ( ) ;
186
-
187
- refreshCoroutine = RuntimeHelper . StartCoroutine ( RefreshCoroutine ( rootObjects , andRefreshUI , jumpToTop , oneShot ) ) ;
185
+ refreshCoroutine = RuntimeHelper . StartCoroutine ( RefreshCoroutine ( andRefreshUI , jumpToTop , oneShot ) ) ;
188
186
}
189
187
190
- // Coroutine for batched updates, max 2000 gameobjects per frame so FPS doesn't get tanked when there is like 100k gameobjects.
191
- // if "oneShot", then this will NOT be batched (if we need an immediate full update).
192
- IEnumerator RefreshCoroutine ( IEnumerable < GameObject > rootObjects , bool andRefreshUI , bool jumpToTop , bool oneShot )
188
+ IEnumerator RefreshCoroutine ( bool andRefreshUI , bool jumpToTop , bool oneShot )
193
189
{
190
+ // Instead of doing string.IsNullOrEmpty(CurrentFilter) many times, let's just do it once per update.
191
+ bool filtering = Filtering ;
192
+
193
+ IEnumerable < GameObject > rootObjects = GetRootEntriesMethod ( ) ;
194
194
foreach ( var gameObj in rootObjects )
195
195
{
196
- if ( gameObj )
196
+ if ( ! gameObj )
197
+ continue ;
198
+
199
+ IEnumerator enumerator = Traverse ( gameObj . transform , null , 0 , oneShot , filtering ) ;
200
+ while ( enumerator . MoveNext ( ) )
197
201
{
198
- var enumerator = Traverse ( gameObj . transform , null , 0 , oneShot ) ;
199
- while ( enumerator . MoveNext ( ) )
200
- {
201
- if ( ! oneShot )
202
- yield return enumerator . Current ;
203
- }
202
+ if ( ! oneShot )
203
+ yield return enumerator . Current ;
204
204
}
205
205
}
206
206
@@ -224,7 +224,7 @@ IEnumerator RefreshCoroutine(IEnumerable<GameObject> rootObjects, bool andRefres
224
224
225
225
// Recursive method to check a Transform and its children (if expanded).
226
226
// Parent and depth can be null/default.
227
- private IEnumerator Traverse ( Transform transform , CachedTransform parent , int depth , bool oneShot )
227
+ private IEnumerator Traverse ( Transform transform , CachedTransform parent , int depth , bool oneShot , bool filtering )
228
228
{
229
229
// Let's only tank 2ms of each frame (60->53fps)
230
230
if ( traversedThisFrame . ElapsedMilliseconds > 2 )
@@ -236,21 +236,20 @@ private IEnumerator Traverse(Transform transform, CachedTransform parent, int de
236
236
237
237
int instanceID = transform . GetInstanceID ( ) ;
238
238
239
+ // Unlikely, but since this method is async it could theoretically happen in extremely rare circumstances
239
240
if ( visited . Contains ( instanceID ) )
240
241
yield break ;
241
242
242
- if ( Filtering )
243
+ if ( filtering )
243
244
{
244
245
if ( ! FilterHierarchy ( transform ) )
245
246
yield break ;
246
247
247
- visited . Add ( instanceID ) ;
248
-
249
248
if ( ! autoExpandedIDs . Contains ( instanceID ) )
250
249
autoExpandedIDs . Add ( instanceID ) ;
251
250
}
252
- else
253
- visited . Add ( instanceID ) ;
251
+
252
+ visited . Add ( instanceID ) ;
254
253
255
254
CachedTransform cached ;
256
255
if ( cachedTransforms . Contains ( instanceID ) )
@@ -286,9 +285,11 @@ private IEnumerator Traverse(Transform transform, CachedTransform parent, int de
286
285
287
286
if ( IsTransformExpanded ( instanceID ) && cached . Value . childCount > 0 )
288
287
{
288
+ ExplorerCore . Log ( $ "Traversing expanded transform { cached . Value . name } ({ cached . InstanceID } )") ;
289
+
289
290
for ( int i = 0 ; i < transform . childCount ; i ++ )
290
291
{
291
- var enumerator = Traverse ( transform . GetChild ( i ) , cached , depth + 1 , oneShot ) ;
292
+ var enumerator = Traverse ( transform . GetChild ( i ) , cached , depth + 1 , oneShot , filtering ) ;
292
293
while ( enumerator . MoveNext ( ) )
293
294
{
294
295
if ( ! oneShot )
@@ -317,7 +318,7 @@ public void SetCell(TransformCell cell, int index)
317
318
{
318
319
if ( index < cachedTransforms . Count )
319
320
{
320
- cell . ConfigureCell ( ( CachedTransform ) cachedTransforms [ index ] , index ) ;
321
+ cell . ConfigureCell ( ( CachedTransform ) cachedTransforms [ index ] ) ;
321
322
if ( Filtering )
322
323
{
323
324
if ( cell . cachedTransform . Name . ContainsIgnoreCase ( currentFilter ) )
@@ -345,6 +346,8 @@ private void OnGameObjectClicked(GameObject obj)
345
346
346
347
public void OnCellExpandToggled ( CachedTransform cache )
347
348
{
349
+ ExplorerCore . Log ( $ "OnCellExpandToggled: { cache . Value . name } ({ cache . InstanceID } )") ;
350
+
348
351
var instanceID = cache . InstanceID ;
349
352
if ( expandedInstanceIDs . Contains ( instanceID ) )
350
353
expandedInstanceIDs . Remove ( instanceID ) ;
0 commit comments