Skip to content

Instantly share code, notes, and snippets.

@karljj1
Created August 8, 2018 09:53
Show Gist options
  • Save karljj1/f6f9e03dca9d578701cfd75ba4e21d94 to your computer and use it in GitHub Desktop.
Save karljj1/f6f9e03dca9d578701cfd75ba4e21d94 to your computer and use it in GitHub Desktop.
[MenuItem("CONTEXT/Component/Find References In Scene")]
private static void OnSearchForReferencesToComponent(MenuCommand command)
{
var component = command.context as Component;
if (component)
{
var searchFilter = "ref:" + component.GetInstanceID() + ":";
foreach (SearchableEditorWindow sw in searchableWindows)
{
if (sw.m_HierarchyType == HierarchyType.GameObjects)
{
sw.SetSearchFilter(searchFilter, SearchMode.All, false, false);
sw.m_HasSearchFilterFocus = true;
sw.Repaint();
}
}
}
}
@karljj1
Copy link
Author

karljj1 commented Aug 1, 2019

Via reflection

var view = SceneView.currentDrawingSceneView;
MethodInfo setSearchType = typeof(SearchableEditorWindow).GetMethod("SetSearchFilter", BindingFlags.NonPublic | BindingFlags.Instance);
bool setAll = false;
bool delayed = false;
setSearchType.Invoke(view, new object[] {"search filter", SearchableEditorWindow.SearchMode.All, setAll, delayed });

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment