forked from pschraut/UnityHeapExplorer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRootPathView.cs
More file actions
159 lines (132 loc) · 4.57 KB
/
Copy pathRootPathView.cs
File metadata and controls
159 lines (132 loc) · 4.57 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
//
// 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 RootPathView : HeapExplorerView
{
RootPath m_Selected;
RootPathControl m_RootPathControl;
RootPathUtility m_RootPaths = new RootPathUtility();
protected override void OnCreate()
{
base.OnCreate();
m_RootPathControl = new RootPathControl(window, GetPrefsKey(() => m_RootPathControl), new TreeViewState());
m_RootPathControl.onSelectionChange += OnSelectionChange;
}
protected override void OnHide()
{
base.OnHide();
m_RootPathControl.SaveLayout();
}
public override void OnGUI()
{
base.OnGUI();
using (new EditorGUI.DisabledGroupScope(m_RootPaths.isBusy))
{
using (new EditorGUILayout.VerticalScope())
{
using (new EditorGUILayout.HorizontalScope())
{
EditorGUILayout.LabelField(string.Format("{0} Path(s) to Root", m_RootPaths.count), EditorStyles.boldLabel);
}
GUILayout.Space(2);
m_RootPathControl.OnGUI();
GUILayout.Space(2);
var reason = "No root object selected.";
if (m_Selected != null)
reason = m_Selected.reasonString;
EditorGUI.HelpBox(GUILayoutUtility.GetRect(10, 48, GUILayout.ExpandWidth(true)), reason, MessageType.Info);
}
}
if (m_RootPaths.isBusy)
{
var r = GUILayoutUtility.GetLastRect();
r.x = r.center.x - 100;
r.width = 200;
r.y = r.center.y - 70;
r.height = 50;
GUI.Label(r, string.Format("Finding root paths, please wait.\n{0} objects scanned", m_RootPaths.scanned), HeEditorStyles.centeredWordWrapLabel);
r = GUILayoutUtility.GetLastRect();
r.x = r.center.x - 60;
r.width = 120;
r.y = r.center.y - 20;
r.height = 24;
if (GUI.Button(r, "Cancel"))
{
m_RootPaths.Abort();
}
}
}
public void Inspect(PackedNativeUnityEngineObject item)
{
m_Selected = null;
ScheduleJob(new ObjectProxy(snapshot, item));
}
public void Inspect(PackedManagedObject item)
{
m_Selected = null;
ScheduleJob(new ObjectProxy(snapshot, item));
}
public void Inspect(PackedManagedStaticField item)
{
m_Selected = null;
ScheduleJob(new ObjectProxy(snapshot, item));
}
public void Inspect(PackedGCHandle item)
{
m_Selected = null;
ScheduleJob(new ObjectProxy(snapshot, item));
}
public void Clear()
{
m_RootPathControl.SetTree(null);
m_Selected = null;
m_RootPaths.Abort();
m_RootPaths = new RootPathUtility();
ScheduleJob(new RootPathJob() { control = m_RootPathControl });
}
void ScheduleJob(ObjectProxy objectProxy)
{
Clear();
var job = new RootPathJob
{
snapshot = snapshot,
objectProxy = objectProxy,
control = m_RootPathControl,
paths = m_RootPaths
};
ScheduleJob(job);
}
void OnSelectionChange(RootPath path)
{
m_Selected = path;
}
class RootPathJob : AbstractThreadJob
{
public ObjectProxy objectProxy;
public RootPathControl control;
public PackedMemorySnapshot snapshot;
// in/out
public RootPathUtility paths;
// Output
public TreeViewItem tree;
public override void ThreadFunc()
{
if (objectProxy != null)
paths.Find(objectProxy);
tree = control.BuildTree(snapshot, paths);
}
public override void IntegrateFunc()
{
control.SetTree(tree);
}
}
}
}