forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddComponentWindow.cs
More file actions
1036 lines (947 loc) · 27.4 KB
/
Copy pathAddComponentWindow.cs
File metadata and controls
1036 lines (947 loc) · 27.4 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
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using UnityEditorInternal;
using UnityEngine;
namespace UnityEditor
{
[InitializeOnLoad]
internal class AddComponentWindow : EditorWindow
{
internal enum Language
{
CSharp,
JavaScript
}
private class Element : IComparable
{
public int level;
public GUIContent content;
public string name
{
get
{
return this.content.text;
}
}
public virtual int CompareTo(object o)
{
return this.name.CompareTo((o as AddComponentWindow.Element).name);
}
}
private class ComponentElement : AddComponentWindow.Element
{
public string menuPath;
public bool isLegacy;
private GUIContent m_LegacyContentCache;
public GUIContent legacyContent
{
get
{
if (this.m_LegacyContentCache == null)
{
this.m_LegacyContentCache = new GUIContent(this.content);
GUIContent expr_24 = this.m_LegacyContentCache;
expr_24.text += " (Legacy)";
}
return this.m_LegacyContentCache;
}
}
public ComponentElement(int level, string name, string menuPath, string commandString)
{
this.level = level;
this.menuPath = menuPath;
this.isLegacy = menuPath.Contains("Legacy");
if (commandString.StartsWith("SCRIPT"))
{
int instanceID = int.Parse(commandString.Substring(6));
UnityEngine.Object obj = EditorUtility.InstanceIDToObject(instanceID);
Texture miniThumbnail = AssetPreview.GetMiniThumbnail(obj);
this.content = new GUIContent(name, miniThumbnail);
}
else
{
int classID = int.Parse(commandString);
this.content = new GUIContent(name, AssetPreview.GetMiniTypeThumbnailFromClassID(classID));
}
}
public override int CompareTo(object o)
{
int result;
if (o is AddComponentWindow.ComponentElement)
{
AddComponentWindow.ComponentElement componentElement = (AddComponentWindow.ComponentElement)o;
if (this.isLegacy && !componentElement.isLegacy)
{
result = 1;
return result;
}
if (!this.isLegacy && componentElement.isLegacy)
{
result = -1;
return result;
}
}
result = base.CompareTo(o);
return result;
}
}
[Serializable]
private class GroupElement : AddComponentWindow.Element
{
public Vector2 scroll;
public int selectedIndex = 0;
public GroupElement(int level, string name)
{
this.level = level;
this.content = new GUIContent(name);
}
}
private class NewScriptElement : AddComponentWindow.GroupElement
{
private char[] kInvalidPathChars = new char[]
{
'<',
'>',
':',
'"',
'|',
'?',
'*',
'\0'
};
private char[] kPathSepChars = new char[]
{
'/',
'\\'
};
private const string kResourcesTemplatePath = "Resources/ScriptTemplates";
private string m_Directory = string.Empty;
private string extension
{
get
{
AddComponentWindow.Language s_Lang = AddComponentWindow.s_Lang;
string result;
if (s_Lang != AddComponentWindow.Language.CSharp)
{
if (s_Lang != AddComponentWindow.Language.JavaScript)
{
throw new ArgumentOutOfRangeException();
}
result = "js";
}
else
{
result = "cs";
}
return result;
}
}
private string templatePath
{
get
{
string path = Path.Combine(EditorApplication.applicationContentsPath, "Resources/ScriptTemplates");
AddComponentWindow.Language s_Lang = AddComponentWindow.s_Lang;
string result;
if (s_Lang != AddComponentWindow.Language.JavaScript)
{
if (s_Lang != AddComponentWindow.Language.CSharp)
{
throw new ArgumentOutOfRangeException();
}
result = Path.Combine(path, "81-C# Script-NewBehaviourScript.cs.txt");
}
else
{
result = Path.Combine(path, "82-Javascript-NewBehaviourScript.js.txt");
}
return result;
}
}
public NewScriptElement() : base(1, "New Script")
{
}
public void OnGUI()
{
GUILayout.Label("Name", EditorStyles.label, new GUILayoutOption[0]);
EditorGUI.FocusTextInControl("NewScriptName");
GUI.SetNextControlName("NewScriptName");
AddComponentWindow.className = EditorGUILayout.TextField(AddComponentWindow.className, new GUILayoutOption[0]);
EditorGUILayout.Space();
AddComponentWindow.Language language = (AddComponentWindow.Language)EditorGUILayout.EnumPopup("Language", AddComponentWindow.s_Lang, new GUILayoutOption[0]);
if (language != AddComponentWindow.s_Lang)
{
AddComponentWindow.s_Lang = language;
EditorPrefs.SetInt("NewScriptLanguage", (int)language);
}
EditorGUILayout.Space();
bool flag = this.CanCreate();
if (!flag && AddComponentWindow.className != "")
{
GUILayout.Label(this.GetError(), EditorStyles.helpBox, new GUILayoutOption[0]);
}
GUILayout.FlexibleSpace();
using (new EditorGUI.DisabledScope(!flag))
{
if (GUILayout.Button("Create and Add", new GUILayoutOption[0]))
{
this.Create();
}
}
EditorGUILayout.Space();
}
public bool CanCreate()
{
return AddComponentWindow.className.Length > 0 && !File.Exists(this.TargetPath()) && !this.ClassAlreadyExists() && !this.ClassNameIsInvalid() && !this.InvalidTargetPath();
}
private string GetError()
{
string result = string.Empty;
if (AddComponentWindow.className != string.Empty)
{
if (File.Exists(this.TargetPath()))
{
result = "A script called \"" + AddComponentWindow.className + "\" already exists at that path.";
}
else if (this.ClassAlreadyExists())
{
result = "A class called \"" + AddComponentWindow.className + "\" already exists.";
}
else if (this.ClassNameIsInvalid())
{
result = "The script name may only consist of a-z, A-Z, 0-9, _.";
}
else if (this.InvalidTargetPath())
{
result = "The folder path contains invalid characters.";
}
}
return result;
}
public void Create()
{
if (this.CanCreate())
{
this.CreateScript();
GameObject[] gameObjects = AddComponentWindow.gameObjects;
for (int i = 0; i < gameObjects.Length; i++)
{
GameObject gameObject = gameObjects[i];
MonoScript monoScript = AssetDatabase.LoadAssetAtPath(this.TargetPath(), typeof(MonoScript)) as MonoScript;
monoScript.SetScriptTypeWasJustCreatedFromComponentMenu();
InternalEditorUtility.AddScriptComponentUncheckedUndoable(gameObject, monoScript);
}
AddComponentWindow.s_AddComponentWindow.Close();
}
}
private bool InvalidTargetPath()
{
return this.m_Directory.IndexOfAny(this.kInvalidPathChars) >= 0 || this.TargetDir().Split(this.kPathSepChars, StringSplitOptions.None).Contains(string.Empty);
}
public string TargetPath()
{
return Path.Combine(this.TargetDir(), AddComponentWindow.className + "." + this.extension);
}
private string TargetDir()
{
return Path.Combine("Assets", this.m_Directory.Trim(this.kPathSepChars));
}
private bool ClassNameIsInvalid()
{
return !CodeGenerator.IsValidLanguageIndependentIdentifier(AddComponentWindow.className);
}
private bool ClassExists(string className)
{
return AppDomain.CurrentDomain.GetAssemblies().Any((Assembly a) => a.GetType(className, false) != null);
}
private bool ClassAlreadyExists()
{
return !(AddComponentWindow.className == string.Empty) && this.ClassExists(AddComponentWindow.className);
}
private void CreateScript()
{
ProjectWindowUtil.CreateScriptAssetFromTemplate(this.TargetPath(), this.templatePath);
AssetDatabase.Refresh();
}
}
private class Styles
{
public GUIStyle header = new GUIStyle(EditorStyles.inspectorBig);
public GUIStyle componentButton = new GUIStyle("PR Label");
public GUIStyle groupButton;
public GUIStyle background = "grey_border";
public GUIStyle previewHeader = new GUIStyle(EditorStyles.label);
public GUIStyle previewText = new GUIStyle(EditorStyles.wordWrappedLabel);
public GUIStyle rightArrow = "AC RightArrow";
public GUIStyle leftArrow = "AC LeftArrow";
public Styles()
{
this.header.font = EditorStyles.boldLabel.font;
this.componentButton.alignment = TextAnchor.MiddleLeft;
this.componentButton.padding.left -= 15;
this.componentButton.fixedHeight = 20f;
this.groupButton = new GUIStyle(this.componentButton);
this.groupButton.padding.left += 17;
this.previewText.padding.left += 3;
this.previewText.padding.right += 3;
this.previewHeader.padding.left++;
this.previewHeader.padding.right += 3;
this.previewHeader.padding.top += 3;
this.previewHeader.padding.bottom += 2;
}
}
private const AddComponentWindow.Language kDefaultLanguage = AddComponentWindow.Language.CSharp;
private const int kHeaderHeight = 30;
private const int kWindowHeight = 320;
private const int kHelpHeight = 0;
private const string kLanguageEditorPrefName = "NewScriptLanguage";
private const string kComponentSearch = "ComponentSearchString";
private static AddComponentWindow.Styles s_Styles;
private static AddComponentWindow s_AddComponentWindow;
private static long s_LastClosedTime;
internal static AddComponentWindow.Language s_Lang;
private static bool s_DirtyList;
private string m_ClassName = "";
private GameObject[] m_GameObjects;
private AddComponentWindow.Element[] m_Tree;
private AddComponentWindow.Element[] m_SearchResultTree;
private List<AddComponentWindow.GroupElement> m_Stack = new List<AddComponentWindow.GroupElement>();
private float m_Anim = 1f;
private int m_AnimTarget = 1;
private long m_LastTime = 0L;
private bool m_ScrollToSelected = false;
private string m_DelayedSearch = null;
private string m_Search = "";
private const string kSearchHeader = "Search";
internal static string className
{
get
{
return AddComponentWindow.s_AddComponentWindow.m_ClassName;
}
set
{
AddComponentWindow.s_AddComponentWindow.m_ClassName = value;
}
}
internal static GameObject[] gameObjects
{
get
{
return AddComponentWindow.s_AddComponentWindow.m_GameObjects;
}
}
private bool hasSearch
{
get
{
return !string.IsNullOrEmpty(this.m_Search);
}
}
private AddComponentWindow.GroupElement activeParent
{
get
{
return this.m_Stack[this.m_Stack.Count - 2 + this.m_AnimTarget];
}
}
private AddComponentWindow.Element[] activeTree
{
get
{
return (!this.hasSearch) ? this.m_Tree : this.m_SearchResultTree;
}
}
private AddComponentWindow.Element activeElement
{
get
{
AddComponentWindow.Element result;
if (this.activeTree == null)
{
result = null;
}
else
{
List<AddComponentWindow.Element> children = this.GetChildren(this.activeTree, this.activeParent);
if (children.Count == 0)
{
result = null;
}
else
{
result = children[this.activeParent.selectedIndex];
}
}
return result;
}
}
private bool isAnimating
{
get
{
return this.m_Anim != (float)this.m_AnimTarget;
}
}
static AddComponentWindow()
{
AddComponentWindow.s_AddComponentWindow = null;
AddComponentWindow.s_DirtyList = false;
AddComponentWindow.s_DirtyList = true;
}
private void OnEnable()
{
AddComponentWindow.s_AddComponentWindow = this;
AddComponentWindow.s_Lang = (AddComponentWindow.Language)EditorPrefs.GetInt("NewScriptLanguage", 0);
if (!Enum.IsDefined(typeof(AddComponentWindow.Language), AddComponentWindow.s_Lang))
{
EditorPrefs.SetInt("NewScriptLanguage", 0);
AddComponentWindow.s_Lang = AddComponentWindow.Language.CSharp;
}
this.m_Search = EditorPrefs.GetString("ComponentSearchString", "");
}
private void OnDisable()
{
AddComponentWindow.s_LastClosedTime = DateTime.Now.Ticks / 10000L;
AddComponentWindow.s_AddComponentWindow = null;
}
private static InspectorWindow FirstInspectorWithGameObject()
{
InspectorWindow result;
foreach (InspectorWindow current in InspectorWindow.GetInspectors())
{
if (current.GetInspectedObject() is GameObject)
{
result = current;
return result;
}
}
result = null;
return result;
}
internal static bool ValidateAddComponentMenuItem()
{
return AddComponentWindow.FirstInspectorWithGameObject() != null;
}
internal static void ExecuteAddComponentMenuItem()
{
InspectorWindow inspectorWindow = AddComponentWindow.FirstInspectorWithGameObject();
if (inspectorWindow != null)
{
inspectorWindow.SendEvent(EditorGUIUtility.CommandEvent("OpenAddComponentDropdown"));
}
}
internal static bool Show(Rect rect, GameObject[] gos)
{
UnityEngine.Object[] array = Resources.FindObjectsOfTypeAll(typeof(AddComponentWindow));
bool result;
if (array.Length > 0)
{
((EditorWindow)array[0]).Close();
result = false;
}
else
{
long num = DateTime.Now.Ticks / 10000L;
if (num >= AddComponentWindow.s_LastClosedTime + 50L)
{
Event.current.Use();
if (AddComponentWindow.s_AddComponentWindow == null)
{
AddComponentWindow.s_AddComponentWindow = ScriptableObject.CreateInstance<AddComponentWindow>();
}
AddComponentWindow.s_AddComponentWindow.Init(rect);
AddComponentWindow.s_AddComponentWindow.m_GameObjects = gos;
result = true;
}
else
{
result = false;
}
}
return result;
}
private void Init(Rect buttonRect)
{
buttonRect = GUIUtility.GUIToScreenRect(buttonRect);
this.CreateComponentTree();
base.ShowAsDropDown(buttonRect, new Vector2(buttonRect.width, 320f), null, ShowMode.PopupMenuWithKeyboardFocus);
base.Focus();
this.m_Parent.AddToAuxWindowList();
base.wantsMouseMove = true;
}
private void CreateComponentTree()
{
string[] submenus = Unsupported.GetSubmenus("Component");
string[] submenusCommands = Unsupported.GetSubmenusCommands("Component");
List<string> list = new List<string>();
List<AddComponentWindow.Element> list2 = new List<AddComponentWindow.Element>();
for (int i = 0; i < submenus.Length; i++)
{
if (!(submenusCommands[i] == "ADD"))
{
string text = submenus[i];
string[] array = text.Split(new char[]
{
'/'
});
while (array.Length - 1 < list.Count)
{
list.RemoveAt(list.Count - 1);
}
while (list.Count > 0 && array[list.Count - 1] != list[list.Count - 1])
{
list.RemoveAt(list.Count - 1);
}
while (array.Length - 1 > list.Count)
{
list2.Add(new AddComponentWindow.GroupElement(list.Count, LocalizationDatabase.GetLocalizedString(array[list.Count])));
list.Add(array[list.Count]);
}
list2.Add(new AddComponentWindow.ComponentElement(list.Count, LocalizationDatabase.GetLocalizedString(array[array.Length - 1]), text, submenusCommands[i]));
}
}
list2.Add(new AddComponentWindow.NewScriptElement());
this.m_Tree = list2.ToArray();
if (this.m_Stack.Count == 0)
{
this.m_Stack.Add(this.m_Tree[0] as AddComponentWindow.GroupElement);
}
else
{
AddComponentWindow.GroupElement groupElement = this.m_Tree[0] as AddComponentWindow.GroupElement;
int level = 0;
while (true)
{
AddComponentWindow.GroupElement groupElement2 = this.m_Stack[level];
this.m_Stack[level] = groupElement;
this.m_Stack[level].selectedIndex = groupElement2.selectedIndex;
this.m_Stack[level].scroll = groupElement2.scroll;
level++;
if (level == this.m_Stack.Count)
{
break;
}
List<AddComponentWindow.Element> children = this.GetChildren(this.activeTree, groupElement);
AddComponentWindow.Element element = children.FirstOrDefault((AddComponentWindow.Element c) => c.name == this.m_Stack[level].name);
if (element != null && element is AddComponentWindow.GroupElement)
{
groupElement = (element as AddComponentWindow.GroupElement);
}
else
{
while (this.m_Stack.Count > level)
{
this.m_Stack.RemoveAt(level);
}
}
}
}
AddComponentWindow.s_DirtyList = false;
this.RebuildSearch();
}
internal void OnGUI()
{
if (AddComponentWindow.s_Styles == null)
{
AddComponentWindow.s_Styles = new AddComponentWindow.Styles();
}
GUI.Label(new Rect(0f, 0f, base.position.width, base.position.height), GUIContent.none, AddComponentWindow.s_Styles.background);
if (AddComponentWindow.s_DirtyList)
{
this.CreateComponentTree();
}
this.HandleKeyboard();
GUILayout.Space(7f);
if (!(this.activeParent is AddComponentWindow.NewScriptElement))
{
EditorGUI.FocusTextInControl("ComponentSearch");
}
Rect rect = GUILayoutUtility.GetRect(10f, 20f);
rect.x += 8f;
rect.width -= 16f;
GUI.SetNextControlName("ComponentSearch");
using (new EditorGUI.DisabledScope(this.activeParent is AddComponentWindow.NewScriptElement))
{
string text = EditorGUI.SearchField(rect, this.m_DelayedSearch ?? this.m_Search);
if (text != this.m_Search || this.m_DelayedSearch != null)
{
if (!this.isAnimating)
{
this.m_Search = (this.m_DelayedSearch ?? text);
EditorPrefs.SetString("ComponentSearchString", this.m_Search);
this.RebuildSearch();
this.m_DelayedSearch = null;
}
else
{
this.m_DelayedSearch = text;
}
}
}
this.ListGUI(this.activeTree, this.m_Anim, this.GetElementRelative(0), this.GetElementRelative(-1));
if (this.m_Anim < 1f)
{
this.ListGUI(this.activeTree, this.m_Anim + 1f, this.GetElementRelative(-1), this.GetElementRelative(-2));
}
if (this.isAnimating && Event.current.type == EventType.Repaint)
{
long ticks = DateTime.Now.Ticks;
float num = (float)(ticks - this.m_LastTime) / 1E+07f;
this.m_LastTime = ticks;
this.m_Anim = Mathf.MoveTowards(this.m_Anim, (float)this.m_AnimTarget, num * 4f);
if (this.m_AnimTarget == 0 && this.m_Anim == 0f)
{
this.m_Anim = 1f;
this.m_AnimTarget = 1;
this.m_Stack.RemoveAt(this.m_Stack.Count - 1);
}
base.Repaint();
}
}
private void HandleKeyboard()
{
Event current = Event.current;
if (current.type == EventType.KeyDown)
{
if (this.activeParent is AddComponentWindow.NewScriptElement)
{
if (current.keyCode == KeyCode.Return || current.keyCode == KeyCode.KeypadEnter)
{
(this.activeParent as AddComponentWindow.NewScriptElement).Create();
current.Use();
GUIUtility.ExitGUI();
}
if (current.keyCode == KeyCode.Escape)
{
this.GoToParent();
current.Use();
}
}
else
{
if (current.keyCode == KeyCode.DownArrow)
{
this.activeParent.selectedIndex++;
this.activeParent.selectedIndex = Mathf.Min(this.activeParent.selectedIndex, this.GetChildren(this.activeTree, this.activeParent).Count - 1);
this.m_ScrollToSelected = true;
current.Use();
}
if (current.keyCode == KeyCode.UpArrow)
{
this.activeParent.selectedIndex--;
this.activeParent.selectedIndex = Mathf.Max(this.activeParent.selectedIndex, 0);
this.m_ScrollToSelected = true;
current.Use();
}
if (current.keyCode == KeyCode.Return || current.keyCode == KeyCode.KeypadEnter)
{
this.GoToChild(this.activeElement, true);
current.Use();
}
if (!this.hasSearch)
{
if (current.keyCode == KeyCode.LeftArrow || current.keyCode == KeyCode.Backspace)
{
this.GoToParent();
current.Use();
}
if (current.keyCode == KeyCode.RightArrow)
{
this.GoToChild(this.activeElement, false);
current.Use();
}
if (current.keyCode == KeyCode.Escape)
{
base.Close();
current.Use();
}
}
}
}
}
private void RebuildSearch()
{
if (!this.hasSearch)
{
this.m_SearchResultTree = null;
if (this.m_Stack[this.m_Stack.Count - 1].name == "Search")
{
this.m_Stack.Clear();
this.m_Stack.Add(this.m_Tree[0] as AddComponentWindow.GroupElement);
}
this.m_AnimTarget = 1;
this.m_LastTime = DateTime.Now.Ticks;
this.m_ClassName = "NewBehaviourScript";
}
else
{
this.m_ClassName = this.m_Search;
string[] array = this.m_Search.ToLower().Split(new char[]
{
' '
});
List<AddComponentWindow.Element> list = new List<AddComponentWindow.Element>();
List<AddComponentWindow.Element> list2 = new List<AddComponentWindow.Element>();
AddComponentWindow.Element[] tree = this.m_Tree;
for (int i = 0; i < tree.Length; i++)
{
AddComponentWindow.Element element = tree[i];
if (element is AddComponentWindow.ComponentElement)
{
string text = element.name.ToLower().Replace(" ", "");
bool flag = true;
bool flag2 = false;
for (int j = 0; j < array.Length; j++)
{
string value = array[j];
if (!text.Contains(value))
{
flag = false;
break;
}
if (j == 0 && text.StartsWith(value))
{
flag2 = true;
}
}
if (flag)
{
if (flag2)
{
list.Add(element);
}
else
{
list2.Add(element);
}
}
}
}
list.Sort();
list2.Sort();
List<AddComponentWindow.Element> list3 = new List<AddComponentWindow.Element>();
list3.Add(new AddComponentWindow.GroupElement(0, "Search"));
list3.AddRange(list);
list3.AddRange(list2);
list3.Add(this.m_Tree[this.m_Tree.Length - 1]);
this.m_SearchResultTree = list3.ToArray();
this.m_Stack.Clear();
this.m_Stack.Add(this.m_SearchResultTree[0] as AddComponentWindow.GroupElement);
if (this.GetChildren(this.activeTree, this.activeParent).Count >= 1)
{
this.activeParent.selectedIndex = 0;
}
else
{
this.activeParent.selectedIndex = -1;
}
}
}
private AddComponentWindow.GroupElement GetElementRelative(int rel)
{
int num = this.m_Stack.Count + rel - 1;
AddComponentWindow.GroupElement result;
if (num < 0)
{
result = null;
}
else
{
result = this.m_Stack[num];
}
return result;
}
private void GoToParent()
{
if (this.m_Stack.Count > 1)
{
this.m_AnimTarget = 0;
this.m_LastTime = DateTime.Now.Ticks;
}
}
private void GoToChild(AddComponentWindow.Element e, bool addIfComponent)
{
if (e is AddComponentWindow.NewScriptElement)
{
if (!this.hasSearch)
{
this.m_ClassName = AssetDatabase.GenerateUniqueAssetPath((e as AddComponentWindow.NewScriptElement).TargetPath());
this.m_ClassName = Path.GetFileNameWithoutExtension(this.m_ClassName);
}
}
if (e is AddComponentWindow.ComponentElement)
{
if (addIfComponent)
{
EditorApplication.ExecuteMenuItemOnGameObjects(((AddComponentWindow.ComponentElement)e).menuPath, this.m_GameObjects);
base.Close();
}
}
else if (!this.hasSearch || e is AddComponentWindow.NewScriptElement)
{
this.m_LastTime = DateTime.Now.Ticks;
if (this.m_AnimTarget == 0)
{
this.m_AnimTarget = 1;
}
else if (this.m_Anim == 1f)
{
this.m_Anim = 0f;
this.m_Stack.Add(e as AddComponentWindow.GroupElement);
}
}
}
private void ListGUI(AddComponentWindow.Element[] tree, float anim, AddComponentWindow.GroupElement parent, AddComponentWindow.GroupElement grandParent)
{
anim = Mathf.Floor(anim) + Mathf.SmoothStep(0f, 1f, Mathf.Repeat(anim, 1f));
Rect position = base.position;
position.x = base.position.width * (1f - anim) + 1f;
position.y = 30f;
position.height -= 30f;
position.width -= 2f;
GUILayout.BeginArea(position);
Rect rect = GUILayoutUtility.GetRect(10f, 25f);
string name = parent.name;
GUI.Label(rect, name, AddComponentWindow.s_Styles.header);
if (grandParent != null)
{
Rect position2 = new Rect(rect.x + 4f, rect.y + 7f, 13f, 13f);
if (Event.current.type == EventType.Repaint)
{
AddComponentWindow.s_Styles.leftArrow.Draw(position2, false, false, false, false);
}
if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition))
{
this.GoToParent();
Event.current.Use();
}
}
if (parent is AddComponentWindow.NewScriptElement)
{
(parent as AddComponentWindow.NewScriptElement).OnGUI();
}
else
{
this.ListGUI(tree, parent);
}
GUILayout.EndArea();
}
private void ListGUI(AddComponentWindow.Element[] tree, AddComponentWindow.GroupElement parent)
{
parent.scroll = GUILayout.BeginScrollView(parent.scroll, new GUILayoutOption[0]);
EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));
List<AddComponentWindow.Element> children = this.GetChildren(tree, parent);
Rect rect = default(Rect);
for (int i = 0; i < children.Count; i++)
{
AddComponentWindow.Element element = children[i];
Rect rect2 = GUILayoutUtility.GetRect(16f, 20f, new GUILayoutOption[]
{
GUILayout.ExpandWidth(true)
});
if (Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDown)
{
if (parent.selectedIndex != i && rect2.Contains(Event.current.mousePosition))
{
parent.selectedIndex = i;
base.Repaint();
}
}
bool flag = false;
if (i == parent.selectedIndex)
{
flag = true;
rect = rect2;
}
if (Event.current.type == EventType.Repaint)
{
GUIStyle gUIStyle = AddComponentWindow.s_Styles.groupButton;
GUIContent content = element.content;
bool flag2 = element is AddComponentWindow.ComponentElement;
if (flag2)
{
AddComponentWindow.ComponentElement componentElement = (AddComponentWindow.ComponentElement)element;
gUIStyle = AddComponentWindow.s_Styles.componentButton;
if (componentElement.isLegacy && this.hasSearch)
{
content = componentElement.legacyContent;
}
}
gUIStyle.Draw(rect2, content, false, false, flag, flag);
if (!flag2)
{
Rect position = new Rect(rect2.x + rect2.width - 13f, rect2.y + 4f, 13f, 13f);
AddComponentWindow.s_Styles.rightArrow.Draw(position, false, false, false, false);
}
}
if (Event.current.type == EventType.MouseDown && rect2.Contains(Event.current.mousePosition))
{
Event.current.Use();
parent.selectedIndex = i;
this.GoToChild(element, true);
}
}
EditorGUIUtility.SetIconSize(Vector2.zero);
GUILayout.EndScrollView();
if (this.m_ScrollToSelected && Event.current.type == EventType.Repaint)
{
this.m_ScrollToSelected = false;
Rect lastRect = GUILayoutUtility.GetLastRect();
if (rect.yMax - lastRect.height > parent.scroll.y)
{
parent.scroll.y = rect.yMax - lastRect.height;
base.Repaint();
}
if (rect.y < parent.scroll.y)
{
parent.scroll.y = rect.y;
base.Repaint();
}
}
}
private List<AddComponentWindow.Element> GetChildren(AddComponentWindow.Element[] tree, AddComponentWindow.Element parent)
{
List<AddComponentWindow.Element> list = new List<AddComponentWindow.Element>();
int num = -1;