forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReorderableList.cs
More file actions
744 lines (744 loc) · 22.8 KB
/
Copy pathReorderableList.cs
File metadata and controls
744 lines (744 loc) · 22.8 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
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
namespace UnityEditorInternal
{
public class ReorderableList
{
public class Defaults
{
private const int buttonWidth = 25;
public const int padding = 6;
public const int dragHandleWidth = 20;
public GUIContent iconToolbarPlus = EditorGUIUtility.IconContent("Toolbar Plus", "Add to list");
public GUIContent iconToolbarPlusMore = EditorGUIUtility.IconContent("Toolbar Plus More", "Choose to add to list");
public GUIContent iconToolbarMinus = EditorGUIUtility.IconContent("Toolbar Minus", "Remove selection from list");
public readonly GUIStyle draggingHandle = "RL DragHandle";
public readonly GUIStyle headerBackground = "RL Header";
public readonly GUIStyle footerBackground = "RL Footer";
public readonly GUIStyle boxBackground = "RL Background";
public readonly GUIStyle preButton = "RL FooterButton";
public GUIStyle elementBackground = new GUIStyle("RL Element");
public void DrawFooter(Rect rect, ReorderableList list)
{
float xMax = rect.xMax;
float num = xMax - 8f;
if (list.displayAdd)
{
num -= 25f;
}
if (list.displayRemove)
{
num -= 25f;
}
rect = new Rect(num, rect.y, xMax - num, rect.height);
Rect rect2 = new Rect(num + 4f, rect.y - 3f, 25f, 13f);
Rect position = new Rect(xMax - 29f, rect.y - 3f, 25f, 13f);
if (Event.current.type == EventType.Repaint)
{
this.footerBackground.Draw(rect, false, false, false, false);
}
if (list.displayAdd && GUI.Button(rect2, (list.onAddDropdownCallback == null) ? this.iconToolbarPlus : this.iconToolbarPlusMore, this.preButton))
{
if (list.onAddDropdownCallback != null)
{
list.onAddDropdownCallback(rect2, list);
}
else
{
if (list.onAddCallback != null)
{
list.onAddCallback(list);
}
else
{
this.DoAddButton(list);
}
}
if (list.onChangedCallback != null)
{
list.onChangedCallback(list);
}
}
if (list.displayRemove)
{
EditorGUI.BeginDisabledGroup(list.index < 0 || list.index >= list.count || (list.onCanRemoveCallback != null && !list.onCanRemoveCallback(list)));
if (GUI.Button(position, this.iconToolbarMinus, this.preButton))
{
if (list.onRemoveCallback == null)
{
this.DoRemoveButton(list);
}
else
{
list.onRemoveCallback(list);
}
if (list.onChangedCallback != null)
{
list.onChangedCallback(list);
}
}
EditorGUI.EndDisabledGroup();
}
}
public void DoAddButton(ReorderableList list)
{
if (list.serializedProperty != null)
{
list.serializedProperty.arraySize++;
list.index = list.serializedProperty.arraySize - 1;
}
else
{
Type elementType = list.list.GetType().GetElementType();
if (elementType == typeof(string))
{
list.index = list.list.Add(string.Empty);
}
else
{
if (elementType != null && elementType.GetConstructor(Type.EmptyTypes) == null)
{
Debug.LogError("Cannot add element. Type " + elementType.ToString() + " has no default constructor. Implement a default constructor or implement your own add behaviour.");
}
else
{
if (list.list.GetType().GetGenericArguments()[0] != null)
{
list.index = list.list.Add(Activator.CreateInstance(list.list.GetType().GetGenericArguments()[0]));
}
else
{
if (elementType != null)
{
list.index = list.list.Add(Activator.CreateInstance(elementType));
}
else
{
Debug.LogError("Cannot add element of type Null.");
}
}
}
}
}
}
public void DoRemoveButton(ReorderableList list)
{
if (list.serializedProperty != null)
{
list.serializedProperty.DeleteArrayElementAtIndex(list.index);
if (list.index >= list.serializedProperty.arraySize - 1)
{
list.index = list.serializedProperty.arraySize - 1;
}
}
else
{
list.list.RemoveAt(list.index);
if (list.index >= list.list.Count - 1)
{
list.index = list.list.Count - 1;
}
}
}
public void DrawHeaderBackground(Rect headerRect)
{
if (Event.current.type == EventType.Repaint)
{
this.headerBackground.Draw(headerRect, false, false, false, false);
}
}
public void DrawHeader(Rect headerRect, SerializedObject serializedObject, SerializedProperty element, IList elementList)
{
EditorGUI.LabelField(headerRect, EditorGUIUtility.TempContent((element == null) ? "IList" : "Serialized Property"));
}
public void DrawElementBackground(Rect rect, int index, bool selected, bool focused, bool draggable)
{
if (Event.current.type == EventType.Repaint)
{
this.elementBackground.Draw(rect, false, selected, selected, focused);
}
}
public void DrawElementDraggingHandle(Rect rect, int index, bool selected, bool focused, bool draggable)
{
if (Event.current.type == EventType.Repaint && draggable)
{
this.draggingHandle.Draw(new Rect(rect.x + 5f, rect.y + 7f, 10f, rect.height - (rect.height - 7f)), false, false, false, false);
}
}
public void DrawElement(Rect rect, SerializedProperty element, object listItem, bool selected, bool focused, bool draggable)
{
EditorGUI.LabelField(rect, EditorGUIUtility.TempContent((element == null) ? listItem.ToString() : element.displayName));
}
public void DrawNoneElement(Rect rect, bool draggable)
{
EditorGUI.LabelField(rect, EditorGUIUtility.TempContent("List is Empty"));
}
}
public delegate void HeaderCallbackDelegate(Rect rect);
public delegate void FooterCallbackDelegate(Rect rect);
public delegate void ElementCallbackDelegate(Rect rect, int index, bool isActive, bool isFocused);
public delegate void ReorderCallbackDelegate(ReorderableList list);
public delegate void SelectCallbackDelegate(ReorderableList list);
public delegate void AddCallbackDelegate(ReorderableList list);
public delegate void AddDropdownCallbackDelegate(Rect buttonRect, ReorderableList list);
public delegate void RemoveCallbackDelegate(ReorderableList list);
public delegate void ChangedCallbackDelegate(ReorderableList list);
public delegate bool CanRemoveCallbackDelegate(ReorderableList list);
public ReorderableList.HeaderCallbackDelegate drawHeaderCallback;
public ReorderableList.FooterCallbackDelegate drawFooterCallback;
public ReorderableList.ElementCallbackDelegate drawElementCallback;
public ReorderableList.ElementCallbackDelegate drawElementBackgroundCallback;
public ReorderableList.ReorderCallbackDelegate onReorderCallback;
public ReorderableList.SelectCallbackDelegate onSelectCallback;
public ReorderableList.AddCallbackDelegate onAddCallback;
public ReorderableList.AddDropdownCallbackDelegate onAddDropdownCallback;
public ReorderableList.RemoveCallbackDelegate onRemoveCallback;
public ReorderableList.SelectCallbackDelegate onMouseUpCallback;
public ReorderableList.CanRemoveCallbackDelegate onCanRemoveCallback;
public ReorderableList.ChangedCallbackDelegate onChangedCallback;
private int m_ActiveElement = -1;
private float m_DragOffset;
private GUISlideGroup m_SlideGroup;
private SerializedObject m_SerializedObject;
private SerializedProperty m_Elements;
private IList m_ElementList;
private bool m_Draggable;
private float m_DraggedY;
private bool m_Dragging;
private List<int> m_NonDragTargetIndices;
private bool m_DisplayHeader;
public bool displayAdd;
public bool displayRemove;
private int id = -1;
private static ReorderableList.Defaults s_Defaults;
public float elementHeight = 21f;
public float headerHeight = 18f;
public float footerHeight = 13f;
public bool showDefaultBackground = true;
public static ReorderableList.Defaults defaultBehaviours
{
get
{
return ReorderableList.s_Defaults;
}
}
public SerializedProperty serializedProperty
{
get
{
return this.m_Elements;
}
set
{
this.m_Elements = value;
}
}
public IList list
{
get
{
return this.m_ElementList;
}
set
{
this.m_ElementList = value;
}
}
public int index
{
get
{
return this.m_ActiveElement;
}
set
{
this.m_ActiveElement = value;
}
}
public bool draggable
{
get
{
return this.m_Draggable;
}
set
{
this.m_Draggable = value;
}
}
public int count
{
get
{
if (this.m_Elements == null)
{
return this.m_ElementList.Count;
}
if (!this.m_Elements.hasMultipleDifferentValues)
{
return this.m_Elements.arraySize;
}
int num = this.m_Elements.arraySize;
UnityEngine.Object[] targetObjects = this.m_Elements.serializedObject.targetObjects;
for (int i = 0; i < targetObjects.Length; i++)
{
UnityEngine.Object obj = targetObjects[i];
SerializedObject serializedObject = new SerializedObject(obj);
SerializedProperty serializedProperty = serializedObject.FindProperty(this.m_Elements.propertyPath);
num = Math.Min(serializedProperty.arraySize, num);
}
return num;
}
}
public ReorderableList(IList elements, Type elementType)
{
this.InitList(null, null, elements, true, true, true, true);
}
public ReorderableList(IList elements, Type elementType, bool draggable, bool displayHeader, bool displayAddButton, bool displayRemoveButton)
{
this.InitList(null, null, elements, draggable, displayHeader, displayAddButton, displayRemoveButton);
}
public ReorderableList(SerializedObject serializedObject, SerializedProperty elements)
{
this.InitList(serializedObject, elements, null, true, true, true, true);
}
public ReorderableList(SerializedObject serializedObject, SerializedProperty elements, bool draggable, bool displayHeader, bool displayAddButton, bool displayRemoveButton)
{
this.InitList(serializedObject, elements, null, draggable, displayHeader, displayAddButton, displayRemoveButton);
}
private void InitList(SerializedObject serializedObject, SerializedProperty elements, IList elementList, bool draggable, bool displayHeader, bool displayAddButton, bool displayRemoveButton)
{
this.id = GUIUtility.GetPermanentControlID();
this.m_SerializedObject = serializedObject;
this.m_Elements = elements;
this.m_ElementList = elementList;
this.m_Draggable = draggable;
this.m_Dragging = false;
this.m_SlideGroup = new GUISlideGroup();
this.displayAdd = displayAddButton;
this.m_DisplayHeader = displayHeader;
this.displayRemove = displayRemoveButton;
if (this.m_Elements != null && !this.m_Elements.editable)
{
this.m_Draggable = false;
}
if (this.m_Elements != null && !this.m_Elements.isArray)
{
Debug.LogError("Input elements should be an Array SerializedProperty");
}
}
private Rect GetContentRect(Rect rect)
{
Rect result = rect;
if (this.draggable)
{
result.xMin += 20f;
}
else
{
result.xMin += 6f;
}
result.xMax -= 6f;
return result;
}
private Rect GetRowRect(int index, Rect listRect)
{
return new Rect(listRect.x, listRect.y + (float)index * this.elementHeight, listRect.width, this.elementHeight);
}
public void DoLayoutList()
{
if (ReorderableList.s_Defaults == null)
{
ReorderableList.s_Defaults = new ReorderableList.Defaults();
}
Rect rect = GUILayoutUtility.GetRect(0f, this.headerHeight, new GUILayoutOption[]
{
GUILayout.ExpandWidth(true)
});
Rect rect2 = GUILayoutUtility.GetRect(10f, this.GetListElementHeight(), new GUILayoutOption[]
{
GUILayout.ExpandWidth(true)
});
Rect rect3 = GUILayoutUtility.GetRect(4f, this.footerHeight, new GUILayoutOption[]
{
GUILayout.ExpandWidth(true)
});
this.DoListHeader(rect);
this.DoListElements(rect2);
this.DoListFooter(rect3);
}
public void DoList(Rect rect)
{
if (ReorderableList.s_Defaults == null)
{
ReorderableList.s_Defaults = new ReorderableList.Defaults();
}
Rect headerRect = new Rect(rect.x, rect.y, rect.width, this.headerHeight);
Rect listRect = new Rect(rect.x, headerRect.y + headerRect.height, rect.width, this.GetListElementHeight());
Rect footerRect = new Rect(rect.x, listRect.y + listRect.height, rect.width, this.footerHeight);
this.DoListHeader(headerRect);
this.DoListElements(listRect);
this.DoListFooter(footerRect);
}
public float GetHeight()
{
float num = 0f;
num += this.GetListElementHeight();
num += this.headerHeight;
return num + this.footerHeight;
}
private float GetListElementHeight()
{
int num = this.count;
if (num == 0)
{
num = 1;
}
return this.elementHeight * (float)num + 7f;
}
private void DoListElements(Rect listRect)
{
int count = this.count;
if (this.showDefaultBackground && Event.current.type == EventType.Repaint)
{
ReorderableList.s_Defaults.boxBackground.Draw(listRect, false, false, false, false);
}
listRect.yMin += 2f;
listRect.yMax -= 5f;
Rect rect = listRect;
rect.height = this.elementHeight;
Rect rect2 = rect;
if (((this.m_Elements != null && this.m_Elements.isArray) || this.m_ElementList != null) && count > 0)
{
if (this.IsDragging() && Event.current.type == EventType.Repaint)
{
int index = this.CalculateRowIndex();
this.m_NonDragTargetIndices.Clear();
for (int i = 0; i < count; i++)
{
if (i != this.m_ActiveElement)
{
this.m_NonDragTargetIndices.Add(i);
}
}
this.m_NonDragTargetIndices.Insert(index, -1);
for (int j = 0; j < this.m_NonDragTargetIndices.Count; j++)
{
if (this.m_NonDragTargetIndices[j] != -1)
{
rect.y = listRect.y + (float)j * this.elementHeight;
rect = this.m_SlideGroup.GetRect(this.m_NonDragTargetIndices[j], rect);
if (this.drawElementBackgroundCallback == null)
{
ReorderableList.s_Defaults.DrawElementBackground(rect, j, false, false, this.m_Draggable);
}
else
{
this.drawElementBackgroundCallback(rect, j, false, false);
}
ReorderableList.s_Defaults.DrawElementDraggingHandle(rect, j, false, false, this.m_Draggable);
rect2 = this.GetContentRect(rect);
if (this.drawElementCallback == null)
{
if (this.m_Elements != null)
{
ReorderableList.s_Defaults.DrawElement(rect2, this.m_Elements.GetArrayElementAtIndex(this.m_NonDragTargetIndices[j]), null, false, false, this.m_Draggable);
}
else
{
ReorderableList.s_Defaults.DrawElement(rect2, null, this.m_ElementList[this.m_NonDragTargetIndices[j]], false, false, this.m_Draggable);
}
}
else
{
this.drawElementCallback(rect2, this.m_NonDragTargetIndices[j], false, false);
}
}
}
rect.y = this.m_DraggedY - this.m_DragOffset + listRect.y;
if (this.drawElementBackgroundCallback == null)
{
ReorderableList.s_Defaults.DrawElementBackground(rect, this.m_ActiveElement, true, true, this.m_Draggable);
}
else
{
this.drawElementBackgroundCallback(rect, this.m_ActiveElement, true, true);
}
ReorderableList.s_Defaults.DrawElementDraggingHandle(rect, this.m_ActiveElement, true, true, this.m_Draggable);
rect2 = this.GetContentRect(rect);
if (this.drawElementCallback == null)
{
if (this.m_Elements != null)
{
ReorderableList.s_Defaults.DrawElement(rect2, this.m_Elements.GetArrayElementAtIndex(this.m_ActiveElement), null, true, true, this.m_Draggable);
}
else
{
ReorderableList.s_Defaults.DrawElement(rect2, null, this.m_ElementList[this.m_ActiveElement], true, true, this.m_Draggable);
}
}
else
{
this.drawElementCallback(rect2, this.m_ActiveElement, true, true);
}
}
else
{
for (int k = 0; k < count; k++)
{
bool flag = k == this.m_ActiveElement;
bool flag2 = k == this.m_ActiveElement && this.HasKeyboardControl();
rect.y = listRect.y + (float)k * this.elementHeight;
if (this.drawElementBackgroundCallback == null)
{
ReorderableList.s_Defaults.DrawElementBackground(rect, k, flag, flag2, this.m_Draggable);
}
else
{
this.drawElementBackgroundCallback(rect, k, flag, flag2);
}
ReorderableList.s_Defaults.DrawElementDraggingHandle(rect, k, flag, flag2, this.m_Draggable);
rect2 = this.GetContentRect(rect);
if (this.drawElementCallback == null)
{
if (this.m_Elements != null)
{
ReorderableList.s_Defaults.DrawElement(rect2, this.m_Elements.GetArrayElementAtIndex(k), null, flag, flag2, this.m_Draggable);
}
else
{
ReorderableList.s_Defaults.DrawElement(rect2, null, this.m_ElementList[k], flag, flag2, this.m_Draggable);
}
}
else
{
this.drawElementCallback(rect2, k, flag, flag2);
}
}
}
this.DoDraggingAndSelection(listRect);
}
else
{
rect.y = listRect.y;
if (this.drawElementBackgroundCallback == null)
{
ReorderableList.s_Defaults.DrawElementBackground(rect, -1, false, false, false);
}
else
{
this.drawElementBackgroundCallback(rect, -1, false, false);
}
ReorderableList.s_Defaults.DrawElementDraggingHandle(rect, -1, false, false, false);
rect2 = rect;
rect2.xMin += 6f;
rect2.xMax -= 6f;
ReorderableList.s_Defaults.DrawNoneElement(rect2, this.m_Draggable);
}
}
private void DoListHeader(Rect headerRect)
{
if (this.showDefaultBackground && Event.current.type == EventType.Repaint)
{
ReorderableList.s_Defaults.DrawHeaderBackground(headerRect);
}
headerRect.xMin += 6f;
headerRect.xMax -= 6f;
headerRect.height -= 2f;
headerRect.y += 1f;
if (this.drawHeaderCallback != null)
{
this.drawHeaderCallback(headerRect);
}
else
{
if (this.m_DisplayHeader)
{
ReorderableList.s_Defaults.DrawHeader(headerRect, this.m_SerializedObject, this.m_Elements, this.m_ElementList);
}
}
}
private void DoListFooter(Rect footerRect)
{
if (this.drawFooterCallback != null)
{
this.drawFooterCallback(footerRect);
}
else
{
if (this.displayAdd || this.displayRemove)
{
ReorderableList.s_Defaults.DrawFooter(footerRect, this);
}
}
}
private void DoDraggingAndSelection(Rect listRect)
{
Event current = Event.current;
int activeElement = this.m_ActiveElement;
bool flag = false;
switch (current.GetTypeForControl(this.id))
{
case EventType.MouseDown:
if (listRect.Contains(Event.current.mousePosition) && Event.current.button == 0)
{
EditorGUI.EndEditingActiveTextField();
this.m_ActiveElement = Mathf.FloorToInt((Event.current.mousePosition.y - listRect.y) / this.elementHeight);
if (this.m_Draggable)
{
this.m_DragOffset = Event.current.mousePosition.y - listRect.y - (float)this.m_ActiveElement * this.elementHeight;
this.UpdateDraggedY(listRect);
GUIUtility.hotControl = this.id;
this.m_SlideGroup.Reset();
this.m_NonDragTargetIndices = new List<int>();
}
this.GrabKeyboardFocus();
current.Use();
flag = true;
}
break;
case EventType.MouseUp:
if (!this.m_Draggable)
{
if (this.onMouseUpCallback != null && this.IsMouseInsideActiveElement(listRect))
{
this.onMouseUpCallback(this);
}
}
else
{
if (GUIUtility.hotControl == this.id)
{
current.Use();
this.m_Dragging = false;
int num = this.CalculateRowIndex();
if (this.m_ActiveElement != num)
{
if (this.m_SerializedObject != null && this.m_Elements != null)
{
this.m_Elements.MoveArrayElement(this.m_ActiveElement, num);
this.m_SerializedObject.ApplyModifiedProperties();
this.m_SerializedObject.Update();
}
else
{
if (this.m_ElementList != null)
{
object value = this.m_ElementList[this.m_ActiveElement];
for (int i = 0; i < this.m_ElementList.Count - 1; i++)
{
if (i >= this.m_ActiveElement)
{
this.m_ElementList[i] = this.m_ElementList[i + 1];
}
}
for (int j = this.m_ElementList.Count - 1; j > 0; j--)
{
if (j > num)
{
this.m_ElementList[j] = this.m_ElementList[j - 1];
}
}
this.m_ElementList[num] = value;
}
}
this.m_ActiveElement = num;
if (this.onReorderCallback != null)
{
this.onReorderCallback(this);
}
if (this.onChangedCallback != null)
{
this.onChangedCallback(this);
}
}
else
{
if (this.onMouseUpCallback != null)
{
this.onMouseUpCallback(this);
}
}
GUIUtility.hotControl = 0;
this.m_NonDragTargetIndices = null;
}
}
break;
case EventType.MouseDrag:
if (this.m_Draggable && GUIUtility.hotControl == this.id)
{
this.m_Dragging = true;
this.UpdateDraggedY(listRect);
current.Use();
}
break;
case EventType.KeyDown:
if (GUIUtility.keyboardControl != this.id)
{
return;
}
if (current.keyCode == KeyCode.DownArrow)
{
this.m_ActiveElement++;
current.Use();
}
if (current.keyCode == KeyCode.UpArrow)
{
this.m_ActiveElement--;
current.Use();
}
if (current.keyCode == KeyCode.Escape && GUIUtility.hotControl == this.id)
{
GUIUtility.hotControl = 0;
this.m_Dragging = false;
current.Use();
}
this.m_ActiveElement = Mathf.Clamp(this.m_ActiveElement, 0, (this.m_Elements == null) ? (this.m_ElementList.Count - 1) : (this.m_Elements.arraySize - 1));
break;
}
if ((this.m_ActiveElement != activeElement || flag) && this.onSelectCallback != null)
{
this.onSelectCallback(this);
}
}
private bool IsMouseInsideActiveElement(Rect listRect)
{
int rowIndex = this.GetRowIndex(Event.current.mousePosition.y - listRect.y);
return rowIndex == this.m_ActiveElement && this.GetRowRect(rowIndex, listRect).Contains(Event.current.mousePosition);
}
private void UpdateDraggedY(Rect listRect)
{
this.m_DraggedY = Mathf.Clamp(Event.current.mousePosition.y - listRect.y, this.m_DragOffset, listRect.height - (this.elementHeight - this.m_DragOffset));
}
private int CalculateRowIndex()
{
return this.GetRowIndex(this.m_DraggedY);
}
private int GetRowIndex(float localY)
{
return Mathf.Clamp(Mathf.FloorToInt(localY / this.elementHeight), 0, this.count - 1);
}
private bool IsDragging()
{
return this.m_Dragging;
}
public void GrabKeyboardFocus()
{
GUIUtility.keyboardControl = this.id;
}
public void ReleaseKeyboardFocus()
{
if (GUIUtility.keyboardControl == this.id)
{
GUIUtility.keyboardControl = 0;
}
}
public bool HasKeyboardControl()
{
return GUIUtility.keyboardControl == this.id;
}
}
}