com.amanotes.gdk 0.2.48 → 0.2.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/Editor/AmaGDKEditor.cs +149 -63
  3. package/Editor/AmaGDKExtra.cs +31 -0
  4. package/Editor/AmaGDKExtra.cs.meta +11 -0
  5. package/Editor/Extra/GDKAutoBuild.cs +891 -0
  6. package/Editor/Extra/GDKAutoBuild.cs.meta +3 -0
  7. package/Editor/Extra/GDKProjectCP.cs +158 -0
  8. package/Editor/Extra/GDKProjectCP.cs.meta +11 -0
  9. package/Editor/Extra.meta +8 -0
  10. package/Editor/Utils/AmaGDKEditor.ExtractVersion.cs +1 -1
  11. package/Extra/AmaGDKInstaller.unitypackage +0 -0
  12. package/Extra/AndroidPostProcessor.unitypackage +0 -0
  13. package/Extra/{AmaGDKProject.unitypackage.meta → AndroidPostProcessor.unitypackage.meta} +1 -1
  14. package/Extra/CheckDiskSpace.unitypackage +0 -0
  15. package/Extra/CheckDiskSpace.unitypackage.meta +7 -0
  16. package/Extra/SDKVersionTracking.unitypackage +0 -0
  17. package/Extra/SDKVersionTracking.unitypackage.meta +7 -0
  18. package/Packages/AmaGDKConfig.unitypackage +0 -0
  19. package/Packages/AmaGDKExample.unitypackage +0 -0
  20. package/Packages/AmaGDKTest.unitypackage +0 -0
  21. package/Packages/AppsFlyerAdapter.unitypackage +0 -0
  22. package/Packages/FirebaseAnalyticsAdapter.unitypackage +0 -0
  23. package/Packages/FirebaseRemoteConfigAdapter.unitypackage +0 -0
  24. package/Packages/IronSourceAdapter.unitypackage +0 -0
  25. package/Packages/RevenueCatAdapter.unitypackage +0 -0
  26. package/Runtime/AmaGDK.Adapters.cs +0 -4
  27. package/Runtime/AmaGDK.Ads.cs +92 -31
  28. package/Runtime/AmaGDK.Analytics.cs +97 -64
  29. package/Runtime/AmaGDK.IAP.cs +39 -45
  30. package/Runtime/AmaGDK.RemoteConfig.cs +76 -52
  31. package/Runtime/AmaGDK.UserProfile.cs +106 -124
  32. package/Runtime/AmaGDK.cs +46 -35
  33. package/Runtime/Internal/AmaGDK.Event.cs +185 -0
  34. package/Runtime/Internal/AmaGDK.Event.cs.meta +3 -0
  35. package/Runtime/Internal/AmaGDK.Internal.cs +4 -0
  36. package/Runtime/Internal/AmaGDK.Utils.cs +85 -24
  37. package/Runtime/Klavar/Attributes.meta +0 -4
  38. package/Runtime/Klavar.meta +0 -4
  39. package/package.json +1 -1
  40. package/Extra/AmaGDKProject.unitypackage +0 -0
