mirror of
https://github.com/Outer-Wilds-New-Horizons/new-horizons.git
synced 2025-12-11 20:15:44 +01:00
search utilities fast and slow path
This commit is contained in:
parent
6da9071208
commit
6be9150223
@ -1,7 +1,10 @@
|
|||||||
|
#define ENABLE_PROFILER
|
||||||
|
|
||||||
using NewHorizons.Utility.OWML;
|
using NewHorizons.Utility.OWML;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.Profiling;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
@ -116,13 +119,17 @@ namespace NewHorizons.Utility
|
|||||||
if (CachedGameObjects.TryGetValue(path, out var go)) return go;
|
if (CachedGameObjects.TryGetValue(path, out var go)) return go;
|
||||||
|
|
||||||
// 1: normal find
|
// 1: normal find
|
||||||
|
Profiler.BeginSample("1");
|
||||||
go = GameObject.Find(path);
|
go = GameObject.Find(path);
|
||||||
if (go)
|
if (go)
|
||||||
{
|
{
|
||||||
CachedGameObjects.Add(path, go);
|
CachedGameObjects.Add(path, go);
|
||||||
|
Profiler.EndSample();
|
||||||
return go;
|
return go;
|
||||||
}
|
}
|
||||||
|
Profiler.EndSample();
|
||||||
|
|
||||||
|
Profiler.BeginSample("1");
|
||||||
// 2: find inactive using root + transform.find
|
// 2: find inactive using root + transform.find
|
||||||
var names = path.Split('/');
|
var names = path.Split('/');
|
||||||
|
|
||||||
@ -142,9 +149,12 @@ namespace NewHorizons.Utility
|
|||||||
if (go)
|
if (go)
|
||||||
{
|
{
|
||||||
CachedGameObjects.Add(path, go);
|
CachedGameObjects.Add(path, go);
|
||||||
|
Profiler.EndSample();
|
||||||
return go;
|
return go;
|
||||||
}
|
}
|
||||||
|
Profiler.EndSample();
|
||||||
|
|
||||||
|
Profiler.BeginSample("3");
|
||||||
var name = names.Last();
|
var name = names.Last();
|
||||||
if (warn) NHLogger.LogWarning($"Couldn't find object in path {path}, will look for potential matches for name {name}");
|
if (warn) NHLogger.LogWarning($"Couldn't find object in path {path}, will look for potential matches for name {name}");
|
||||||
// 3: find resource to include inactive objects (but skip prefabs)
|
// 3: find resource to include inactive objects (but skip prefabs)
|
||||||
@ -153,10 +163,12 @@ namespace NewHorizons.Utility
|
|||||||
if (go)
|
if (go)
|
||||||
{
|
{
|
||||||
CachedGameObjects.Add(path, go);
|
CachedGameObjects.Add(path, go);
|
||||||
|
Profiler.EndSample();
|
||||||
return go;
|
return go;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (warn) NHLogger.LogWarning($"Couldn't find object with name {name}");
|
if (warn) NHLogger.LogWarning($"Couldn't find object with name {name}");
|
||||||
|
Profiler.EndSample();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user