protected GameObject[] FetchGameObjects() { var prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { return(SceneModeUtility.GetObjects(new[] { prefabStage.prefabContentsRoot }, true)); } var goRoots = new List <UnityEngine.Object>(); for (int i = 0; i < SceneManager.sceneCount; ++i) { var scene = SceneManager.GetSceneAt(i); if (!scene.IsValid() || !scene.isLoaded) { continue; } var sceneRootObjects = scene.GetRootGameObjects(); if (sceneRootObjects != null && sceneRootObjects.Length > 0) { goRoots.AddRange(sceneRootObjects); } } return(SceneModeUtility.GetObjects(goRoots.ToArray(), true)); }
/// <summary> /// Utility function to fetch all the game objects in a particular scene. /// </summary> /// <param name="scene">Scene to get objects from.</param> /// <returns>The array of game objects in the scene.</returns> public static GameObject[] FetchGameObjects(Scene scene) { var goRoots = new List <UnityEngine.Object>(); if (!scene.IsValid() || !scene.isLoaded) { return(new GameObject[0]); } var sceneRootObjects = scene.GetRootGameObjects(); if (sceneRootObjects != null && sceneRootObjects.Length > 0) { goRoots.AddRange(sceneRootObjects); } return(SceneModeUtility.GetObjects(goRoots.ToArray(), true) .Where(o => !o.hideFlags.HasFlag(HideFlags.HideInHierarchy)).ToArray()); }
private void IndexPrefab(string prefabPath, bool checkIfDocumentExists) { var prefabRoot = PrefabUtility.LoadPrefabContents(prefabPath); if (!prefabRoot) { return; } try { var objects = SceneModeUtility.GetObjects(new[] { prefabRoot }, true); IndexObjects(objects, "prefab", prefabRoot.name, checkIfDocumentExists); } finally { PrefabUtility.UnloadPrefabContents(prefabRoot); } }
protected GameObject[] FetchGameObjects() { var prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) return SceneModeUtility.GetObjects(new[] { prefabStage.prefabContentsRoot }, true); var goRoots = new List<UnityEngine.Object>(); for (int i = 0; i < SceneManager.sceneCount; ++i) { var scene = SceneManager.GetSceneAt(i); if (!scene.IsValid() || !scene.isLoaded) continue; var sceneRootObjects = scene.GetRootGameObjects(); if (sceneRootObjects != null && sceneRootObjects.Length > 0) goRoots.AddRange(sceneRootObjects); } return SceneModeUtility.GetObjects(goRoots.ToArray(), true) .Where(o => !o.hideFlags.HasFlag(HideFlags.HideInHierarchy)).ToArray(); }
UnityObject[] GetObjects(bool includeChildren) { return(SceneModeUtility.GetObjects(targets, includeChildren)); }
private IEnumerator <SearchItem> BuildGODS(SearchContext context, SearchProvider provider) { //using (new DebugTimer("BuildGODS")) { var objects = new GameObject[0]; var prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { objects = SceneModeUtility.GetObjects(new[] { prefabStage.prefabContentsRoot }, true); yield return(null); } else { var goRoots = new List <UnityEngine.Object>(); for (int i = 0; i < SceneManager.sceneCount; ++i) { var scene = SceneManager.GetSceneAt(i); if (!scene.IsValid() || !scene.isLoaded) { continue; } var sceneRootObjects = scene.GetRootGameObjects(); if (sceneRootObjects != null && sceneRootObjects.Length > 0) { goRoots.AddRange(sceneRootObjects); } yield return(null); } objects = SceneModeUtility.GetObjects(goRoots.ToArray(), true); yield return(null); } //using (new DebugTimer($"Fetching Scene Objects Components")) { List <int> matches = new List <int>(); var useFuzzySearch = objects.Length < k_LODDetail2 && context.categories.Any(c => c.name.id == "fuzzy" && c.isEnabled); gods = new GOD[objects.Length]; for (int i = 0; i < objects.Length; ++i) { gods[i].gameObject = objects[i]; var id = gods[i].gameObject.GetInstanceID(); if (!componentsById.TryGetValue(id, out gods[i].name)) { if (gods.Length > k_LODDetail2) { gods[i].rawname = gods[i].gameObject.name; } else if (gods.Length > k_LODDetail1) { gods[i].rawname = GetTransformPath(gods[i].gameObject.transform); } else { gods[i].rawname = BuildComponents(gods[i].gameObject); } gods[i].name = CleanString(gods[i].rawname); componentsById[id] = gods[i].name; } gods[i].id = id.ToString(); yield return(MatchGOD(context, provider, gods[i], i, useFuzzySearch, CleanString(context.searchQuery), matches)); } } } }
public SceneObjectsProvider(string providerId, string displayName = null) : base(providerId, displayName) { priority = 50; filterId = "h:"; subCategories = new List <NameId> { new NameId("fuzzy", "fuzzy"), new NameId("limit", $"limit to {k_LimitMatches} matches") }; isEnabledForContextualSearch = () => QuickSearchTool.IsFocusedWindowTypeName("SceneView") || QuickSearchTool.IsFocusedWindowTypeName("SceneHierarchyWindow"); EditorApplication.hierarchyChanged += () => componentsById.Clear(); onEnable = () => { //using (new DebugTimer("Building Scene Object Description")) { var objects = new GameObject[0]; var prefabStage = PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { objects = SceneModeUtility.GetObjects(new[] { prefabStage.prefabContentsRoot }, true); } else { var goRoots = new List <UnityEngine.Object>(); for (int i = 0; i < UnityEngine.SceneManagement.SceneManager.sceneCount; ++i) { goRoots.AddRange(UnityEngine.SceneManagement.SceneManager.GetSceneAt(i).GetRootGameObjects()); } objects = SceneModeUtility.GetObjects(goRoots.ToArray(), true); } //using (new DebugTimer($"Fetching {gods.Length} Scene Objects Components")) { gods = new GOD[objects.Length]; for (int i = 0; i < objects.Length; ++i) { gods[i].gameObject = objects[i]; var id = gods[i].gameObject.GetInstanceID(); if (!componentsById.TryGetValue(id, out gods[i].name)) { if (gods.Length > k_LODDetail2) { gods[i].name = CleanString(gods[i].gameObject.name); } else if (gods.Length > k_LODDetail1) { gods[i].name = CleanString(GetTransformPath(gods[i].gameObject.transform)); } else { gods[i].name = BuildComponents(gods[i].gameObject); } componentsById[id] = gods[i].name; } } indexer = new SceneSearchIndexer(SceneManager.GetActiveScene().name, gods); indexer.Build(); } } }; onDisable = () => { indexer = null; gods = new GOD[0]; }; fetchItems = (context, items, provider) => { if (gods == null) { return; } if (indexer != null && indexer.IsReady()) { var results = indexer.Search(context.searchQuery).Take(201); items.AddRange(results.Select(r => { if (r.index < 0 || r.index >= gods.Length) { return(provider.CreateItem("invalid")); } var gameObjectId = gods[r.index].gameObject.GetInstanceID().ToString(); var gameObjectName = gods[r.index].gameObject.name; var itemScore = r.score - 1000; if (gameObjectName.Equals(context.searchQuery, StringComparison.InvariantCultureIgnoreCase)) { itemScore *= 2; } var item = provider.CreateItem(gameObjectId, itemScore, null, null, null, r.index); item.descriptionFormat = SearchItemDescriptionFormat.Ellipsis | SearchItemDescriptionFormat.RightToLeft | SearchItemDescriptionFormat.Highlight; return(item); })); } SearchGODs(context, provider, items); }; fetchLabel = (item, context) => { if (item.label != null) { return(item.label); } var go = ObjectFromItem(item); if (!go) { return(item.id); } var transformPath = GetTransformPath(go.transform); var components = go.GetComponents <Component>(); if (components.Length > 2 && components[1] && components[components.Length - 1]) { item.label = $"{transformPath} ({components[1].GetType().Name}..{components[components.Length-1].GetType().Name})"; } else if (components.Length > 1 && components[1]) { item.label = $"{transformPath} ({components[1].GetType().Name})"; } else { item.label = $"{transformPath} ({item.id})"; } long score = 1; List <int> matches = new List <int>(); var sq = CleanString(context.searchQuery); if (FuzzySearch.FuzzyMatch(sq, CleanString(item.label), ref score, matches)) { item.label = RichTextFormatter.FormatSuggestionTitle(item.label, matches); } return(item.label); }; fetchDescription = (item, context) => { #if QUICKSEARCH_DEBUG item.description = gods[(int)item.data].name + " * " + item.score; #else var go = ObjectFromItem(item); item.description = GetHierarchyPath(go); #endif return(item.description); }; fetchThumbnail = (item, context) => { if (item.thumbnail) { return(item.thumbnail); } var obj = ObjectFromItem(item); if (obj != null) { if (SearchSettings.fetchPreview) { var assetPath = GetHierarchyAssetPath(obj, true); if (!String.IsNullOrEmpty(assetPath)) { item.thumbnail = AssetPreview.GetAssetPreview(obj); if (item.thumbnail) { return(item.thumbnail); } item.thumbnail = Utils.GetAssetThumbnailFromPath(assetPath, true); if (item.thumbnail) { return(item.thumbnail); } } } item.thumbnail = PrefabUtility.GetIconForGameObject(obj); if (item.thumbnail) { return(item.thumbnail); } item.thumbnail = EditorGUIUtility.ObjectContent(obj, obj.GetType()).image as Texture2D; } return(item.thumbnail); }; startDrag = (item, context) => { var obj = ObjectFromItem(item); if (obj != null) { DragAndDrop.PrepareStartDrag(); DragAndDrop.objectReferences = new[] { obj }; DragAndDrop.StartDrag("Drag scene object"); } }; trackSelection = (item, context) => PingItem(item); }