scene | 获取对象的场景。 |
GameObject[] 场景中的游戏对象数组。
用于获取特定场景中所有游戏对象的实用程序函数。
使用 SearchUtils.FetchGameObjects
创建一个能够访问当前场景对象的自定义 SearchProvider。
static void OnEnable() { s_GameObjects = SearchUtils.FetchGameObjects().ToArray(); 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[] {"=", "!=", "<", ">", "<=", ">="}); }
static IEnumerator SearchItems(SearchContext context, SearchProvider provider) { var query = s_QueryEngine.ParseQuery(context.searchQuery); if (!query.valid) yield break; var filteredObjects = query.Apply(s_GameObjects); foreach (var filteredObject in filteredObjects) { yield return provider.CreateItem(filteredObject.GetInstanceID().ToString(), null, null, null, filteredObject.GetInstanceID()); } }