Skip to content

Commit 9ba3fde

Browse files
authored
Update HierarchyEditor.cs for unity 2022
1 parent 7572e73 commit 9ba3fde

File tree

1 file changed

+58
-29
lines changed

1 file changed

+58
-29
lines changed

Assets/Hierarchy 2/Editor/HierarchyEditor.cs

Lines changed: 58 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -110,43 +110,67 @@ static void InternalReflection()
110110
InternalEditorType = arrayInteralEditorType.ToList();
111111
dicInternalEditorType = arrayInteralEditorType.ToDictionary(type => type.FullName);
112112

113-
FieldInfo refreshHierarchy = typeof(EditorApplication).GetField(nameof(refreshHierarchy), BindingFlags.Static | BindingFlags.NonPublic);
114-
MethodInfo OnRepaintHierarchyWindow = typeof(HierarchyEditor).GetMethod(nameof(OnRepaintHierarchyWindow), BindingFlags.NonPublic | BindingFlags.Static);
115-
Delegate refreshHierarchyDelegate = Delegate.CreateDelegate(typeof(EditorApplication.CallbackFunction), OnRepaintHierarchyWindow);
113+
FieldInfo refreshHierarchy = typeof(EditorApplication).GetField(nameof(refreshHierarchy),
114+
BindingFlags.Static | BindingFlags.NonPublic);
115+
MethodInfo OnRepaintHierarchyWindow = typeof(HierarchyEditor).GetMethod(nameof(OnRepaintHierarchyWindow),
116+
BindingFlags.NonPublic | BindingFlags.Static);
117+
Delegate refreshHierarchyDelegate =
118+
Delegate.CreateDelegate(typeof(EditorApplication.CallbackFunction), OnRepaintHierarchyWindow);
116119
refreshHierarchy.SetValue(null, refreshHierarchyDelegate);
117120

118121

119-
FieldInfo windowsReordered = typeof(EditorApplication).GetField(nameof(windowsReordered), BindingFlags.Static | BindingFlags.NonPublic);
120-
MethodInfo OnWindowsReordered = typeof(HierarchyEditor).GetMethod(nameof(OnWindowsReordered), BindingFlags.NonPublic | BindingFlags.Static);
121-
Delegate windowsReorderedDelegate = Delegate.CreateDelegate(typeof(EditorApplication.CallbackFunction), OnWindowsReordered);
122+
FieldInfo windowsReordered = typeof(EditorApplication).GetField(nameof(windowsReordered),
123+
BindingFlags.Static | BindingFlags.NonPublic);
124+
MethodInfo OnWindowsReordered = typeof(HierarchyEditor).GetMethod(nameof(OnWindowsReordered),
125+
BindingFlags.NonPublic | BindingFlags.Static);
126+
Delegate windowsReorderedDelegate =
127+
Delegate.CreateDelegate(typeof(EditorApplication.CallbackFunction), OnWindowsReordered);
122128
windowsReordered.SetValue(null, windowsReorderedDelegate);
123129

124130
{
125-
dicInternalEditorType.TryGetValue(nameof(UnityEditor) + "." + nameof(SceneHierarchyWindow), out SceneHierarchyWindow);
126-
dicInternalEditorType.TryGetValue(nameof(UnityEditor) + "." + nameof(GameObjectTreeViewGUI), out GameObjectTreeViewGUI); //GameObjectTreeViewGUI : TreeViewGUI
127-
dicInternalEditorType.TryGetValue(nameof(UnityEditor) + "." + nameof(SceneHierarchy), out SceneHierarchy);
131+
dicInternalEditorType.TryGetValue(nameof(UnityEditor) + "." + nameof(SceneHierarchyWindow),
132+
out SceneHierarchyWindow);
133+
dicInternalEditorType.TryGetValue(nameof(UnityEditor) + "." + nameof(GameObjectTreeViewGUI),
134+
out GameObjectTreeViewGUI); //GameObjectTreeViewGUI : TreeViewGUI
135+
dicInternalEditorType.TryGetValue(nameof(UnityEditor) + "." + nameof(SceneHierarchy),
136+
out SceneHierarchy);
128137
}
129138

130-
FieldInfo s_LastInteractedHierarchy = SceneHierarchyWindow.GetField(nameof(s_LastInteractedHierarchy), BindingFlags.NonPublic | BindingFlags.Static);
139+
FieldInfo s_LastInteractedHierarchy = SceneHierarchyWindow.GetField(nameof(s_LastInteractedHierarchy),
140+
BindingFlags.NonPublic | BindingFlags.Static);
131141

132-
MethodInfo lastInteractedHierarchyWindow = SceneHierarchyWindow.GetProperty(nameof(lastInteractedHierarchyWindow), BindingFlags.Static | BindingFlags.Public).GetGetMethod();
133-
lastInteractedHierarchyWindowDelegate = Delegate.CreateDelegate(typeof(Func<SearchableEditorWindow>), lastInteractedHierarchyWindow) as Func<SearchableEditorWindow>;
142+
MethodInfo lastInteractedHierarchyWindow = SceneHierarchyWindow
143+
.GetProperty(nameof(lastInteractedHierarchyWindow), BindingFlags.Static | BindingFlags.Public)
144+
.GetGetMethod();
145+
lastInteractedHierarchyWindowDelegate =
146+
Delegate.CreateDelegate(typeof(Func<SearchableEditorWindow>), lastInteractedHierarchyWindow) as
147+
Func<SearchableEditorWindow>;
134148

