-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectToolsWindow.cs
More file actions
807 lines (624 loc) · 26.2 KB
/
ProjectToolsWindow.cs
File metadata and controls
807 lines (624 loc) · 26.2 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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using JetBrains.Annotations;
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace CourseMod.Editor {
public class ProjectToolsWindow : EditorWindow {
private enum Tab {
Build,
Shortcut,
Test
}
private const string RepositoryLink = "https://github.com/ADOFAI-gg/CourseMod"; // disabled if null
private const string I18NLink = null; // disabled if null
public static string BuildDirectory => Path.Combine(Directory.GetCurrentDirectory(), "Builds");
private static readonly Color BrandColor;
private static readonly Color OpenLinkColor;
private static readonly Color OpenLinkSubColor;
private static readonly Color OrangeColor;
private static readonly Color PinkColor;
private static readonly Color SkyBlueColor;
private static readonly Color OpenAssetColor;
private Tab _currentTab = Tab.Build;
private static readonly IEnumerable<Tab> AllTabs = Enum.GetValues(typeof(Tab)).Cast<Tab>();
private bool _firstRender;
private SerializedObject _modInfo;
private readonly Dictionary<FieldInfo, SerializedProperty> _modInfoSps = new();
private static readonly FieldInfo[] ModInfoFields = typeof(ModInfo).GetFields();
private static FileSystemWatcher _scenesDirectoryWatcher;
private static FileSystemWatcher _assemblyDefinitionsDirectoryWatcher;
private static FileSystemWatcher _fluentDirectoryWatcher;
private static FileSystemWatcher _buildDirectoryWatcher;
private static readonly HashSet<string> Scenes = new();
private static readonly HashSet<string> AssemblyDefinitions = new();
private static readonly Dictionary<string, string> AssemblyDefinitionRelativePaths = new();
private static readonly HashSet<string> FluentFiles = new();
private static readonly HashSet<string> BuildFiles = new();
private static long _buildSize;
private static string _buildSizeString;
private static int _buildCount;
static ProjectToolsWindow() {
ColorUtility.TryParseHtmlString("#0b192b", out BrandColor);
OpenLinkColor = BrandColor * 14;
OpenLinkSubColor = BrandColor * 10;
ColorUtility.TryParseHtmlString("#ff8000", out OrangeColor);
ColorUtility.TryParseHtmlString("#ff00bb", out PinkColor);
ColorUtility.TryParseHtmlString("#00aaff", out SkyBlueColor);
ColorUtility.TryParseHtmlString("#a7a7ff", out OpenAssetColor);
}
[MenuItem("Modding/Project Tools")]
private static void ShowWindow() {
var window = GetWindow<ProjectToolsWindow>();
window.titleContent.text = "Project Tools";
window.titleContent.tooltip = "The tool that builds your mod.";
window._firstRender = true;
window.SetupDirectoryWatchers();
}
private void OnEnable() {
if (_firstRender) return;
SetupDirectoryWatchers();
ReleaseResources();
_modInfo = new SerializedObject(ModInfo.Info);
foreach (var field in ModInfoFields)
_modInfoSps[field] = _modInfo.FindProperty(field.Name);
}
private void SetupDirectoryWatchers() {
ReleaseStaticResources();
ReloadFileCache();
var scenesDirectory = Path.Combine(Application.dataPath, "Scenes");
var resourcesDirectory = Path.Combine(Application.dataPath, "Resources");
var buildDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Builds");
if (!Directory.Exists(scenesDirectory))
Directory.CreateDirectory(scenesDirectory);
if (!Directory.Exists(resourcesDirectory))
Directory.CreateDirectory(resourcesDirectory);
if (!Directory.Exists(buildDirectory))
Directory.CreateDirectory(buildDirectory);
_scenesDirectoryWatcher =
CreateWatcherForFile(scenesDirectory, "*.unity", false);
_assemblyDefinitionsDirectoryWatcher =
CreateWatcherForFile(Application.dataPath, "*.asmdef", true);
_fluentDirectoryWatcher =
CreateWatcherForFile(resourcesDirectory, "*.ftl", false);
_buildDirectoryWatcher =
CreateWatcherForDirectory(buildDirectory, "*", false);
return;
FileSystemWatcher CreateWatcherForFile(string path, string filter, bool includeSubdirectories)
=> CreateWatcherInternal(path, filter, includeSubdirectories,
NotifyFilters.FileName | NotifyFilters.LastWrite | NotifyFilters.CreationTime);
FileSystemWatcher CreateWatcherForDirectory(string path, string filter, bool includeSubdirectories)
=> CreateWatcherInternal(path, filter, includeSubdirectories,
NotifyFilters.DirectoryName | NotifyFilters.LastWrite | NotifyFilters.CreationTime);
FileSystemWatcher CreateWatcherInternal(string path, string filter, bool includeSubdirectories,
NotifyFilters notifyFilter) {
var watcher = new FileSystemWatcher(path, filter) {
EnableRaisingEvents = true,
IncludeSubdirectories = includeSubdirectories,
NotifyFilter = notifyFilter
};
watcher.Created += OnWatcherUpdate;
watcher.Deleted += OnWatcherUpdate;
watcher.Renamed += OnWatcherUpdate;
return watcher;
}
}
private void OnWatcherUpdate(object sender, FileSystemEventArgs e) {
try {
if (sender is not FileSystemWatcher watcher) return;
var set = 0 switch {
_ when watcher == _scenesDirectoryWatcher => Scenes,
_ when watcher == _assemblyDefinitionsDirectoryWatcher => AssemblyDefinitions,
_ when watcher == _fluentDirectoryWatcher => FluentFiles,
_ when watcher == _buildDirectoryWatcher => BuildFiles,
_ => throw new InvalidOperationException("Unregistered watcher triggered the event."),
};
var relativePathRecord = 0 switch {
_ when watcher == _assemblyDefinitionsDirectoryWatcher => AssemblyDefinitionRelativePaths,
_ => null,
};
switch (e.ChangeType) {
case WatcherChangeTypes.Created:
UpdateCache(set, add: e.FullPath, relativePathRecordToUpdate: relativePathRecord);
break;
case WatcherChangeTypes.Renamed when e is RenamedEventArgs re:
UpdateCache(set, add: re.FullPath, remove: re.OldFullPath,
relativePathRecordToUpdate: relativePathRecord);
break;
case WatcherChangeTypes.Deleted:
UpdateCache(set, remove: e.FullPath, relativePathRecordToUpdate: relativePathRecord);
break;
}
if (watcher == _buildDirectoryWatcher) {
ReloadBuildCache();
}
} catch (Exception exception) {
Debug.Log(exception);
}
}
private static void UpdateCache(
HashSet<string> setToUpdate,
[CanBeNull] string add = null,
[CanBeNull] string remove = null,
[CanBeNull] Dictionary<string, string> relativePathRecordToUpdate = null) {
if (add != null) {
var processedPath = ProcessPath.Invoke(add);
setToUpdate.Add(processedPath);
if (relativePathRecordToUpdate != null)
relativePathRecordToUpdate[processedPath] = ProcessRelativePath.Invoke(add);
}
if (remove != null) {
setToUpdate.Remove(ProcessPath.Invoke(remove));
relativePathRecordToUpdate?.Remove(ProcessRelativePath.Invoke(remove));
}
}
private static void ReloadFileCache() {
Scenes.UnionWith(Directory.GetFiles(Path.Combine(Application.dataPath, "Scenes"),
"*.unity", SearchOption.TopDirectoryOnly)
.Select(ProcessPath));
var assemblyDefinitionPaths = Directory.GetFiles(Application.dataPath,
"*.asmdef", SearchOption.AllDirectories);
var assemblyDefinitionRelativePaths = assemblyDefinitionPaths
.ToDictionary(ProcessPath, ProcessRelativePath);
AssemblyDefinitions.UnionWith(assemblyDefinitionRelativePaths.Keys.ToArray());
foreach (var v in assemblyDefinitionRelativePaths)
AssemblyDefinitionRelativePaths.Add(v.Key, v.Value);
FluentFiles.UnionWith(Directory.GetFiles(Path.Combine(Application.dataPath, "Resources"),
"*.ftl", SearchOption.TopDirectoryOnly)
.Select(ProcessPath));
ReloadBuildCache();
}
private static void ReloadBuildCache() {
var buildDir = BuildDirectory;
var buildDirExists = Directory.Exists(buildDir);
_buildCount = buildDirExists ? Directory.GetDirectories(buildDir).Length : 0;
_buildSize = 0;
if (buildDirExists) {
var dirInfo = new DirectoryInfo(buildDir);
_buildSize += dirInfo.GetDirectories()
.Sum(dir => dir.EnumerateFiles("*", SearchOption.AllDirectories)
.Sum(file => file.Length));
}
_buildSizeString = _buildSize switch {
< 1024 => _buildSize + " B",
< 1024 * 1024 => (_buildSize / 1024.0).ToString("F2") + " KiB",
< 1024 * 1024 * 1024 => (_buildSize / (1024.0 * 1024.0)).ToString("F2") + " MiB",
_ => (_buildSize / (1024.0 * 1024.0 * 1024.0)).ToString("F2") + " GiB"
};
}
private static readonly Func<string, string> ProcessPath = Path.GetFileNameWithoutExtension;
private static readonly Func<string, string> ProcessRelativePath =
path => Path.GetRelativePath(Application.dataPath, path);
private void OnDestroy() {
ReleaseStaticResources();
ReleaseResources();
}
private static void ReleaseStaticResources() {
_scenesDirectoryWatcher?.Dispose();
_assemblyDefinitionsDirectoryWatcher?.Dispose();
_fluentDirectoryWatcher?.Dispose();
_buildDirectoryWatcher?.Dispose();
Scenes.Clear();
AssemblyDefinitions.Clear();
AssemblyDefinitionRelativePaths.Clear();
FluentFiles.Clear();
BuildFiles.Clear();
_buildCount = 0;
_buildSize = 0;
_buildSizeString = "0 B";
}
private void ReleaseResources() {
_modInfo?.Dispose();
_modInfo = null;
_modInfoSps?.Clear();
}
// NOTE: **NEVER** use return unless it is for assertion
private void OnGUI() {
ExtendedGUILayout.SetupGUIStyles();
ExtendedGUILayout.SetGUIBackgroundColor(Color.gray);
using (new GUILayout.HorizontalScope()) {
foreach (var tab in AllTabs) {
var thisTab = tab == _currentTab;
if (thisTab) ExtendedGUILayout.SetGUIBackgroundColor(BrandColor);
if (GUILayout.Button(tab.ToString()))
_currentTab = tab;
if (thisTab) ExtendedGUILayout.SetGUIBackgroundColor(Color.gray);
}
}
ExtendedGUILayout.SetGUIBackgroundColor(Color.white);
switch (_currentTab) {
case Tab.Build:
var config = ProjectToolsConfig.Config;
if (!config) {
GUILayout.Label(
"<color=#ffff00><b>⚠️ Configuration isn't loaded yet, it should only take a few seconds...</b></color>");
return;
}
var isBuilding = config.ModBuilder.IsBuilding;
if (isBuilding) GUI.enabled = false;
ExtendedGUILayout.SectionTitle("Game Importer");
GUILayout.BeginHorizontal();
var adofaiPath = EditorGUILayout.TextField("ADOFAI Executable Path", config.adofaiPath);
if (GUILayout.Button("Find...", GUILayout.Width(60))) {
// ReSharper disable JoinDeclarationAndInitializer
string initialDirectory;
string extension;
// ReSharper restore JoinDeclarationAndInitializer
#if UNITY_EDITOR_WIN
initialDirectory = "C:\\Program Files (x86)\\Steam\\steamapps\\common\\A Dance of Fire and Ice";
extension = "exe";
#elif UNITY_EDITOR_OSX
initialDirectory = "~/Library/Application Support/Steam/steamapps/common/ADanceOfFireAndIce";
extension = "app";
#elif UNITY_EDITOR_LINUX
initialDirectory = "~/.local/share/Steam/steamapps/common/A Dance of Fire and Ice";
extension = string.Empty;
#else
initialDirectory = Application.dataPath;
extension = string.Empty;
#endif
var executablePath = EditorUtility.OpenFilePanel("Find Game Executable", initialDirectory, extension);
if (!string.IsNullOrEmpty(executablePath))
adofaiPath = executablePath;
}
GUILayout.EndHorizontal();
var modifiedPath = config.adofaiPath != adofaiPath;
var modified = modifiedPath;
if (string.IsNullOrEmpty(adofaiPath)) {
GUILayout.Label(
"<color=red><b>⚠️ This field is required for importing or copying the mod files.</b></color>");
} else if (modifiedPath || _firstRender) {
if (!File.Exists(config.adofaiPath = adofaiPath)) {
GUILayout.Label("<color=red><b>⚠️ File not found.</b></color>");
}
}
ExtendedGUILayout.SetGUIBackgroundColor(Color.green);
if (GUILayout.Button("<b>Import ADOFAI</b>", GUILayout.Height(32))) {
var continueImporting = EditorUtility.DisplayDialog(
"Are you sure?",
"Importing the game assembly may take a while, and you will likely be asked to restart the Unity Editor.",
"Yes, continue",
"No");
if (!continueImporting)
return;
if (string.IsNullOrEmpty(config.adofaiPath)) {
EditorUtility.DisplayDialog("Error", "Please set the ADOFAI Executable Path first.", "OK");
return;
}
config.Importer.SetGamePath(config.adofaiPath);
config.Importer.Import();
}
ExtendedGUILayout.SetGUIBackgroundColor(Color.white);
ExtendedGUILayout.SectionTitle("Mod Information");
if (_modInfo == null) {
GUILayout.Label(
"<color=#ffff00><b>⚠️ Info.json SerializedObject isn't loaded yet, it should only take a few seconds...</b></color>");
} else {
using (new ExtendedGUILayout.IndentScope()) {
var openModInfoFoldout = EditorGUILayout.Foldout(config.openModInfoFoldout,
" <b>Display Info.json</b>");
if (openModInfoFoldout != config.openModInfoFoldout) {
config.openModInfoFoldout = openModInfoFoldout;
modified = true;
}
if (openModInfoFoldout) {
using (new ExtendedGUILayout.IndentScope(24)) {
foreach (var fieldInfo in ModInfoFields) {
if (_modInfoSps.TryGetValue(fieldInfo, out var modInfoProperty))
EditorGUILayout.PropertyField(modInfoProperty);
}
// immediately save changes
if (_modInfo.ApplyModifiedProperties()) {
EditorUtility.SetDirty(_modInfo.targetObject);
AssetDatabase.SaveAssetIfDirty(_modInfo.targetObject);
}
}
}
}
}
ExtendedGUILayout.SectionTitle("Builder");
ExtendedGUILayout.SetGUIBackgroundColor(OrangeColor);
GUILayout.Label("<color=#999999><b>Asset Bundles</b></color>");
using (new ExtendedGUILayout.IndentScope()) {
var skipAssetBundleBuild =
GUILayout.Toggle(config.skipAssetBundleBuild, "don't build asset bundles");
if (skipAssetBundleBuild != config.skipAssetBundleBuild) {
config.skipAssetBundleBuild = skipAssetBundleBuild;
modified = true;
}
GUILayout.Space(4);
var buildEveryPlatform = GUILayout.Toggle(config.buildEveryPlatform,
"build asset bundles for all platforms");
if (buildEveryPlatform != config.buildEveryPlatform) {
config.buildEveryPlatform = buildEveryPlatform;
modified = true;
}
GUILayout.Space(8);
if (!buildEveryPlatform) {
using (new ExtendedGUILayout.IndentScope(20)) {
var buildTargets = config.BuildPlatforms;
using (new GUILayout.HorizontalScope()) {
var buildTargetModified = false;
BuildTargetUI(BuildTarget.StandaloneWindows64);
BuildTargetUI(BuildTarget.StandaloneOSX);
BuildTargetUI(BuildTarget.StandaloneLinux64);
if (buildTargetModified) {
config.BuildPlatforms = buildTargets;
modified = true;
}
void BuildTargetUI(BuildTarget b) {
var isAssigned = buildTargets.Contains(b);
var buildTargetColor = isAssigned
? Color.green
: Color.gray;
var buildTargetString = GetBuildTargetString(b);
if (isAssigned)
buildTargetString = $"<b>{buildTargetString}</b>";
ExtendedGUILayout.SetGUIBackgroundColor(buildTargetColor);
if (GUILayout.Button(buildTargetString)) {
if (isAssigned)
buildTargets.Remove(b);
else
buildTargets.Add(b);
buildTargetModified = true;
}
}
}
var buildTargetMessage = buildTargets.Count == 0
? $"Only building <b>{GetBuildTargetString(ModBuilder.PlatformToBuildTarget(Application.platform))}</b> because no build targets are selected"
: $"Building <b>{string.Join(", ", buildTargets.Select(GetBuildTargetString))}</b>";
GUILayout.Label($"<color=#999999>{buildTargetMessage}</color>");
}
string GetBuildTargetString(BuildTarget b) => b switch {
BuildTarget.StandaloneWindows64 => "Windows",
BuildTarget.StandaloneOSX => "MacOS",
BuildTarget.StandaloneLinux64 => "Linux",
_ => $"<Undefined> {b}"
};
}
}
GUILayout.Space(8);
ExtendedGUILayout.SetGUIBackgroundColor(PinkColor);
GUILayout.Label("<color=#999999><b>Build Options</b></color>");
using (new ExtendedGUILayout.IndentScope()) {
var developmentBuild = GUILayout.Toggle(config.developmentBuild, "debug build");
if (developmentBuild != config.developmentBuild) {
config.developmentBuild = developmentBuild;
modified = true;
}
GUILayout.Space(4);
var generateDebugSymbols =
GUILayout.Toggle(config.generateDebugSymbols, "generate debug symbols (.pdb)");
if (generateDebugSymbols != config.generateDebugSymbols) {
config.generateDebugSymbols = generateDebugSymbols;
modified = true;
}
}
GUILayout.Space(8);
ExtendedGUILayout.SetGUIBackgroundColor(SkyBlueColor);
GUILayout.Label("<color=#999999><b>Post Build Event</b></color>");
using (new ExtendedGUILayout.IndentScope()) {
var copyToDirectory =
GUILayout.Toggle(config.copyToDirectory, "copy to mod path");
if (copyToDirectory != config.copyToDirectory) {
config.copyToDirectory = copyToDirectory;
modified = true;
}
GUILayout.Space(4);
var zip = GUILayout.Toggle(config.createZip, "create a .zip file in build directory");
if (zip != config.createZip) {
config.createZip = zip;
modified = true;
}
GUILayout.Space(4);
var runApplication =
GUILayout.Toggle(config.runApplication, "run application after building mod");
if (runApplication != config.runApplication) {
config.runApplication = runApplication;
modified = true;
}
GUILayout.Space(4);
using (new GUILayout.HorizontalScope()) {
GUILayout.Label("<color=#00aaff>└</color>", GUILayout.Width(16));
var runAppThruSteam =
GUILayout.Toggle(config.runApplicationThroughSteam,
"run with steam instead of directly executing binary");
if (runAppThruSteam != config.runApplicationThroughSteam) {
config.runApplicationThroughSteam = runAppThruSteam;
modified = true;
}
}
}
GUILayout.Space(12);
ExtendedGUILayout.SetGUIBackgroundColor(Color.white);
GUILayout.Label("<color=#999999><b>Build Option Presets</b></color>");
using (new GUILayout.HorizontalScope()) {
if (GUILayout.Button("Debug")) {
config.buildEveryPlatform = false;
config.copyToDirectory = true;
config.createZip = false;
config.runApplication = true;
config.developmentBuild = true;
config.generateDebugSymbols = true;
modified = true;
}
if (GUILayout.Button("Release")) {
config.buildEveryPlatform = true;
config.createZip = true;
config.developmentBuild = false;
config.generateDebugSymbols = false;
modified = true;
}
ExtendedGUILayout.SetGUIBackgroundColor(Color.red + Color.white * .6f);
if (GUILayout.Button("Clear All", GUILayout.Width(72))) {
config.skipAssetBundleBuild = false;
config.buildEveryPlatform = false;
config.copyToDirectory = false;
config.createZip = false;
config.runApplication = false;
config.runApplicationThroughSteam = false;
config.developmentBuild = false;
config.generateDebugSymbols = false;
modified = true;
}
}
ExtendedGUILayout.SetGUIBackgroundColor(Color.green);
if (GUILayout.Button("<b>Build Mod</b>", GUILayout.Height(32))) {
config.BuildMod(config.copyToDirectory
? Path.Combine(Path.GetDirectoryName(config.adofaiPath)!, "Mods", "CourseMod")
: null);
}
ExtendedGUILayout.SetGUIBackgroundColor(Color.white);
if (isBuilding) GUI.enabled = true;
ExtendedGUILayout.SectionTitle("Build Management");
var buildDir = BuildDirectory;
ExtendedGUILayout.SetGUIBackgroundColor(OpenLinkColor);
if (GUILayout.Button("Open Build Directory")) {
Application.OpenURL(buildDir);
}
GUILayout.Space(12);
GUILayout.Label($"Cached Builds: {_buildCount} (Using <b>{_buildSizeString}</b> of Storage)");
ExtendedGUILayout.SetGUIBackgroundColor(Color.red);
using (new GUILayout.HorizontalScope()) {
// checkbox position misaligns for some reason?? so we have to manually add the space
GUILayout.Space(4);
var autoDeleteBuilds =
GUILayout.Toggle(config.automaticallyDeleteBuilds, "Automatically Delete Builds");
if (autoDeleteBuilds != config.automaticallyDeleteBuilds) {
config.automaticallyDeleteBuilds = autoDeleteBuilds;
modified = true;
}
}
if (isBuilding) GUI.enabled = false;
using (new GUILayout.HorizontalScope()) {
if (GUILayout.Button("Delete All Builds")) {
config.DeleteBuilds();
}
ExtendedGUILayout.SetGUIBackgroundColor(Color.white);
GUILayout.Label("Except for ", GUILayout.MaxWidth(60));
var exceptString = config.deleteBuildsExceptLastN.ToString();
var exceptStringNew = GUILayout.TextField(exceptString);
if (exceptString != exceptStringNew) {
if (int.TryParse(exceptStringNew, out var exceptNew)) {
config.deleteBuildsExceptLastN = Math.Abs(exceptNew);
modified = true;
}
}
GUILayout.Label(" Build(s)");
}
if (isBuilding) GUI.enabled = true;
GUILayout.Space(12);
ExtendedGUILayout.SetGUIBackgroundColor(Color.white);
if (modified) {
EditorUtility.SetDirty(config);
}
ExtendedGUILayout.SectionTitle("Notes");
GUILayout.Label(
"· Put the scenes in <b>course_scenes.bundle</b>, and other assets in <b>course_assets.bundle</b>");
GUILayout.Label("· DO NOT add the test scenes in the bundle.");
GUILayout.Label("· When fixing patches for future updates, use the frontline beta");
break;
case Tab.Shortcut:
ExtendedGUILayout.SectionTitle("Project", bottomMargin: 0, bottomLineMargin: 4);
ExtendedGUILayout.SetGUIBackgroundColor(OpenLinkColor);
using (new GUILayout.HorizontalScope()) {
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (string.IsNullOrEmpty(RepositoryLink)) {
GUILayout.Label(
"<color=#ffff00><b>⚠️ Repository Shortcut is disabled.\n Edit ProjectToolsWindow.cs#L20 to enable it.</b></color>");
ExtendedGUILayout.SetGUIBackgroundColor(Color.yellow);
if (GUILayout.Button("Go to line")) {
OpenScriptInEditor("Assets/Editor/ProjectToolsWindow.cs", 20);
}
} else {
if (GUILayout.Button("Open Repository")) {
Application.OpenURL(RepositoryLink);
}
ExtendedGUILayout.SetGUIBackgroundColor(OpenLinkSubColor);
if (GUILayout.Button("Issues", GUILayout.MaxWidth(88))) {
Application.OpenURL($"{RepositoryLink}/issues");
}
if (GUILayout.Button("Pull Requests", GUILayout.MaxWidth(88))) {
Application.OpenURL($"{RepositoryLink}/pulls");
}
}
}
GUILayout.Space(12);
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (string.IsNullOrEmpty(I18NLink)) {
GUILayout.Label(
"<color=#ffff00><b>⚠️ I18N Shortcut is disabled.\n Edit ProjectToolsWindow.cs#L21 to enable it.</b></color>");
ExtendedGUILayout.SetGUIBackgroundColor(Color.yellow);
if (GUILayout.Button("Go to line")) {
OpenScriptInEditor("Assets/Editor/ProjectToolsWindow.cs", 21);
}
} else {
ExtendedGUILayout.SetGUIBackgroundColor(OpenLinkColor);
if (GUILayout.Button("Open I18N URL")) {
Application.OpenURL(I18NLink);
}
}
GUILayout.Space(8);
ExtendedGUILayout.SetGUIBackgroundColor(Color.white);
using (new GUILayout.HorizontalScope()) {
GUILayout.Label("<color=#999999><b>I18N Assets: </b></color>");
foreach (var fluentFile in FluentFiles)
if (GUILayout.Button(fluentFile, GUILayout.Width(72)))
OpenScriptInEditor(Path.Combine("Assets/Resources", fluentFile + ".ftl"));
}
ExtendedGUILayout.SectionTitle("Scenes", bottomMargin: 0, bottomLineMargin: 4);
ExtendedGUILayout.SetGUIBackgroundColor(OpenAssetColor);
foreach (var scene in Scenes)
if (GUILayout.Button(scene))
SwitchToScene(scene);
ExtendedGUILayout.SectionTitle("Assembly Definitions", bottomMargin: 0, bottomLineMargin: 4);
foreach (var asmdef in AssemblyDefinitions)
if (GUILayout.Button(asmdef))
SelectAsset(AssemblyDefinitionRelativePaths[asmdef]);
ExtendedGUILayout.SetGUIBackgroundColor(Color.white);
break;
case Tab.Test:
ExtendedGUILayout.SectionTitle("TBD");
GUILayout.Label("· TBD");
break;
default:
_currentTab = Tab.Build;
break;
}
_firstRender = false;
}
private static void SwitchToScene(string sceneName) // copied from adofai code haha
{
if (Application.isPlaying) {
if (sceneName.Contains('/'))
sceneName = sceneName.Split('/').Last();
SceneManager.LoadScene(sceneName);
} else if (!SceneManager.GetActiveScene().name.Contains(sceneName)) {
EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
EditorSceneManager.OpenScene(Path.Combine("Assets/Scenes", sceneName) + ".unity");
}
}
private static void SelectAsset(string path) {
Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(path);
FocusInspectorWindow();
}
private static void OpenAsset(string path) {
// PrefabUtility.LoadPrefabContentsIntoPreviewScene(path, );
AssetDatabase.OpenAsset(AssetDatabase.LoadAssetAtPath<GameObject>(path));
}
private static void FocusInspectorWindow() {
var inspectorWindow =
GetWindow(typeof(UnityEditor.Editor).Assembly.GetType("UnityEditor.InspectorWindow"));
inspectorWindow.Show();
inspectorWindow.Focus();
}
private static void OpenScriptInEditor(string path, int? line = null) {
UnityEditorInternal.InternalEditorUtility.OpenFileAtLineExternal(path, line ?? 1);
}
}
}