@@ -0,0 +1,891 @@
1
+ using System;
2
+ using System.Collections.Generic;
3
+ using System.Diagnostics;
4
+ using System.IO;
5
+ using System.Linq;
6
+ using UnityEditor;
7
+ using UnityEngine;
8
+ using UnityEngine.Events;
9
+ using Debug = UnityEngine.Debug;
10
+ using UnityObject = UnityEngine.Object;
11
+
12
+ namespace Amanotes.Editor
13
+ {
14
+ [CreateAssetMenu(menuName = "AmaGDK/Build Config")]
15
+ public class GDKAutoBuild : ScriptableObject
16
+ {
17
+ private const string DEFAULT_BUILD_FOLDER = "../../_Build";
18
+
19
+ public KeystoreInfo keystore;
20
+ public string buildFolder = DEFAULT_BUILD_FOLDER;
21
+ public Texture2D icon;
22
+
23
+ public List<BuildInfo> listBuild = new List<BuildInfo>();
24
+
25
+ public List<UnityObject> listUnused;
26
+ public BuildRequestTS buildRQ;
27
+ public UnityEvent beforeBuild;
28
+ public TextAsset shTemplate;
29
+
30
+ [NonSerialized] private BuildInfo _buildInfo;
31
+ [NonSerialized] private int _lockCount;
32
+
33
+ public int nBuildPending
34
+ {
35
+ get
36
+ {
37
+ if ((buildRQ != null) && !buildRQ.isDifferentSession) return listBuild.Count(t => t.enable);
38
+
39
+ StopBuild();
40
+ return 0;
41
+ }
42
+ }
43
+
44
+ internal static int SecondsTS => (int)(DateTime.Now - new DateTime(2010, 1, 1)).TotalSeconds;
45
+ public void Lock()
46
+ {
47
+ _lockCount++;
48
+ }
49
+ public void Unlock()
50
+ {
51
+ _lockCount--;
52
+ if ((_lockCount == 0) && (_buildInfo != null)) ExportBuild(_buildInfo);
53
+ }
54
+
55
+ public void StopBuild()
56
+ {
57
+ for (var i = 0; i < listBuild.Count; i++)
58
+ {
59
+ listBuild[i].enable = false;
60
+ }
61
+ }
62
+
63
+ public void ProcessBuild()
64
+ {
65
+ BuildTarget cTarget = EditorUserBuildSettings.activeBuildTarget;
66
+
67
+ for (var i = 0; i < listBuild.Count; i++)
68
+ {
69
+ BuildInfo item = listBuild[i];
70
+ if (!item.enable) continue;
71
+
72
+ if (item.target != cTarget) continue;
73
+
74
+ item.enable = false; // already build
75
+ Build(item);
76
+ return; // only do one build at a time
77
+ }
78
+
79
+ for (var i = 0; i < listBuild.Count; i++)
80
+ {
81
+ BuildInfo item = listBuild[i];
82
+ if (!item.enable) continue;
83
+
84
+ switch (item.target)
85
+ {
86
+ case BuildTarget.Android:
87
+ EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
88
+ return; // only do one build at a time
89
+
90
+ case BuildTarget.iOS:
91
+ EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.iOS, BuildTarget.iOS);
92
+ return; // only do one build at a time
93
+ }
94
+
95
+ }
96
+ }
97
+
98
+ private void RemoveUnusedAssets()
99
+ {
100
+ AssetDatabase.StartAssetEditing();
101
+ for (var i = 0; i < listUnused.Count; i++)
102
+ {
103
+ if (listUnused[i] == null) continue;
104
+ string path = AssetDatabase.GetAssetPath(listUnused[i]);
105
+ AssetDatabase.DeleteAsset(path);
106
+ }
107
+ AssetDatabase.StopAssetEditing();
108
+ }
109
+
110
+ public void Build(BuildInfo info)
111
+ {
112
+ DryRun(info);
113
+
114
+ if (_lockCount == 0)
115
+ {
116
+ ExportBuild(info);
117
+ return;
118
+ }
119
+
120
+ _buildInfo = info;
121
+ }
122
+
123
+ public void EnableBuildForTarget(BuildTarget target, bool updateBuildNumber = true)
124
+ {
125
+ for (var i = 0; i < listBuild.Count; i++)
126
+ {
127
+ BuildInfo b = listBuild[i];
128
+ b.enable = b.target == target;
129
+
130
+ if (updateBuildNumber && (b.target == target)) b.buildNumber++;
131
+ }
132
+
133
+ EditorUtility.SetDirty(this);
134
+ }
135
+
136
+ public void DryRun(BuildInfo info)
137
+ {
138
+ if (string.IsNullOrEmpty(buildFolder)) buildFolder = DEFAULT_BUILD_FOLDER;
139
+
140
+ var buildDir = new DirectoryInfo(buildFolder);
141
+ if (!buildDir.Exists) Directory.CreateDirectory(buildDir.FullName);
142
+
143
+ // Check for existed build with the same name
144
+ if (info.overwrite == false)
145
+ {
146
+ if (info.target == BuildTarget.Android)
147
+ {
148
+ string[] apkNames = info.GetAPKNames(buildFolder);
149
+ for (var i = 0; i < apkNames.Length; i++)
150
+ {
151
+ string item = apkNames[i];
152
+ if (!File.Exists(item)) continue;
153
+ Debug.LogWarning("Exporting file existed! " + item);
154
+
155
+ // return;
156
+ }
157
+ } else
158
+ {
159
+ string fullBuildPath = info.fullBuildPath(buildFolder);
160
+ if (Directory.Exists(fullBuildPath))
161
+ {
162
+ Debug.LogWarning("Exporting target existed! " + fullBuildPath);
163
+ EditorUtility.RevealInFinder(fullBuildPath);
164
+
165
+ // return;
166
+ }
167
+ }
168
+ }
169
+
170
+ RemoveUnusedAssets();
171
+ if (info.target == BuildTarget.Android) keystore.Write();
172
+
173
+ info.Write();
174
+ info.PreprocessBuild(buildFolder);
175
+
176
+ // write customized icon, if any
177
+ if ((icon != null) && (info.buildIcon != null) && (info.buildIcon != icon))
178
+ {
179
+ string p1 = AssetDatabase.GetAssetPath(info.buildIcon);
180
+ string p2 = AssetDatabase.GetAssetPath(icon);
181
+ byte[] bytes = File.ReadAllBytes(p1);
182
+ File.WriteAllBytes(p2, bytes);
183
+
184
+ // force refresh
185
+ AssetDatabase.ImportAsset(p2, ImportAssetOptions.ForceSynchronousImport);
186
+ RepaintAll();
187
+ }
188
+
189
+ _lockCount = 0;
190
+ if (beforeBuild != null) beforeBuild.Invoke();
191
+ }
192
+
193
+ private static void RepaintAll()
194
+ {
195
+ UnityObject[] windows = Resources.FindObjectsOfTypeAll(typeof(EditorWindow));
196
+ if (windows == null || windows.Length <= 0) return;
197
+
198
+ for (var i = 0; i < windows.Length; i++)
199
+ {
200
+ var w = windows[i] as EditorWindow;
201
+ if (w != null) w.Repaint();
202
+ }
203
+ }
204
+
205
+ private void RunPostBuild()
206
+ {
207
+ listBuild[0].buildNumber++;
208
+ EditorUtility.SetDirty(this);
209
+ AssetDatabase.SaveAssets();
210
+ // RunPostBuildSH(listBuild[0]);
211
+ }
212
+
213
+ // private void RunPostBuildSH(BuildInfo info)
214
+ // {
215
+ // if (shTemplate == null) return;
216
+ //
217
+ // string shPath = ExternalProcessUtils.FileFromTemplate(
218
+ // "git-post-build.sh", shTemplate.text,
219
+ // "{{TEMPLATE_PROJECT_PATH}}", Application.dataPath.Replace("/Assets", string.Empty),
220
+ // "{{TEMPLATE_TAG}}", $"{info.projectId}/v{info.buildVersion}_b{info.buildNumber}",
221
+ // "{{TEMPLATE_BRANCH}}", $"build/v{info.buildVersion}_b{info.buildNumber}",
222
+ // "{{TEMPLATE_BUILD_ASSET}}", $"{AssetDatabase.GetAssetPath(this)}"
223
+ // );
224
+ //
225
+ // // Run & Lock Unity until git finish
226
+ // ExternalProcessUtils.Run(shPath, true);
227
+ // }
228
+
229
+ private void ExportBuild(BuildInfo info)
230
+ {
231
+ string fullBuildPath = info.fullBuildPath(buildFolder);
232
+ BuildPipeline.BuildPlayer(GetScenes(), fullBuildPath, info.target, BuildOptions.None);
233
+ info.PostProcessBuild(buildFolder);
234
+
235
+ // if (buildRQ.willRunSHPostBuild)
236
+ // {
237
+ // // Run once per build request
238
+ // buildRQ.willRunSHPostBuild = false;
239
+ // RunPostBuildSH(info);
240
+ // }
241
+
242
+ if (nBuildPending > 0)
243
+ {
244
+ ProcessBuild();
245
+ return;
246
+ }
247
+
248
+ EditorUtility.RevealInFinder(fullBuildPath);
249
+ }
250
+
251
+ internal static string[] GetScenes()
252
+ {
253
+ return EditorBuildSettings.scenes.Where(s => s.enabled).Select(s => s.path).ToArray();
254
+ }
255
+
256
+ internal static void DrawRect(Rect rect, Color c)
257
+ {
258
+ Color bgColor = GUI.color;
259
+ GUI.color = c;
260
+ GUI.DrawTexture(rect, Texture2D.whiteTexture, ScaleMode.StretchToFill, false);
261
+ GUI.color = bgColor;
262
+ }
263
+ [Serializable] public class BuildRequestTS
264
+ {
265
+ public int processId;
266
+ public string machineId;
267
+ public string projectPath;
268
+ public bool willRunSHPostBuild = true;
269
+
270
+ public bool isDifferentSession
271
+ {
272
+ get
273
+ {
274
+ if (machineId != SystemInfo.deviceUniqueIdentifier)
275
+
276
+ //Debug.LogWarning("Different device");
277
+ return true;
278
+
279
+ var currentProcess = Process.GetCurrentProcess();
280
+ if (processId != currentProcess.Id)
281
+
282
+ //Debug.LogWarning("Different process ID");
283
+ return true; // Changed process id
284
+
285
+ if (projectPath != Application.dataPath)
286
+
287
+ //Debug.LogWarning("Different project path");
288
+ return true; // Changed project
289
+
290
+ return false;
291
+ }
292
+ }
293
+
294
+ public static BuildRequestTS Generate() //bool runGit
295
+ {
296
+ var currentProcess = Process.GetCurrentProcess();
297
+
298
+ return new BuildRequestTS
299
+ {
300
+ machineId = SystemInfo.deviceUniqueIdentifier,
301
+ processId = currentProcess.Id,
302
+ projectPath = Application.dataPath,
303
+ // willRunSHPostBuild = runGit
304
+ };
305
+ }
306
+ }
307
+ [Serializable] public class BuildInfo
308
+ {
309
+ public string projectId;
310
+ public string productName;
311
+ public string packageName;
312
+
313
+ public Texture2D buildIcon;
314
+ public BuildTarget target;
315
+
316
+ public bool isAAB;
317
+ public bool splitAPK = true;
318
+ public bool overwrite = true;
319
+ public string buildVersion;
320
+ public int buildNumber;
321
+
322
+ // Android options
323
+ public bool enable;
324
+
325
+ public bool isAndroid => target == BuildTarget.Android;
326
+ public bool isIOS => target == BuildTarget.iOS;
327
+
328
+ public string buildName => $"{projectId}_v{buildVersion}_b{buildNumber}";
329
+
330
+ public void PreprocessBuild(string buildFolder)
331
+ {
332
+ AssetDatabase.SaveAssets();
333
+ GC.Collect();
334
+ Resources.UnloadUnusedAssets();
335
+ EditorUtility.UnloadUnusedAssetsImmediate();
336
+
337
+ PlayerSettings.bundleVersion = buildVersion;
338
+
339
+ if (isAndroid)
340
+ {
341
+ PlayerSettings.Android.bundleVersionCode = buildNumber;
342
+ PlayerSettings.Android.buildApkPerCpuArchitecture = splitAPK;
343
+ PlayerSettings.Android.targetArchitectures = AndroidArchitecture.All;
344
+
345
+ EditorUserBuildSettings.buildAppBundle = isAAB;
346
+ EditorUserBuildSettings.exportAsGoogleAndroidProject = false;
347
+ EditorUserBuildSettings.androidCreateSymbols = AndroidCreateSymbols.Disabled;
348
+
349
+ string[] listAPKNames = GetAPKNames(buildFolder);
350
+
351
+ for (var i = 0; i < listAPKNames.Length; i++)
352
+ {
353
+ string apkName = listAPKNames[i];
354
+ string tempName = apkName.Replace(buildName, Application.productName);
355
+
356
+ if (File.Exists(tempName)) File.Delete(tempName); // always delete temp file no matter what
357
+ if (overwrite && File.Exists(apkName)) File.Delete(apkName);
358
+ }
359
+
360
+ return;
361
+ }
362
+
363
+ if (isIOS)
364
+ {
365
+ PlayerSettings.iOS.buildNumber = buildNumber.ToString();
366
+ if (!overwrite) return;
367
+
368
+ string path = fullBuildPath(buildFolder);
369
+ if (Directory.Exists(path)) Directory.Delete(path, true);
370
+ return;
371
+ }
372
+
373
+ Debug.LogWarning("Unsupported platform: " + target);
374
+ }
375
+
376
+ public string[] GetAPKNames(string buildFolder)
377
+ {
378
+ var buildDir = new DirectoryInfo(buildFolder);
379
+ string fullName = buildDir.FullName;
380
+
381
+ if (isAAB)
382
+ return new[]
383
+ {
384
+ Path.Combine(fullName, buildName + ".aab")
385
+ };
386
+
387
+ if (splitAPK)
388
+ return new[]
389
+ {
390
+ Path.Combine(fullName, buildName + ".arm64-v8a.apk"), Path.Combine(fullName, buildName + ".armeabi-v7a.apk")
391
+ };
392
+
393
+ return new[]
394
+ {
395
+ Path.Combine(fullName, buildName + ".apk")
396
+ };
397
+ }
398
+
399
+ public void PostProcessBuild(string buildFolder)
400
+ {
401
+ if (target != BuildTarget.Android) return;
402
+ if (isAAB) return;
403
+
404
+ // var productName = Application.productName;
405
+ string[] listAPKNames = GetAPKNames(buildFolder);
406
+
407
+ for (var i = 0; i < listAPKNames.Length; i++)
408
+ {
409
+ string apkName = listAPKNames[i];
410
+ string tempName = apkName.Replace(buildName, productName);
411
+
412
+ if (!File.Exists(tempName)) continue;
413
+ File.Move(tempName, apkName);
414
+ }
415
+ }
416
+
417
+ public string fullBuildPath(string buildFolder)
418
+ {
419
+ if (buildFolder.EndsWith("/"))
420
+
421
+ // remove last slash
422
+ buildFolder = buildFolder.Substring(0, buildFolder.Length - 1);
423
+
424
+ var buildDir = new DirectoryInfo(buildFolder);
425
+
426
+ if (isAndroid)
427
+ {
428
+ if (isAAB) return Path.Combine(buildDir.FullName, buildName + ".aab");
429
+ if (splitAPK) return buildDir.FullName;
430
+ return Path.Combine(buildDir.FullName, buildName + ".apk");
431
+ }
432
+
433
+ return Path.Combine(buildDir.FullName, "XCode_" + buildName);
434
+ }
435
+
436
+ public BuildInfo Read()
437
+ {
438
+ buildVersion = PlayerSettings.bundleVersion;
439
+ productName = PlayerSettings.productName;
440
+
441
+ if (isAndroid)
442
+ {
443
+ buildNumber = PlayerSettings.Android.bundleVersionCode;
444
+ packageName = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.Android);
445
+ }
446
+
447
+ if (isIOS)
448
+ {
449
+ int.TryParse(PlayerSettings.iOS.buildNumber, out buildNumber);
450
+ packageName = PlayerSettings.GetApplicationIdentifier(BuildTargetGroup.iOS);
451
+ }
452
+
453
+ return this;
454
+ }
455
+
456
+ public void Write()
457
+ {
458
+ PlayerSettings.bundleVersion = buildVersion;
459
+ PlayerSettings.productName = productName;
460
+
461
+ if (isAndroid)
462
+ {
463
+ PlayerSettings.Android.bundleVersionCode = buildNumber;
464
+ PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, packageName);
465
+ }
466
+
467
+ if (isIOS)
468
+ {
469
+ PlayerSettings.iOS.buildNumber = buildNumber.ToString();
470
+ PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.iOS, packageName);
471
+ }
472
+
473
+ EditorApplication.RepaintProjectWindow();
474
+ }
475
+
476
+ public void IncreaseVersion()
477
+ {
478
+ buildNumber++;
479
+ if (string.IsNullOrEmpty(buildVersion)) buildVersion = "1.0.0";
480
+
481
+ string[] arr = buildVersion.Split('.');
482
+ int last = int.Parse(arr[2]);
483
+ last++;
484
+
485
+ arr[2] = last.ToString();
486
+ buildVersion = string.Join(".", arr);
487
+ }
488
+ }
489
+
490
+ [Serializable] public class KeystoreInfo
491
+ {
492
+ public string path = "AmaGDK/Store/project.keystore";
493
+ public string alias = "alias";
494
+ public string keystorePassword = "123456789";
495
+ public string aliasPassword = "123456789";
496
+
497
+ public void Write()
498
+ {
499
+ // Must use absolute path or else gradle build fail
500
+ var keystoreFI = new FileInfo(path);
501
+ PlayerSettings.Android.keystoreName = keystoreFI.FullName;
502
+ PlayerSettings.keystorePass = keystorePassword;
503
+ PlayerSettings.Android.keyaliasPass = aliasPassword;
504
+ PlayerSettings.Android.keyaliasName = alias;
505
+ }
506
+ }
507
+ }
508
+
509
+
510
+ [InitializeOnLoad]
511
+ internal class GDKAutoBuildHelper
512
+ {
513
+ private static GDKAutoBuild build;
514
+ static GDKAutoBuildHelper()
515
+ {
516
+ EditorApplication.update -= Update;
517
+ EditorApplication.update += Update;
518
+ }
519
+
520
+ private static void Update()
521
+ {
522
+ if (EditorApplication.isCompiling || EditorApplication.isUpdating) return;
523
+
524
+ if (EditorApplication.isPlaying || EditorApplication.isPlayingOrWillChangePlaymode)
525
+ {
526
+ if (build != null) build.StopBuild();
527
+ EditorApplication.update -= Update;
528
+ return;
529
+ }
530
+
531
+ if (build == null)
532
+ {
533
+ string[] guids = AssetDatabase.FindAssets("t:" + nameof(GDKAutoBuild)); //FindAssets uses tags check documentation for more info
534
+ if (guids.Length == 0)
535
+ {
536
+ EditorApplication.update -= Update;
537
+ return;
538
+ }
539
+
540
+ string path = AssetDatabase.GUIDToAssetPath(guids[0]);
541
+ build = AssetDatabase.LoadAssetAtPath<GDKAutoBuild>(path);
542
+ if (build == null)
543
+ {
544
+ EditorApplication.update -= Update;
545
+ return;
546
+ }
547
+ }
548
+
549
+ EditorApplication.update -= Update;
550
+
551
+ //check if timeStamp is valid
552
+ if (build.nBuildPending == 0) return;
553
+
554
+ build.ProcessBuild();
555
+ }
556
+
557
+
558
+ // [MenuItem("Window/AmaGDK/Build/Select Build Asset &#b", false, 10)]
559
+ public static void SelectBuild()
560
+ {
561
+ string[] arr = AssetDatabase.FindAssets("t:" + nameof(GDKAutoBuild));
562
+
563
+ if (arr.Length == 0)
564
+ {
565
+ Debug.LogWarning("There are no Build asset in the project!");
566
+ return;
567
+ }
568
+
569
+ // if (arr.Length > 1)
570
+ // {
571
+ // Debug.LogWarning("There are [" + arr.Length + "] Build assets in the project!");
572
+ // }
573
+
574
+ string path = AssetDatabase.GUIDToAssetPath(arr[0]);
575
+ var obj = AssetDatabase.LoadAssetAtPath<UnityObject>(path);
576
+ Selection.activeObject = obj;
577
+ EditorGUIUtility.PingObject(obj);
578
+ }
579
+
580
+ private static GDKAutoBuild FindAutoBuildAssets(string name = null, bool allowFallback = false)
581
+ {
582
+ string[] arr = AssetDatabase.FindAssets("t:" + nameof(GDKAutoBuild));
583
+ if (arr.Length == 0)
584
+ {
585
+ Debug.LogWarning("There are no Build asset in the project!");
586
+ return null;
587
+ }
588
+
589
+ for (var i = 0; i < arr.Length; i++)
590
+ {
591
+ string path = AssetDatabase.GUIDToAssetPath(arr[i]).Replace("\\", "/");
592
+ if (string.IsNullOrEmpty(name)) return AssetDatabase.LoadAssetAtPath<GDKAutoBuild>(path);
593
+
594
+ string fileName = Path.GetFileName(path);
595
+ if (fileName.ToLower().Contains(name.ToLower())) return AssetDatabase.LoadAssetAtPath<GDKAutoBuild>(path);
596
+ }
597
+
598
+ if (!allowFallback) return null;
599
+
600
+ // Fall back to the first one
601
+ string path0 = AssetDatabase.GUIDToAssetPath(arr[0]).Replace("\\", "/");
602
+ return AssetDatabase.LoadAssetAtPath<GDKAutoBuild>(path0);
603
+ }
604
+
605
+ // [MenuItem("Window/AmaGDK/Build/Android", false, 50)] public static void BuildAndroid() { BuildAndroid(false); }
606
+ // [MenuItem("Window/AmaGDK/Build/iOS", false, 51)] public static void BuildIOS() { BuildIOS(false); }
607
+ // [MenuItem("Window/AmaGDK/Build/Android - Release", false, 90)] public static void BuildAndroidRelease() { BuildAndroid(true); }
608
+ // [MenuItem("Window/AmaGDK/Build/iOS - Release", false, 91)] public static void BuildIOSRelease() { BuildIOS(true); }
609
+
610
+
611
+ private static void BuildAndroid(bool isRelease)
612
+ {
613
+ GDKAutoBuild buildAsset = FindAutoBuildAssets("android");
614
+ if (buildAsset == null)
615
+ {
616
+ Debug.LogWarning("Build Asset for Android not found!");
617
+ return;
618
+ }
619
+
620
+ buildAsset.EnableBuildForTarget(BuildTarget.Android);
621
+ buildAsset.buildRQ = GDKAutoBuild.BuildRequestTS.Generate();// isRelease
622
+ buildAsset.ProcessBuild();
623
+ }
624
+
625
+ private static void BuildIOS(bool isRelease)
626
+ {
627
+ GDKAutoBuild buildAsset = FindAutoBuildAssets("ios");
628
+ if (buildAsset == null)
629
+ {
630
+ Debug.LogWarning("Build Asset for iOS not found!");
631
+ return;
632
+ }
633
+ buildAsset.EnableBuildForTarget(BuildTarget.iOS);
634
+ buildAsset.buildRQ = GDKAutoBuild.BuildRequestTS.Generate(); //isRelease
635
+ buildAsset.ProcessBuild();
636
+ }
637
+ }
638
+
639
+ [CustomEditor(typeof(GDKAutoBuild))]
640
+ public class GDKAutoBuildEditor : UnityEditor.Editor
641
+ {
642
+ public int bIndex;
643
+ public string path;
644
+ public bool drawDefault;
645
+
646
+ public GUIStyle productNameStyle;
647
+ public GUIStyle projectStyle;
648
+
649
+ private string helpInfo;
650
+
651
+ private void Init()
652
+ {
653
+ productNameStyle = new GUIStyle(EditorStyles.largeLabel)
654
+ {
655
+ alignment = TextAnchor.MiddleCenter,
656
+ fontSize = 32
657
+ };
658
+
659
+ projectStyle = new GUIStyle(EditorStyles.miniLabel)
660
+ {
661
+ alignment = TextAnchor.MiddleCenter
662
+ };
663
+
664
+ path = Application.dataPath;
665
+ List<string> arr = path.Split('/').ToList();
666
+ arr.RemoveAt(arr.Count - 1);
667
+
668
+ if (arr.Count > 3) arr.RemoveRange(0, arr.Count - 3);
669
+
670
+ path = string.Join("/", arr);
671
+ }
672
+ public override void OnInspectorGUI()
673
+ {
674
+ var ab = (GDKAutoBuild)target;
675
+ if (ab == null) return;
676
+
677
+ if (productNameStyle == null) Init();
678
+
679
+ GUILayout.Label(PlayerSettings.productName, productNameStyle);
680
+
681
+ Rect r0 = GUILayoutUtility.GetRect(0, Screen.width, 16f, 16f);
682
+ r0.xMin = 0;
683
+ r0.xMax += 16f;
684
+ GDKAutoBuild.DrawRect(r0, new Color32(20, 20, 20, 255));
685
+
686
+ if ((Event.current.type == EventType.MouseUp) && r0.Contains(Event.current.mousePosition))
687
+ {
688
+ var fullPath = new DirectoryInfo(ab.buildFolder);
689
+ EditorUtility.RevealInFinder(fullPath.FullName);
690
+ Event.current.Use();
691
+ }
692
+
693
+ GUI.Label(r0, path, projectStyle);
694
+ EditorGUILayout.Space();
695
+
696
+ if (string.IsNullOrEmpty(helpInfo)) helpInfo = $"\nPackageName:\t{PlayerSettings.applicationIdentifier}\nTargetPlatform:\t{EditorUserBuildSettings.activeBuildTarget}\n";
697
+ EditorGUILayout.HelpBox(helpInfo, MessageType.Info);
698
+ Rect rect = GUILayoutUtility.GetLastRect();
699
+ if ((Event.current.type == EventType.MouseUp) && rect.Contains(Event.current.mousePosition))
700
+ {
701
+ Event.current.Use();
702
+ helpInfo = null;
703
+ Repaint();
704
+ }
705
+
706
+ drawDefault = GUILayout.Toggle(drawDefault, "Draw default");
707
+ if (drawDefault) DrawDefaultInspector();
708
+
709
+ EditorGUILayout.Space();
710
+
711
+ int max = ab.listBuild.Count;
712
+ if (max == 0)
713
+ {
714
+ EditorGUILayout.HelpBox("No BuildInfo!", MessageType.Warning);
715
+
716
+ if (GUILayout.Button("Create Default"))
717
+ {
718
+ new GDKAutoBuild.BuildInfo().Read();
719
+
720
+ ab.listBuild = new List<GDKAutoBuild.BuildInfo>
721
+ {
722
+ new GDKAutoBuild.BuildInfo
723
+ {
724
+ target = BuildTarget.Android, isAAB = false, splitAPK = true
725
+ }.Read(),
726
+ new GDKAutoBuild.BuildInfo
727
+ {
728
+ target = BuildTarget.Android, isAAB = true, splitAPK = true
729
+ }.Read(),
730
+ new GDKAutoBuild.BuildInfo
731
+ {
732
+ target = BuildTarget.iOS, isAAB = true, splitAPK = true
733
+ }.Read()
734
+ };
735
+ }
736
+ return;
737
+ }
738
+
739
+ serializedObject.Update();
740
+ SerializedProperty prop = serializedObject.FindProperty($"listBuild.Array.data[{bIndex}]");
741
+ prop.isExpanded = true;
742
+
743
+ GDKAutoBuild.BuildInfo info = ab.listBuild[bIndex];
744
+
745
+ EditorGUI.BeginChangeCheck();
746
+ {
747
+ EditorGUILayout.PropertyField(prop, true);
748
+ }
749
+ if (EditorGUI.EndChangeCheck()) serializedObject.ApplyModifiedProperties();
750
+
751
+ Rect r = GUILayoutUtility.GetLastRect();
752
+ r.x = 0;
753
+ r.width = Screen.width;
754
+ r.height = 16f;
755
+
756
+ GDKAutoBuild.DrawRect(r, new Color32(20, 20, 20, 255));
757
+
758
+ r.xMin += 12f;
759
+ GUI.Label(r, info.buildName);
760
+
761
+ if ((ab.icon != null) && (ab.icon == info.buildIcon)) EditorGUILayout.HelpBox("Build Icon must be different with the template icon (which will be overwritten)", MessageType.Error);
762
+
763
+ GUILayout.BeginHorizontal();
764
+ {
765
+ if (GUILayout.Button("Read")) info.Read();
766
+
767
+ if (GUILayout.Button("Write")) info.Write();
768
+
769
+ if (GUILayout.Button("+")) info.IncreaseVersion();
770
+ }
771
+ GUILayout.EndHorizontal();
772
+
773
+ if (GUILayout.Button("Dry Run"))
774
+ {
775
+ ab.DryRun(info);
776
+ helpInfo = null;
777
+ Repaint();
778
+ }
779
+
780
+ bIndex = EditorGUILayout.IntSlider(bIndex, 0, max - 1);
781
+
782
+ var nBuilds = 0;
783
+ for (var i = 0; i < ab.listBuild.Count; i++)
784
+ {
785
+ GDKAutoBuild.BuildInfo item = ab.listBuild[i];
786
+
787
+ if (!item.enable) continue;
788
+ nBuilds++;
789
+
790
+ string hint = item.target == BuildTarget.Android
791
+ ? $"{string.Join("\n", item.GetAPKNames(ab.buildFolder))}"
792
+ : item.fullBuildPath(ab.buildFolder);
793
+
794
+ EditorGUILayout.HelpBox(hint, MessageType.Info);
795
+ }
796
+
797
+ if (nBuilds == 0) return;
798
+
799
+ GUILayout.BeginHorizontal();
800
+ {
801
+ if (GUILayout.Button("Build"))
802
+ {
803
+ ab.buildRQ = GDKAutoBuild.BuildRequestTS.Generate(); //ab.runGitPostBuild
804
+ ab.ProcessBuild();
805
+ }
806
+
807
+ if (GUILayout.Button("Stop")) ab.StopBuild();
808
+ }
809
+ GUILayout.EndHorizontal();
810
+ }
811
+ }
812
+
813
+
814
+ public class ExternalProcessUtils
815
+ {
816
+ public static string FileFromTemplate(string fileName, string source, params string[] tokens)
817
+ {
818
+ for (var i = 0; i < tokens.Length; i += 2)
819
+ {
820
+ source = source.Replace(tokens[i], tokens[i + 1]);
821
+ }
822
+
823
+ string filePath = Application.dataPath.Replace("/Assets", "/" + fileName);
824
+
825
+ // Debug.LogWarning("FilePath: " + filePath);
826
+ File.WriteAllText(filePath, source);
827
+ return filePath;
828
+ }
829
+
830
+ // public static void GitResetRepo()
831
+ // {
832
+ // RunCMD("git reset --hard | git clean -df");
833
+ // }
834
+
835
+ public static void RunCMD(string cmd)
836
+ {
837
+ try
838
+ {
839
+ var startInfo = new ProcessStartInfo
840
+ {
841
+ FileName = "/bin/bash",
842
+ Arguments = $"-c \" {cmd} \" ",
843
+ CreateNoWindow = true
844
+ };
845
+
846
+ var proc = new Process
847
+ {
848
+ StartInfo = startInfo
849
+ };
850
+
851
+ proc.Start();
852
+ proc.WaitForExit();
853
+ } catch (Exception e)
854
+ {
855
+ Debug.LogWarning(e);
856
+ }
857
+ }
858
+
859
+ public static void ChmodX(string filePath)
860
+ {
861
+ RunCMD($"chmod +x {filePath}");
862
+ }
863
+
864
+ public static void Run(string filePath, bool waitExit = false)
865
+ {
866
+ ChmodX(filePath);
867
+
868
+ try
869
+ {
870
+ var process = new Process
871
+ {
872
+ EnableRaisingEvents = false,
873
+ StartInfo =
874
+ {
875
+ FileName = filePath,
876
+ UseShellExecute = false,
877
+ RedirectStandardOutput = true,
878
+ RedirectStandardInput = true,
879
+ RedirectStandardError = true
880
+ }
881
+ };
882
+
883
+ process.Start();
884
+ if (waitExit) process.WaitForExit();
885
+ } catch (Exception e)
886
+ {
887
+ Debug.LogWarning(e);
888
+ }
889
+ }
890
+ }
891
+ }