コード例 #1
0
    static void OnEnable()
    {
        s_GameObjects = SearchUtils.FetchGameObjects();
        s_QueryEngine = new QueryEngine <GameObject>();

        // Id supports all operators
        s_QueryEngine.AddFilter("id", go => go.GetInstanceID());
        // Name supports only :, = and !=
        s_QueryEngine.AddFilter("n", go => go.name, new [] { ":", "=", "!=" });

        // Add distance filtering. Does not support :.
        s_QueryEngine.AddFilter("dist", DistanceHandler, DistanceParamHandler, new [] { "=", "!=", "<", ">", "<=", ">=" });
    }
コード例 #2
0
        private IEnumerator SearchItems(SearchContext context, SearchProvider provider)
        {
            if (!string.IsNullOrEmpty(context.searchQuery))
            {
                if (m_HierarchyChanged)
                {
                    m_SceneQueryEngine = new SceneQueryEngine(SearchUtils.FetchGameObjects());
                    m_HierarchyChanged = false;
                }

                IEnumerable <GameObject> subset = null;
                if (context.subset != null)
                {
                    subset = context.subset
                             .Where(item => item.provider.id == "scene")
                             .Select(item => ObjectFromItem(item))
                             .Where(obj => obj != null);
                }

                #if USE_PROPERTY_DATABASE
                using (SearchMonitor.GetView())
                #endif
                {
                    yield return(m_SceneQueryEngine.Search(context, provider, subset)
                                 .Where(go => go)
                                 .Select(go => AddResult(context, provider, go)));
                }
            }
            else if (context.filterType != null && string.IsNullOrEmpty(context.searchQuery))
            {
                yield return(UnityEngine.Object.FindObjectsOfType(context.filterType)
                             .Select(obj =>
                {
                    if (obj is Component c)
                    {
                        return c.gameObject;
                    }
                    return obj as GameObject;
                })
                             .Where(go => go)
                             .Select(go => AddResult(context, provider, go)));
            }
        }