예제 #1
0
        public void Refresh(bool full, Predicate <GameObject> objectFilter)
        {
            if (_searchResults != null)
            {
                return;
            }

            if (_cachedRootGameObjects == null || full)
            {
                _cachedRootGameObjects = FindAllRootGameObjects().OrderBy(x => x.name, StringComparer.InvariantCultureIgnoreCase).ToList();
                full = true;
            }
            else
            {
                _cachedRootGameObjects.RemoveAll(o => o == null);
            }

            if (UnityFeatureHelper.SupportsScenes && !full)
            {
                var newItems = UnityFeatureHelper.GetSceneGameObjects().Except(_cachedRootGameObjects).ToList();
                if (newItems.Count > 0)
                {
                    _cachedRootGameObjects.AddRange(newItems);
                    _cachedRootGameObjects.Sort((o1, o2) => string.Compare(o1.name, o2.name, StringComparison.InvariantCultureIgnoreCase));
                }
            }

            if (objectFilter != null)
            {
                _cachedRootGameObjects.RemoveAll(objectFilter);
            }
        }
            public static bool Prefix(GameObjectSearcher __instance, bool full, Predicate <GameObject> objectFilter)
            {
                if (!disableSort.Value)
                {
                    return(true);
                }
                var _searchResults         = Traverse.Create(__instance).Field("_searchResults").GetValue <List <GameObject> >();
                var _cachedRootGameObjects = Traverse.Create(__instance).Field("_cachedRootGameObjects").GetValue <List <GameObject> >();

                if (_searchResults != null)
                {
                    return(false);
                }
                if (_cachedRootGameObjects == null || full)
                {
                    _cachedRootGameObjects = GameObjectSearcher.FindAllRootGameObjects().ToList();
                    full = true;
                }
                else
                {
                    _cachedRootGameObjects.RemoveAll((GameObject o) => o == null);
                }
                if (UnityFeatureHelper.SupportsScenes && !full)
                {
                    List <GameObject> list = UnityFeatureHelper.GetSceneGameObjects().Except(_cachedRootGameObjects).ToList <GameObject>();
                    if (list.Count > 0)
                    {
                        _cachedRootGameObjects.AddRange(list);
                    }
                }
                if (objectFilter != null)
                {
                    _cachedRootGameObjects.RemoveAll(objectFilter);
                }
                Traverse.Create(__instance).Field("_cachedRootGameObjects").SetValue(_cachedRootGameObjects);
                return(false);
            }