-
Notifications
You must be signed in to change notification settings - Fork 2
/
ShowSelectedObjectsInProject.cs
58 lines (52 loc) · 1.97 KB
/
ShowSelectedObjectsInProject.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using System;
using System.Reflection;
using UnityEditor;
using UnityEngine;
public static class ShowSelectedObjectsInProject
{
[MenuItem("Tools/Selection/Show Selected Objects in Project %#g")]
public static void ShowSelectedObjectsInLastInteractedProjectBrowser()
{
if (Selection.objects == null || Selection.objects.Length <= 1)
{
return;
}
Type projectBrowserType = Type.GetType("UnityEditor.ProjectBrowser,UnityEditor");
if (projectBrowserType == null)
{
Debug.LogError("Can't find UnityEditor.ProjectBrowser type!");
return;
}
FieldInfo lastProjectBrowser = projectBrowserType.GetField("s_LastInteractedProjectBrowser",
BindingFlags.Static | BindingFlags.Public);
if (lastProjectBrowser == null)
{
Debug.LogError("Can't find s_LastInteractedProjectBrowser field!");
return;
}
object lastProjectBrowserInstance = lastProjectBrowser.GetValue(null);
FieldInfo projectBrowserViewMode =
projectBrowserType.GetField("m_ViewMode", BindingFlags.Instance | BindingFlags.NonPublic);
if (projectBrowserViewMode == null)
{
Debug.LogError("Can't find m_ViewMode field!");
return;
}
// 0 - one column, 1 - two column
int viewMode = (int)projectBrowserViewMode.GetValue(lastProjectBrowserInstance);
if (viewMode != 1)
{
return;
}
MethodInfo showSelectedObjects = projectBrowserType.GetMethod(
"ShowSelectedObjectsInLastInteractedProjectBrowser", BindingFlags.NonPublic | BindingFlags.Static);
if (showSelectedObjects != null)
{
showSelectedObjects.Invoke(null, null);
}
else
{
Debug.LogError("Can't find ShowSelectedObjectsInLastInteractedProjectBrowser method!");
}
}
}