示例#1
0
        public List <CacheObjectBase> SearchSceneObjects(string _search)
        {
            var matches = new List <CacheObjectBase>();

            foreach (var obj in ResourcesUnstrip.FindObjectsOfTypeAll(ReflectionHelpers.GameObjectType))
            {
#if CPP
                var go = obj.TryCast <GameObject>();
#else
                var go = obj as GameObject;
#endif
                if (go.name.ToLower().Contains(_search.ToLower()) && go.scene.name == m_currentScene)
                {
                    matches.Add(CacheFactory.GetCacheObject(go));
                }
            }

            return(matches);
        }
示例#2
0
        public static void StartInspect()
        {
            Enabled = true;
            MainMenu.Instance.MainPanel.SetActive(false);
            s_UIContent.SetActive(true);

            // recache Graphic Raycasters each time we start
            var casters = ResourcesUnstrip.FindObjectsOfTypeAll(typeof(GraphicRaycaster));

            m_gCasters = new GraphicRaycaster[casters.Length];
            for (int i = 0; i < casters.Length; i++)
            {
#if CPP
                m_gCasters[i] = casters[i].TryCast <GraphicRaycaster>();
#else
                m_gCasters[i] = casters[i] as GraphicRaycaster;
#endif
            }
        }
示例#3
0
        private void Search()
        {
            //if (m_cachingResults)
            //{
            //    ExplorerCore.Log("Cannot search now, we are already caching results...");
            //    return;
            //}

            Pages.PageOffset = 0;

#if CPP
            Il2CppSystem.Type searchType = null;
#else
            Type searchType = null;
#endif
            if (TypeMode == TypeFilter.Custom)
            {
                if (ReflectionHelpers.GetTypeByName(m_typeInput) is Type t)
                {
#if CPP
                    searchType = Il2CppSystem.Type.GetType(t.AssemblyQualifiedName);
#else
                    searchType = t;
#endif
                }
                else
                {
                    ExplorerCore.Log($"Could not find a Type by the name of '{m_typeInput}'!");
                    return;
                }
            }
            else if (TypeMode == TypeFilter.Object)
            {
                searchType = ReflectionHelpers.ObjectType;
            }
            else if (TypeMode == TypeFilter.GameObject)
            {
                searchType = ReflectionHelpers.GameObjectType;
            }
            else if (TypeMode == TypeFilter.Component)
            {
                searchType = ReflectionHelpers.ComponentType;
            }

            if (!ReflectionHelpers.ObjectType.IsAssignableFrom(searchType))
            {
                if (searchType != null)
                {
                    ExplorerCore.LogWarning("Your Custom Class Type must inherit from UnityEngine.Object!");
                }
                return;
            }

            var matches = new List <object>();

            var allObjectsOfType = ResourcesUnstrip.FindObjectsOfTypeAll(searchType);

            //ExplorerCore.Log("Found count: " + allObjectsOfType.Length);

            int i = 0;
            foreach (var obj in allObjectsOfType)
            {
                if (i >= MaxSearchResults)
                {
                    break;
                }

                if (m_searchInput != "" && !obj.name.ToLower().Contains(m_searchInput.ToLower()))
                {
                    continue;
                }

                if (searchType.FullName == ReflectionHelpers.ComponentType.FullName
#if CPP
                    && ReflectionHelpers.TransformType.IsAssignableFrom(obj.GetIl2CppType()))
#else
                    && ReflectionHelpers.TransformType.IsAssignableFrom(obj.GetType()))
#endif
                {
                    // Transforms shouldn't really be counted as Components, skip them.
                    // They're more akin to GameObjects.
                    continue;
                }

                if (SceneMode != SceneFilter.Any && !FilterScene(obj, this.SceneMode))
                {
                    continue;
                }

                if (!matches.Contains(obj))
                {
                    matches.Add(obj);
                }

                i++;
            }

            CacheResults(matches);
        }
