com.amanotes.gdk 0.2.97 → 0.2.99

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