private void AddPropertyReferences(SerializedProperty p, ICollection <string> refs, int depth, int maxDepth) { if (p.propertyType != SerializedPropertyType.ObjectReference || !p.objectReferenceValue) { return; } var refValue = AssetDatabase.GetAssetPath(p.objectReferenceValue); if (String.IsNullOrEmpty(refValue)) { if (p.objectReferenceValue is GameObject go) { refValue = SearchUtils.GetTransformPath(go.transform); } } if (!String.IsNullOrEmpty(refValue)) { if (!refs.Contains(refValue)) { AddReference(p.objectReferenceValue, refValue, refs); BuildReferences(p.objectReferenceValue, refs, depth + 1, maxDepth); } } // Add custom object cases if (p.objectReferenceValue is Material material) { if (material.shader) { AddReference(material.shader, material.shader.name, refs); } } }
public string GetPath(GameObject go) { var god = GetGOD(go); if (god.path == null) { god.path = SearchUtils.GetTransformPath(go.transform).ToLowerInvariant(); } return(god.path); }
private void IndexObjects(GameObject[] objects, string type, string containerName, bool checkIfDocumentExists) { var options = settings.options; var globalIds = new GlobalObjectId[objects.Length]; GlobalObjectId.GetGlobalObjectIdsSlow(objects, globalIds); for (int i = 0; i < objects.Length; ++i) { var obj = objects[i]; if (!obj) { continue; } if (PrefabUtility.IsPrefabAssetMissing(obj)) { continue; } var gid = globalIds[i]; var id = gid.ToString(); var path = SearchUtils.GetTransformPath(obj.transform); var documentIndex = AddDocument(id, path, checkIfDocumentExists); if (!String.IsNullOrEmpty(name)) { IndexProperty(id, "a", name, documentIndex, saveKeyword: true); } var depth = GetObjectDepth(obj); IndexNumber(id, "depth", depth, documentIndex); IndexWordComponents(id, documentIndex, path); IndexProperty(id, "from", type, documentIndex, saveKeyword: true, exact: true); IndexProperty(id, type, containerName, documentIndex, saveKeyword: true); IndexGameObject(id, documentIndex, obj, options); } }
public SceneProvider(string providerId, string filterId, string displayName) : base(providerId, displayName) { priority = 50; this.filterId = filterId; this.showDetails = true; showDetailsOptions = ShowDetailsOptions.Inspector | ShowDetailsOptions.Actions; isEnabledForContextualSearch = () => Utils.IsFocusedWindowTypeName("SceneView") || Utils.IsFocusedWindowTypeName("SceneHierarchyWindow"); EditorApplication.hierarchyChanged += () => m_HierarchyChanged = true; onEnable = () => { if (m_HierarchyChanged) { m_GameObjects = fetchGameObjects(); m_SceneQueryEngine = new SceneQueryEngine(m_GameObjects); m_HierarchyChanged = false; } }; onDisable = () => { // Only track changes that occurs when Quick Search is not active. m_HierarchyChanged = false; }; toObject = (item, type) => ObjectFromItem(item); fetchItems = (context, items, provider) => SearchItems(context, provider); fetchLabel = (item, context) => { if (item.label != null) { return(item.label); } var go = ObjectFromItem(item); if (!go) { return(item.id); } if (context.searchView == null || context.searchView.displayMode == DisplayMode.List) { var transformPath = SearchUtils.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 = Utils.CleanString(context.searchQuery); if (FuzzySearch.FuzzyMatch(sq, Utils.CleanString(item.label), ref score, matches)) { item.label = RichTextFormatter.FormatSuggestionTitle(item.label, matches); } } else { item.label = go.name; } return(item.label); }; fetchDescription = (item, context) => { var go = ObjectFromItem(item); return(item.description = SearchUtils.GetHierarchyPath(go)); }; fetchThumbnail = (item, context) => { var obj = ObjectFromItem(item); if (obj == null) { return(null); } return(item.thumbnail = Utils.GetThumbnailForGameObject(obj)); }; fetchPreview = (item, context, size, options) => { var obj = ObjectFromItem(item); if (obj == null) { return(item.thumbnail); } return(Utils.GetSceneObjectPreview(obj, size, options, item.thumbnail)); }; startDrag = (item, context) => { Utils.StartDrag(context.selection.Select(i => ObjectFromItem(i)).ToArray(), item.GetLabel(context, true)); }; trackSelection = (item, context) => PingItem(item); fetchGameObjects = SceneQueryEngine.FetchGameObjects; buildKeywordComponents = SceneQueryEngine.BuildKeywordComponents; }
public SceneProvider(string providerId, string filterId, string displayName) : base(providerId, displayName) { priority = 50; this.filterId = filterId; showDetails = true; showDetailsOptions = ShowDetailsOptions.Inspector | ShowDetailsOptions.Actions | ShowDetailsOptions.Preview | ShowDetailsOptions.DefaultGroup; isEnabledForContextualSearch = () => Utils.IsFocusedWindowTypeName("SceneView") || Utils.IsFocusedWindowTypeName("SceneHierarchyWindow"); SearchMonitor.sceneChanged += InvalidateScene; SearchMonitor.documentsInvalidated += Refresh; SearchMonitor.objectChanged += OnObjectChanged; supportsSyncViewSearch = true; toObject = (item, type) => ObjectFromItem(item, type); toKey = (item) => ToKey(item); fetchItems = (context, items, provider) => SearchItems(context, provider); fetchLabel = (item, context) => { if (item.label != null) { return(item.label); } var go = ObjectFromItem(item); if (!go) { return(item.id); } if (context == null || context.searchView == null || context.searchView.displayMode == DisplayMode.List) { var transformPath = SearchUtils.GetTransformPath(go.transform); if (item.options.HasAny(SearchItemOptions.Compacted)) { item.label = transformPath; } else { 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})"; } } if (context != null) { long score = 1; List <int> matches = new List <int>(); var sq = Utils.CleanString(context.searchQuery); if (FuzzySearch.FuzzyMatch(sq, Utils.CleanString(item.label), ref score, matches)) { item.label = RichTextFormatter.FormatSuggestionTitle(item.label, matches); } } } else { item.label = go.name; } return(item.label); }; fetchDescription = (item, context) => { var go = ObjectFromItem(item); return(item.description = SearchUtils.GetHierarchyPath(go)); }; fetchThumbnail = (item, context) => { var obj = ObjectFromItem(item); if (obj == null) { return(null); } return(item.thumbnail = Utils.GetThumbnailForGameObject(obj)); }; fetchPreview = (item, context, size, options) => { var obj = ObjectFromItem(item); if (obj == null) { return(item.thumbnail); } return(Utils.GetSceneObjectPreview(obj, size, options, item.thumbnail)); }; startDrag = (item, context) => { if (context.selection.Count > 1) { Utils.StartDrag(context.selection.Select(i => ObjectFromItem(i)).ToArray(), item.GetLabel(context, true)); } else { Utils.StartDrag(new[] { ObjectFromItem(item) }, item.GetLabel(context, true)); } }; fetchPropositions = (context, options) => { if (options.HasAny(SearchPropositionFlags.QueryBuilder)) { return(FetchQueryBuilderPropositions(context)); } return(m_SceneQueryEngine == null ? new SearchProposition[0] : m_SceneQueryEngine.FindPropositions(context, options)); }; trackSelection = (item, context) => PingItem(item); fetchColumns = (context, items) => SceneSelectors.Enumerate(items); }
public SceneProvider(string providerId, string filterId, string displayName) : base(providerId, displayName) { priority = 50; this.filterId = filterId; isEnabledForContextualSearch = () => Utils.IsFocusedWindowTypeName("SceneView") || Utils.IsFocusedWindowTypeName("SceneHierarchyWindow"); EditorApplication.hierarchyChanged += () => m_HierarchyChanged = true; onEnable = () => { if (m_HierarchyChanged) { m_GameObjects = fetchGameObjects(); m_SceneQueryEngine = new SceneQueryEngine(m_GameObjects); m_HierarchyChanged = false; } }; onDisable = () => { // Only track changes that occurs when Quick Search is not active. m_HierarchyChanged = false; }; toObject = (item, type) => ObjectFromItem(item); fetchItems = (context, items, provider) => SearchItems(context, provider); fetchLabel = (item, context) => { if (item.label != null) { return(item.label); } var go = ObjectFromItem(item); if (!go) { return(item.id); } if (context.searchView == null || context.searchView.displayMode == DisplayMode.List) { var transformPath = SearchUtils.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 = Utils.CleanString(context.searchQuery); if (FuzzySearch.FuzzyMatch(sq, Utils.CleanString(item.label), ref score, matches)) { item.label = RichTextFormatter.FormatSuggestionTitle(item.label, matches); } } else { item.label = go.name; } return(item.label); }; fetchDescription = (item, context) => { var go = ObjectFromItem(item); return(item.description = SearchUtils.GetHierarchyPath(go)); }; fetchThumbnail = (item, context) => { var obj = ObjectFromItem(item); if (obj == null) { return(null); } return(item.thumbnail = Utils.GetThumbnailForGameObject(obj)); }; fetchPreview = (item, context, size, options) => { var obj = ObjectFromItem(item); if (obj == null) { return(item.thumbnail); } var sr = obj.GetComponent <SpriteRenderer>(); if (sr && sr.sprite && sr.sprite.texture) { return(sr.sprite.texture); } #if PACKAGE_UGUI var uii = obj.GetComponent <UnityEngine.UI.Image>(); if (uii && uii.mainTexture is Texture2D uiit) { return(uiit); } #endif var preview = AssetPreview.GetAssetPreview(obj); if (preview) { return(preview); } var assetPath = SearchUtils.GetHierarchyAssetPath(obj, true); if (String.IsNullOrEmpty(assetPath)) { return(item.thumbnail); } return(Utils.GetAssetPreviewFromPath(assetPath, size, options)); }; startDrag = (item, context) => { var obj = ObjectFromItem(item); if (obj != null) { Utils.StartDrag(obj, item.label); } }; trackSelection = (item, context) => PingItem(item); fetchGameObjects = SceneQueryEngine.FetchGameObjects; buildKeywordComponents = SceneQueryEngine.BuildKeywordComponents; }