forked from pschraut/UnityHeapExplorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAbstractNativeObjectsView.cs
More file actions
355 lines (296 loc) · 13.4 KB
/
Copy pathAbstractNativeObjectsView.cs
File metadata and controls
355 lines (296 loc) · 13.4 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
//
// Heap Explorer for Unity. Copyright (c) 2019-2020 Peter Schraut (www.console-dev.de). See LICENSE.md
// https://github.com/pschraut/UnityHeapExplorer/
//
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.IMGUI.Controls;
using UnityEditor;
namespace HeapExplorer
{
public class AbstractNativeObjectsView : HeapExplorerView
{
protected NativeObjectsControl m_NativeObjectsControl;
NativeObjectControl m_NativeObjectControl;
HeSearchField m_SearchField;
ConnectionsView m_ConnectionsView;
PackedNativeUnityEngineObject? m_Selected;
RootPathView m_RootPathView;
NativeObjectPreviewView m_PreviewView;
float m_SplitterHorz = 0.33333f;
float m_SplitterVert = 0.32f;
float m_PreviewSplitterVert = 0.32f;
float m_RootPathSplitterVert = 0.32f;
Rect m_FilterButtonRect;
protected bool showAssets
{
get
{
return EditorPrefs.GetBool(GetPrefsKey(() => showAssets), true);
}
set
{
EditorPrefs.SetBool(GetPrefsKey(() => showAssets), value);
}
}
protected bool showSceneObjects
{
get
{
return EditorPrefs.GetBool(GetPrefsKey(() => showSceneObjects), true);
}
set
{
EditorPrefs.SetBool(GetPrefsKey(() => showSceneObjects), value);
}
}
protected bool showRuntimeObjects
{
get
{
return EditorPrefs.GetBool(GetPrefsKey(() => showRuntimeObjects), true);
}
set
{
EditorPrefs.SetBool(GetPrefsKey(() => showRuntimeObjects), value);
}
}
protected bool showDestroyOnLoadObjects
{
get
{
return EditorPrefs.GetBool(GetPrefsKey(() => showDestroyOnLoadObjects), true);
}
set
{
EditorPrefs.SetBool(GetPrefsKey(() => showDestroyOnLoadObjects), value);
}
}
protected bool showDontDestroyOnLoadObjects
{
get
{
return EditorPrefs.GetBool(GetPrefsKey(() => showDontDestroyOnLoadObjects), true);
}
set
{
EditorPrefs.SetBool(GetPrefsKey(() => showDontDestroyOnLoadObjects), value);
}
}
protected override void OnCreate()
{
base.OnCreate();
m_ConnectionsView = CreateView<ConnectionsView>();
m_ConnectionsView.editorPrefsKey = GetPrefsKey(() => m_ConnectionsView);
m_ConnectionsView.showReferencesAsExcluded = snapshot.header.nativeObjectFromConnectionsExcluded;
m_RootPathView = CreateView<RootPathView>();
m_RootPathView.editorPrefsKey = GetPrefsKey(() => m_RootPathView);
// The list at the left that contains all native objects
m_NativeObjectsControl = new NativeObjectsControl(window, GetPrefsKey(() => m_NativeObjectsControl), new TreeViewState());
m_NativeObjectsControl.onSelectionChange += OnListViewSelectionChange;
//m_NativeObjectsControl.gotoCB += Goto;
m_SearchField = new HeSearchField(window);
m_SearchField.downOrUpArrowKeyPressed += m_NativeObjectsControl.SetFocusAndEnsureSelectedItem;
m_NativeObjectsControl.findPressed += m_SearchField.SetFocus;
// The list at the right that shows the selected native object
m_NativeObjectControl = new NativeObjectControl(window, GetPrefsKey(() => m_NativeObjectControl), new TreeViewState());
m_PreviewView = CreateView<NativeObjectPreviewView>();
m_SplitterHorz = EditorPrefs.GetFloat(GetPrefsKey(() => m_SplitterHorz), m_SplitterHorz);
m_SplitterVert = EditorPrefs.GetFloat(GetPrefsKey(() => m_SplitterVert), m_SplitterVert);
m_PreviewSplitterVert = EditorPrefs.GetFloat(GetPrefsKey(() => m_PreviewSplitterVert), m_PreviewSplitterVert);
m_RootPathSplitterVert = EditorPrefs.GetFloat(GetPrefsKey(() => m_RootPathSplitterVert), m_RootPathSplitterVert);
OnRebuild();
}
protected override void OnHide()
{
base.OnHide();
m_NativeObjectsControl.SaveLayout();
m_NativeObjectControl.SaveLayout();
EditorPrefs.SetFloat(GetPrefsKey(() => m_SplitterHorz), m_SplitterHorz);
EditorPrefs.SetFloat(GetPrefsKey(() => m_SplitterVert), m_SplitterVert);
EditorPrefs.SetFloat(GetPrefsKey(() => m_PreviewSplitterVert), m_PreviewSplitterVert);
EditorPrefs.SetFloat(GetPrefsKey(() => m_RootPathSplitterVert), m_RootPathSplitterVert);
}
protected virtual void OnRebuild()
{
// Derived classes overwrite this method to trigger their
// individual tree rebuild jobs
}
protected void DrawFilterToolbarButton()
{
var hasFilter = false;
if (!showAssets) hasFilter = true;
if (!showSceneObjects) hasFilter = true;
if (!showRuntimeObjects) hasFilter = true;
if (!showDestroyOnLoadObjects) hasFilter = true;
if (!showDontDestroyOnLoadObjects) hasFilter = true;
var oldColor = GUI.color;
if (hasFilter)
GUI.color = new Color(oldColor.r, oldColor.g * 0.75f, oldColor.b * 0.75f, oldColor.a);
if (GUILayout.Button(new GUIContent("Filter"), EditorStyles.toolbarDropDown, GUILayout.Width(70)))
{
PopupWindow.Show(m_FilterButtonRect, new NativeObjectsFilterWindowContent(this));
}
if (Event.current.type == EventType.Repaint)
m_FilterButtonRect = GUILayoutUtility.GetLastRect();
GUI.color = oldColor;
}
public override void RestoreCommand(GotoCommand command)
{
if (command.toNativeObject.isValid)
{
m_NativeObjectsControl.Select(command.toNativeObject.packed);
return;
}
base.RestoreCommand(command);
}
public override GotoCommand GetRestoreCommand()
{
if (m_Selected.HasValue)
return new GotoCommand(new RichNativeObject(snapshot, m_Selected.Value.nativeObjectsArrayIndex));
return base.GetRestoreCommand();
}
public override void OnToolbarGUI()
{
base.OnToolbarGUI();
DrawFilterToolbarButton();
}
public override void OnGUI()
{
base.OnGUI();
using (new EditorGUILayout.HorizontalScope())
{
using (new EditorGUILayout.VerticalScope())
{
// Native objects list at the left side
using (new EditorGUILayout.VerticalScope(HeEditorStyles.panel))
{
using (new EditorGUILayout.HorizontalScope())
{
OnDrawHeader();
if (m_SearchField.OnToolbarGUI())
m_NativeObjectsControl.Search(m_SearchField.text);
}
GUILayout.Space(2);
m_NativeObjectsControl.OnGUI();
}
m_SplitterVert = HeEditorGUILayout.VerticalSplitter("m_splitterVert".GetHashCode(), m_SplitterVert, 0.1f, 0.8f, window);
using (new EditorGUILayout.HorizontalScope(GUILayout.Height(window.position.height * m_SplitterVert)))
{
m_ConnectionsView.OnGUI();
}
}
m_SplitterHorz = HeEditorGUILayout.HorizontalSplitter("m_splitterHorz".GetHashCode(), m_SplitterHorz, 0.1f, 0.8f, window);
// Various panels at the right side
using (new EditorGUILayout.VerticalScope(GUILayout.Width(window.position.width * m_SplitterHorz)))
{
using (new EditorGUILayout.VerticalScope(HeEditorStyles.panel))
{
using (new EditorGUILayout.HorizontalScope(GUILayout.MaxWidth(16)))
{
if (m_Selected.HasValue)
{
HeEditorGUI.NativeObjectIcon(GUILayoutUtility.GetRect(16, 16), m_Selected.Value);
//GUI.DrawTexture(r, HeEditorStyles.assetImage);
}
EditorGUILayout.LabelField("Native UnityEngine object", EditorStyles.boldLabel);
}
GUILayout.Space(2);
m_NativeObjectControl.OnGUI();
}
m_PreviewSplitterVert = HeEditorGUILayout.VerticalSplitter("m_PreviewSplitterVert".GetHashCode(), m_PreviewSplitterVert, 0.1f, 0.8f, window);
using (new EditorGUILayout.VerticalScope(HeEditorStyles.panel, GUILayout.Height(window.position.height * m_PreviewSplitterVert)))
{
m_PreviewView.OnGUI();
}
m_RootPathSplitterVert = HeEditorGUILayout.VerticalSplitter("m_RootPathSplitterVert".GetHashCode(), m_RootPathSplitterVert, 0.1f, 0.8f, window);
using (new EditorGUILayout.VerticalScope(HeEditorStyles.panel, GUILayout.Height(window.position.height * m_RootPathSplitterVert)))
{
m_RootPathView.OnGUI();
}
}
}
}
protected virtual void OnDrawHeader()
{
}
void OnListViewSelectionChange(PackedNativeUnityEngineObject? nativeObject)
{
m_Selected = nativeObject;
if (!m_Selected.HasValue)
{
m_RootPathView.Clear();
m_ConnectionsView.Clear();
m_NativeObjectControl.Clear();
m_PreviewView.Clear();
return;
}
m_ConnectionsView.Inspect(m_Selected.Value);
m_NativeObjectControl.Inspect(snapshot, m_Selected.Value);
m_PreviewView.Inspect(m_Selected.Value);
m_RootPathView.Inspect(m_Selected.Value);
}
// The 'Filer' menu displays this content
class NativeObjectsFilterWindowContent : PopupWindowContent
{
AbstractNativeObjectsView m_Owner;
bool m_ShowAssets;
bool m_ShowSceneObjects;
bool m_ShowRuntimeObjects;
bool m_ShowDestroyOnLoadObjects;
bool m_ShowDontDestroyOnLoadObjects;
public NativeObjectsFilterWindowContent(AbstractNativeObjectsView owner)
{
m_Owner = owner;
}
public override Vector2 GetWindowSize()
{
return new Vector2(280, 190);
}
public override void OnGUI(Rect rect)
{
if (m_Owner == null)
{
editorWindow.Close();
return;
}
GUILayout.Space(4);
GUILayout.Label("Object types", EditorStyles.boldLabel);
m_ShowAssets = GUILayout.Toggle(m_ShowAssets, new GUIContent("Show assets", HeEditorStyles.assetImage), GUILayout.Height(18));
m_ShowSceneObjects = GUILayout.Toggle(m_ShowSceneObjects, new GUIContent("Show scene objects", HeEditorStyles.sceneImage), GUILayout.Height(18));
m_ShowRuntimeObjects = GUILayout.Toggle(m_ShowRuntimeObjects, new GUIContent("Show runtime objects", HeEditorStyles.instanceImage), GUILayout.Height(18));
GUILayout.Space(4);
GUILayout.Label("Object flags", EditorStyles.boldLabel);
m_ShowDestroyOnLoadObjects = GUILayout.Toggle(m_ShowDestroyOnLoadObjects, new GUIContent("Show 'Destroy on load' assets/objects"), GUILayout.Height(18));
m_ShowDontDestroyOnLoadObjects = GUILayout.Toggle(m_ShowDontDestroyOnLoadObjects, new GUIContent("Show 'Don't destroy on load' assets/objects"), GUILayout.Height(18));
GUILayout.Space(14);
if (GUILayout.Button("Apply"))
{
Apply();
editorWindow.Close();
}
}
void Apply()
{
m_Owner.showAssets = m_ShowAssets;
m_Owner.showSceneObjects = m_ShowSceneObjects;
m_Owner.showRuntimeObjects = m_ShowRuntimeObjects;
m_Owner.showDestroyOnLoadObjects = m_ShowDestroyOnLoadObjects;
m_Owner.showDontDestroyOnLoadObjects = m_ShowDontDestroyOnLoadObjects;
m_Owner.OnRebuild();
}
public override void OnOpen()
{
m_ShowAssets = m_Owner.showAssets;
m_ShowSceneObjects = m_Owner.showSceneObjects;
m_ShowRuntimeObjects = m_Owner.showRuntimeObjects;
m_ShowDestroyOnLoadObjects = m_Owner.showDestroyOnLoadObjects;
m_ShowDontDestroyOnLoadObjects = m_Owner.showDontDestroyOnLoadObjects;
}
public override void OnClose()
{
}
}
}
}