-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathUITable.cs
294 lines (269 loc) · 6.7 KB
/
UITable.cs
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
using System;
using System.Collections.Generic;
using UnityEngine;
[AddComponentMenu("NGUI/Interaction/Table")]
public class UITable : UIWidgetContainer
{
public enum Direction
{
Down,
Up
}
public enum Sorting
{
None,
Alphabetic,
Horizontal,
Vertical,
Custom
}
public delegate void OnReposition();
public int columns;
public Direction direction;
public Sorting sorting;
public UIWidget.Pivot pivot;
public UIWidget.Pivot cellAlignment;
public bool hideInactive = true;
public bool keepWithinPanel;
public Vector2 padding = Vector2.zero;
public OnReposition onReposition;
public Comparison<Transform> onCustomSort;
protected UIPanel mPanel;
protected bool mInitDone;
protected bool mReposition;
public bool repositionNow
{
set
{
if (value)
{
mReposition = true;
base.enabled = true;
}
}
}
public List<Transform> GetChildList()
{
Transform transform = base.transform;
List<Transform> list = new List<Transform>();
for (int i = 0; i < transform.childCount; i++)
{
Transform child = transform.GetChild(i);
if (!hideInactive || ((bool)child && NGUITools.GetActive(child.gameObject)))
{
list.Add(child);
}
}
if (sorting != 0)
{
if (sorting == Sorting.Alphabetic)
{
list.Sort(UIGrid.SortByName);
}
else if (sorting == Sorting.Horizontal)
{
list.Sort(UIGrid.SortHorizontal);
}
else if (sorting == Sorting.Vertical)
{
list.Sort(UIGrid.SortVertical);
}
else if (onCustomSort != null)
{
list.Sort(onCustomSort);
}
else
{
Sort(list);
}
}
return list;
}
protected virtual void Sort(List<Transform> list)
{
list.Sort(UIGrid.SortByName);
}
protected virtual void Start()
{
Init();
Reposition();
base.enabled = false;
}
protected virtual void Init()
{
mInitDone = true;
mPanel = NGUITools.FindInParents<UIPanel>(base.gameObject);
}
protected virtual void LateUpdate()
{
if (mReposition)
{
Reposition();
}
base.enabled = false;
}
private void OnValidate()
{
if (!Application.isPlaying && NGUITools.GetActive(this))
{
Reposition();
}
}
protected void RepositionVariableSize(List<Transform> children)
{
float num = 0f;
float num2 = 0f;
int num3 = (columns <= 0) ? 1 : (children.Count / columns + 1);
int num4 = (columns <= 0) ? children.Count : columns;
Bounds[,] array = new Bounds[num3, num4];
Bounds[] array2 = new Bounds[num4];
Bounds[] array3 = new Bounds[num3];
int num5 = 0;
int num6 = 0;
int i = 0;
for (int count = children.Count; i < count; i++)
{
Transform transform = children[i];
Bounds bounds = NGUIMath.CalculateRelativeWidgetBounds(transform, !hideInactive);
Vector3 localScale = transform.localScale;
bounds.min = Vector3.Scale(bounds.min, localScale);
bounds.max = Vector3.Scale(bounds.max, localScale);
array[num6, num5] = bounds;
array2[num5].Encapsulate(bounds);
array3[num6].Encapsulate(bounds);
if (++num5 >= columns && columns > 0)
{
num5 = 0;
num6++;
}
}
num5 = 0;
num6 = 0;
Vector2 pivotOffset = NGUIMath.GetPivotOffset(cellAlignment);
int j = 0;
for (int count2 = children.Count; j < count2; j++)
{
Transform transform2 = children[j];
Bounds bounds2 = array[num6, num5];
Bounds bounds3 = array2[num5];
Bounds bounds4 = array3[num6];
Vector3 localPosition = transform2.localPosition;
float num7 = num;
Vector3 extents = bounds2.extents;
float num8 = num7 + extents.x;
Vector3 center = bounds2.center;
localPosition.x = num8 - center.x;
float x = localPosition.x;
Vector3 max = bounds2.max;
float x2 = max.x;
Vector3 min = bounds2.min;
float num9 = x2 - min.x;
Vector3 max2 = bounds3.max;
float num10 = num9 - max2.x;
Vector3 min2 = bounds3.min;
localPosition.x = x - (Mathf.Lerp(0f, num10 + min2.x, pivotOffset.x) - padding.x);
if (direction == Direction.Down)
{
float num11 = 0f - num2;
Vector3 extents2 = bounds2.extents;
float num12 = num11 - extents2.y;
Vector3 center2 = bounds2.center;
localPosition.y = num12 - center2.y;
float y = localPosition.y;
Vector3 max3 = bounds2.max;
float y2 = max3.y;
Vector3 min3 = bounds2.min;
float num13 = y2 - min3.y;
Vector3 max4 = bounds4.max;
float num14 = num13 - max4.y;
Vector3 min4 = bounds4.min;
localPosition.y = y + (Mathf.Lerp(num14 + min4.y, 0f, pivotOffset.y) - padding.y);
}
else
{
float num15 = num2;
Vector3 extents3 = bounds2.extents;
float num16 = num15 + extents3.y;
Vector3 center3 = bounds2.center;
localPosition.y = num16 - center3.y;
float y3 = localPosition.y;
Vector3 max5 = bounds2.max;
float y4 = max5.y;
Vector3 min5 = bounds2.min;
float num17 = y4 - min5.y;
Vector3 max6 = bounds4.max;
float num18 = num17 - max6.y;
Vector3 min6 = bounds4.min;
localPosition.y = y3 - (Mathf.Lerp(0f, num18 + min6.y, pivotOffset.y) - padding.y);
}
float num19 = num;
Vector3 size = bounds3.size;
num = num19 + (size.x + padding.x * 2f);
transform2.localPosition = localPosition;
if (++num5 >= columns && columns > 0)
{
num5 = 0;
num6++;
num = 0f;
float num20 = num2;
Vector3 size2 = bounds4.size;
num2 = num20 + (size2.y + padding.y * 2f);
}
}
if (pivot != 0)
{
pivotOffset = NGUIMath.GetPivotOffset(pivot);
Bounds bounds5 = NGUIMath.CalculateRelativeWidgetBounds(base.transform);
Vector3 size3 = bounds5.size;
float num21 = Mathf.Lerp(0f, size3.x, pivotOffset.x);
Vector3 size4 = bounds5.size;
float num22 = Mathf.Lerp(0f - size4.y, 0f, pivotOffset.y);
Transform transform3 = base.transform;
for (int k = 0; k < transform3.childCount; k++)
{
Transform child = transform3.GetChild(k);
SpringPosition component = child.GetComponent<SpringPosition>();
if (component != null)
{
component.target.x -= num21;
component.target.y -= num22;
}
else
{
Vector3 localPosition2 = child.localPosition;
localPosition2.x -= num21;
localPosition2.y -= num22;
child.localPosition = localPosition2;
}
}
}
}
[ContextMenu("Execute")]
public virtual void Reposition()
{
if (Application.isPlaying && !mInitDone && NGUITools.GetActive(this))
{
Init();
}
mReposition = false;
Transform transform = base.transform;
List<Transform> childList = GetChildList();
if (childList.Count > 0)
{
RepositionVariableSize(childList);
}
if (keepWithinPanel && mPanel != null)
{
mPanel.ConstrainTargetToBounds(transform, immediate: true);
UIScrollView component = mPanel.GetComponent<UIScrollView>();
if (component != null)
{
component.UpdateScrollbars(recalculateBounds: true);
}
}
if (onReposition != null)
{
onReposition();
}
}
}