forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackendData.cs
More file actions
279 lines (253 loc) · 5.5 KB
/
Copy pathBackendData.cs
File metadata and controls
279 lines (253 loc) · 5.5 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
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace UnityEditor.TreeViewExamples
{
internal class BackendData
{
public class Foo
{
public string name
{
get;
set;
}
public int id
{
get;
set;
}
public int depth
{
get;
set;
}
public BackendData.Foo parent
{
get;
set;
}
public List<BackendData.Foo> children
{
get;
set;
}
public bool hasChildren
{
get
{
return this.children != null && this.children.Count > 0;
}
}
public Foo(string name, int depth, int id)
{
this.name = name;
this.depth = depth;
this.id = id;
}
}
private BackendData.Foo m_Root;
public bool m_RecursiveFindParentsBelow = true;
private int m_MaxItems = 10000;
private const int k_MinChildren = 3;
private const int k_MaxChildren = 15;
private const float k_ProbOfLastDescendent = 0.5f;
private const int k_MaxDepth = 12;
public BackendData.Foo root
{
get
{
return this.m_Root;
}
}
public int IDCounter
{
get;
private set;
}
public void GenerateData(int maxNumItems)
{
this.m_MaxItems = maxNumItems;
this.IDCounter = 1;
this.m_Root = new BackendData.Foo("Root", 0, 0);
for (int i = 0; i < 10; i++)
{
this.AddChildrenRecursive(this.m_Root, UnityEngine.Random.Range(3, 15), true);
}
}
public BackendData.Foo Find(int id)
{
return this.FindRecursive(id, this.m_Root);
}
public BackendData.Foo FindRecursive(int id, BackendData.Foo parent)
{
BackendData.Foo result;
if (!parent.hasChildren)
{
result = null;
}
else
{
foreach (BackendData.Foo current in parent.children)
{
if (current.id == id)
{
result = current;
return result;
}
BackendData.Foo foo = this.FindRecursive(id, current);
if (foo != null)
{
result = foo;
return result;
}
}
result = null;
}
return result;
}
public HashSet<int> GetParentsBelow(int id)
{
BackendData.Foo foo = BackendData.FindItemRecursive(this.root, id);
HashSet<int> result;
if (foo != null)
{
if (this.m_RecursiveFindParentsBelow)
{
result = this.GetParentsBelowRecursive(foo);
}
else
{
result = this.GetParentsBelowStackBased(foo);
}
}
else
{
result = new HashSet<int>();
}
return result;
}
private HashSet<int> GetParentsBelowStackBased(BackendData.Foo searchFromThis)
{
Stack<BackendData.Foo> stack = new Stack<BackendData.Foo>();
stack.Push(searchFromThis);
HashSet<int> hashSet = new HashSet<int>();
while (stack.Count > 0)
{
BackendData.Foo foo = stack.Pop();
if (foo.hasChildren)
{
hashSet.Add(foo.id);
foreach (BackendData.Foo current in foo.children)
{
stack.Push(current);
}
}
}
return hashSet;
}
private HashSet<int> GetParentsBelowRecursive(BackendData.Foo searchFromThis)
{
HashSet<int> hashSet = new HashSet<int>();
BackendData.GetParentsBelowRecursive(searchFromThis, hashSet);
return hashSet;
}
private static void GetParentsBelowRecursive(BackendData.Foo item, HashSet<int> parentIDs)
{
if (item.hasChildren)
{
parentIDs.Add(item.id);
foreach (BackendData.Foo current in item.children)
{
BackendData.GetParentsBelowRecursive(current, parentIDs);
}
}
}
public void ReparentSelection(BackendData.Foo parentItem, int insertionIndex, List<BackendData.Foo> draggedItems)
{
if (parentItem != null)
{
if (insertionIndex > 0)
{
insertionIndex -= parentItem.children.GetRange(0, insertionIndex).Count(new Func<BackendData.Foo, bool>(draggedItems.Contains));
}
foreach (BackendData.Foo current in draggedItems)
{
current.parent.children.Remove(current);
current.parent = parentItem;
}
if (!parentItem.hasChildren)
{
parentItem.children = new List<BackendData.Foo>();
}
List<BackendData.Foo> list = new List<BackendData.Foo>(parentItem.children);
if (insertionIndex == -1)
{
insertionIndex = 0;
}
list.InsertRange(insertionIndex, draggedItems);
parentItem.children = list;
}
}
private void AddChildrenRecursive(BackendData.Foo foo, int numChildren, bool force)
{
if (this.IDCounter <= this.m_MaxItems)
{
if (foo.depth < 12)
{
if (force || UnityEngine.Random.value >= 0.5f)
{
if (foo.children == null)
{
foo.children = new List<BackendData.Foo>(numChildren);
}
for (int i = 0; i < numChildren; i++)
{
BackendData.Foo foo2 = new BackendData.Foo("Tud" + this.IDCounter, foo.depth + 1, ++this.IDCounter);
foo2.parent = foo;
foo.children.Add(foo2);
}
if (this.IDCounter <= this.m_MaxItems)
{
foreach (BackendData.Foo current in foo.children)
{
this.AddChildrenRecursive(current, UnityEngine.Random.Range(3, 15), false);
}
}
}
}
}
}
public static BackendData.Foo FindItemRecursive(BackendData.Foo item, int id)
{
BackendData.Foo result;
if (item == null)
{
result = null;
}
else if (item.id == id)
{
result = item;
}
else if (item.children == null)
{
result = null;
}
else
{
foreach (BackendData.Foo current in item.children)
{
BackendData.Foo foo = BackendData.FindItemRecursive(current, id);
if (foo != null)
{
result = foo;
return result;
}
}
result = null;
}
return result;
}
}
}