示例#4
0
        internal void UnityObjectSearch()
        {
            Type searchType = null;

            switch (m_context)
            {
            case SearchContext.GameObject:
                searchType = typeof(GameObject); break;

            case SearchContext.Component:
                searchType = typeof(Component); break;

            case SearchContext.Custom:
                if (string.IsNullOrEmpty(m_customTypeInput.text))
                {
                    ExplorerCore.LogWarning("Custom Type input must not be empty!");
                    return;
                }
                if (ReflectionHelpers.GetTypeByName(m_customTypeInput.text) is Type customType)
                {
                    if (typeof(UnityEngine.Object).IsAssignableFrom(customType))
                    {
                        searchType = customType;
                    }
                    else
                    {
                        ExplorerCore.LogWarning($"Custom type '{customType.FullName}' is not assignable from UnityEngine.Object!");
                    }
                }
                else
                {
                    ExplorerCore.LogWarning($"Could not find a type by the name '{m_customTypeInput.text}'!");
                }
                break;

            default:
                searchType = typeof(UnityEngine.Object); break;
            }

            if (searchType == null)
            {
                return;
            }

            var allObjects = ResourcesUnstrip.FindObjectsOfTypeAll(searchType);
            var results    = new List <object>();

            // perform filter comparers

            string nameFilter = null;

            if (!string.IsNullOrEmpty(m_nameInput.text))
            {
                nameFilter = m_nameInput.text.ToLower();
            }

            bool canGetGameObject = (m_sceneFilter != SceneFilter.Any || m_childFilter != ChildFilter.Any) &&
                                    (m_context == SearchContext.GameObject || typeof(Component).IsAssignableFrom(searchType));

            string sceneFilter = null;

            if (!canGetGameObject)
            {
                if (m_context != SearchContext.UnityObject && (m_sceneFilter != SceneFilter.Any || m_childFilter != ChildFilter.Any))
                {
                    ExplorerCore.LogWarning($"Type '{searchType}' cannot have Scene or Child filters applied to it");
                }
            }
            else
            {
                if (m_sceneFilter == SceneFilter.DontDestroyOnLoad)
                {
                    sceneFilter = "DontDestroyOnLoad";
                }
                else if (m_sceneFilter == SceneFilter.Explicit)
                {
                    sceneFilter = m_sceneDropdown.options[m_sceneDropdown.value].text;
                }
            }

            foreach (var obj in allObjects)
            {
                // name check
                if (!string.IsNullOrEmpty(nameFilter) && !obj.name.ToLower().Contains(nameFilter))
                {
                    continue;
                }

                if (canGetGameObject)
                {
#if MONO
                    var go = m_context == SearchContext.GameObject
                            ? obj as GameObject
                            : (obj as Component).gameObject;
#else
                    var go = m_context == SearchContext.GameObject
                            ? obj.TryCast <GameObject>()
                            : obj.TryCast <Component>().gameObject;
#endif

                    // scene check
                    if (m_sceneFilter != SceneFilter.Any)
                    {
                        if (!go)
                        {
                            continue;
                        }

                        switch (m_context)
                        {
                        case SearchContext.GameObject:
                            if (go.scene.name != sceneFilter)
                            {
                                continue;
                            }
                            break;

                        case SearchContext.Custom:
                        case SearchContext.Component:
                            if (go.scene.name != sceneFilter)
                            {
                                continue;
                            }
                            break;
                        }
                    }

                    if (m_childFilter != ChildFilter.Any)
                    {
                        if (!go)
                        {
                            continue;
                        }

                        // root object check (no parent)
                        if (m_childFilter == ChildFilter.HasParent && !go.transform.parent)
                        {
                            continue;
                        }
                        else if (m_childFilter == ChildFilter.RootObject && go.transform.parent)
                        {
                            continue;
                        }
                    }
                }

                results.Add(obj);
            }

            m_results = results.ToArray();
        }