-
Notifications
You must be signed in to change notification settings - Fork 157
Expand file tree
/
Copy pathAbstractView.cs
More file actions
208 lines (174 loc) · 4.92 KB
/
AbstractView.cs
File metadata and controls
208 lines (174 loc) · 4.92 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
//
// 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;
using System;
using System.Linq.Expressions;
namespace HeapExplorer
{
abstract public class HeapExplorerView
{
/// <summary>
/// The titleContent is shown in Heap Explorer's toolbar View menu.
/// </summary>
public GUIContent titleContent
{
get;
set;
}
/// <summary>
/// Lets you control the menu item order in Heap Explorer's View menu.
/// Specify a negative value to not create an item in the View menu.
/// If two items are 100 units apart, Heap Explorer inserts a seperator item.
/// </summary>
public int viewMenuOrder
{
get;
set;
}
/// <summary>
/// The window in which the view is rendered to.
/// </summary>
public HeapExplorerWindow window
{
get;
internal set;
}
/// <summary>
/// Gets whether the view is currently active.
/// </summary>
public bool isVisible
{
get;
private set;
}
/// <summary>
/// Gets the active memory snapshot.
/// </summary>
public PackedMemorySnapshot snapshot
{
get;
private set;
}
/// <summary>
/// The key-prefix to load and save EditorPrefs.
/// </summary>
public string editorPrefsKey
{
get;
set;
}
List<HeapExplorerView> m_Views = new List<HeapExplorerView>();
// This allows to pass a member variable whose name is converted to a string.
protected string GetPrefsKey(Expression<Func<object>> exp)
{
var body = exp.Body as MemberExpression;
if (body == null)
{
var ubody = (UnaryExpression)exp.Body;
body = ubody.Operand as MemberExpression;
}
return $"HeapExplorer.{editorPrefsKey}.{body.Member.Name}";
}
public HeapExplorerView()
{
editorPrefsKey = GetType().Name;
viewMenuOrder = int.MaxValue - 1;
}
public virtual void Awake()
{
titleContent = new GUIContent(ObjectNames.NicifyVariableName(GetType().Name));
}
public virtual void OnDestroy()
{
foreach (var v in m_Views)
v.OnDestroy();
m_Views = null;
snapshot = null;
}
internal void EvictHeap()
{
snapshot = null;
}
public void Show(PackedMemorySnapshot heap)
{
if (snapshot != heap)
{
if (snapshot != null && isVisible)
Hide(); // Hide normally implements to save the layout of various UI elements
snapshot = heap;
OnCreate();
}
OnShow();
// Show any views that might have been added during OnShow()
foreach (var v in m_Views)
v.Show(heap);
isVisible = true;
Repaint();
}
public void Hide()
{
OnHide();
foreach (var v in m_Views)
v.Hide();
isVisible = false;
Repaint();
}
public virtual int CanProcessCommand(GotoCommand command)
{
return 0;
}
public virtual void RestoreCommand(GotoCommand command)
{
}
public virtual GotoCommand GetRestoreCommand()
{
return new GotoCommand();
}
/// <summary>
/// Implement your own editor GUI here.
/// </summary>
public virtual void OnGUI()
{
}
/// <summary>
/// Implement the OnToolbarGUI method to draw your own GUI in Heap Explorer's toolbar menu.
/// </summary>
public virtual void OnToolbarGUI()
{
}
protected virtual void OnCreate()
{
}
protected virtual void OnShow()
{
}
protected virtual void OnHide()
{
}
protected void Goto(GotoCommand command)
{
window.OnGoto(command);
}
protected void Repaint()
{
window.Repaint();
}
protected void ScheduleJob(AbstractThreadJob job)
{
window.ScheduleJob(job);
}
protected T CreateView<T>() where T : HeapExplorerView, new()
{
var view = new T();
view.window = window;
view.Awake();
m_Views.Add(view);
return view;
}
}
}