135-
MethodInfo GetAllSceneHierarchyWindows = SceneHierarchyWindow.GetMethod(nameof(GetAllSceneHierarchyWindows), BindingFlags.Static | BindingFlags.Public);
136-
GetAllSceneHierarchyWindowsDelegate = Delegate.CreateDelegate(typeof(Func<IEnumerable>), GetAllSceneHierarchyWindows) as Func<IEnumerable>;
149+
MethodInfo GetAllSceneHierarchyWindows = SceneHierarchyWindow.GetMethod(nameof(GetAllSceneHierarchyWindows),
150+
BindingFlags.Static | BindingFlags.Public);
151+
GetAllSceneHierarchyWindowsDelegate =
152+
Delegate.CreateDelegate(typeof(Func<IEnumerable>), GetAllSceneHierarchyWindows) as Func<IEnumerable>;
137153

138154
{
139-
m_SceneHierarchy = SceneHierarchyWindow.GetField(nameof(m_SceneHierarchy), BindingFlags.NonPublic | BindingFlags.Instance);
140-
m_TreeView = SceneHierarchy.GetField(nameof(m_TreeView), BindingFlags.NonPublic | BindingFlags.Instance);
141-
gui = m_TreeView.FieldType.GetProperty(nameof(gui).ToLower(), BindingFlags.Public | BindingFlags.Instance);
142-
k_IconWidth = GameObjectTreeViewGUI.GetField(nameof(k_IconWidth), BindingFlags.Public | BindingFlags.Instance);
155+
m_SceneHierarchy = SceneHierarchyWindow.GetField(nameof(m_SceneHierarchy),
156+
BindingFlags.NonPublic | BindingFlags.Instance);
157+
m_TreeView =
158+
SceneHierarchy.GetField(nameof(m_TreeView), BindingFlags.NonPublic | BindingFlags.Instance);
159+
gui = m_TreeView.FieldType.GetProperty(nameof(gui).ToLower(),
160+
BindingFlags.Public | BindingFlags.Instance);
161+
k_IconWidth =
162+
GameObjectTreeViewGUI.GetField(nameof(k_IconWidth), BindingFlags.Public | BindingFlags.Instance);
143163
}
144164

145-
MethodInfo DisplayObjectContextMenu = typeof(EditorUtility).GetMethods(BindingFlags.Static | BindingFlags.NonPublic).Single
146-
(
147-
method => method.Name == nameof(DisplayObjectContextMenu) && method.GetParameters()[1].ParameterType == typeof(UnityEngine.Object)
148-
);
149-
DisplayObjectContextMenuDelegate = Delegate.CreateDelegate(typeof(Action<Rect, UnityEngine.Object, int>), DisplayObjectContextMenu) as Action<Rect, UnityEngine.Object, int>;
165+
MethodInfo DisplayObjectContextMenu = typeof(EditorUtility)
166+
.GetMethods(BindingFlags.Static | BindingFlags.NonPublic).Single
167+
(
168+
method => method.Name == nameof(DisplayObjectContextMenu) &&
169+
method.GetParameters()[1].ParameterType == typeof(UnityEngine.Object)
170+
);
171+
DisplayObjectContextMenuDelegate =
172+
Delegate.CreateDelegate(typeof(Action<Rect, UnityEngine.Object, int>), DisplayObjectContextMenu) as
173+
Action<Rect, UnityEngine.Object, int>;
150174

151175

152176
Type IconSelector = typeof(EditorWindow).Assembly.GetTypes().Single(type =>
@@ -156,15 +180,20 @@ static void InternalReflection()
156180
method => method.Name == nameof(ShowAtPosition) &&
157181
method.GetParameters()[0].ParameterType == typeof(UnityEngine.Object)
158182
);
159-
IconSelectorShowAtPositionDelegate = Delegate.CreateDelegate(typeof(Func<GameObject, Rect, bool, bool>), ShowAtPosition) as Func<GameObject, Rect, bool, bool>;
183+
IconSelectorShowAtPositionDelegate =
184+
Delegate.CreateDelegate(typeof(Func<GameObject, Rect, bool, bool>), ShowAtPosition) as
185+
Func<GameObject, Rect, bool, bool>;
160186

161-
GetItemAndRowIndexMethod = m_TreeView.FieldType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance).Single(method => method.Name == "GetItemAndRowIndex");
187+
GetItemAndRowIndexMethod = m_TreeView.FieldType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)
188+
.Single(method => method.Name == "GetItemAndRowIndex");
162189

163-
m_TreeView_IData = m_TreeView.FieldType.GetProperties(BindingFlags.Public | BindingFlags.Instance).Single(property => property.Name == "data");
190+
m_TreeView_IData = m_TreeView.FieldType.GetProperties(BindingFlags.Public | BindingFlags.Instance)
191+
.Single(property => property.Name == "data");
164192

165-
m_Rows = InternalEditorType.Find(type => type.Name == "TreeViewDataSource").GetFields(BindingFlags.NonPublic | BindingFlags.Instance).Single(field => field.Name.Contains(nameof(m_Rows)));
193+
m_Rows = InternalEditorType.Find(type => type.Name == "TreeViewDataSource")
194+
.GetFields(BindingFlags.NonPublic | BindingFlags.Instance)
195+
.Single(field => field.Name.Contains(nameof(m_Rows)));
166196
}
167-
168197
public static IEnumerable GetAllSceneHierarchyWindows() => GetAllSceneHierarchyWindowsDelegate();
169198

170199
public static void DisplayObjectContextMenu(Rect rect, UnityEngine.Object unityObject, int value) => DisplayObjectContextMenuDelegate(rect, unityObject, value);
@@ -1873,4 +1902,4 @@ static void CreateHeaderInstance(UnityEditor.MenuCommand command)
18731902
}
18741903
}
18751904
}
1876-
}
1905+
}

0 commit comments

Comments
 (0)