com.amanotes.gdk 0.2.45 → 0.2.47

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 (48) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/Editor/AmaGDKEditor.cs +325 -120
  3. package/Editor/MatchSDKVersion.cs +3 -6
  4. package/Editor/Utils/AmaGDKEditor.ExtractVersion.cs +6 -4
  5. package/Extra/AmaGDKInstaller.unitypackage +0 -0
  6. package/Extra/AmaGDKProject.unitypackage +0 -0
  7. package/Packages/AmaGDKConfig.unitypackage +0 -0
  8. package/Packages/AmaGDKExample.unitypackage +0 -0
  9. package/Packages/AmaGDKTest.unitypackage +0 -0
  10. package/Packages/AppsFlyerAdapter.unitypackage +0 -0
  11. package/Packages/{FirebaseAnalyticsAdapter_v9.1.0.unitypackage.meta → AppsFlyerAdapter.unitypackage.meta} +1 -1
  12. package/Packages/FirebaseAnalyticsAdapter.unitypackage +0 -0
  13. package/Packages/{IronSourceAdapter_v7.5.2.unitypackage.meta → FirebaseAnalyticsAdapter.unitypackage.meta} +1 -1
  14. package/Packages/FirebaseRemoteConfigAdapter.unitypackage +0 -0
  15. package/Packages/{FirebaseRemoteConfigAdapter_v9.1.0.unitypackage.meta → FirebaseRemoteConfigAdapter.unitypackage.meta} +1 -1
  16. package/Packages/IronSourceAdapter.unitypackage +0 -0
  17. package/Packages/{AppsFlyerAdapter_v6.5.4.unitypackage.meta → IronSourceAdapter.unitypackage.meta} +1 -1
  18. package/Packages/RevenueCatAdapter.unitypackage +0 -0
  19. package/Packages/RevenueCatAdapter.unitypackage.meta +7 -0
  20. package/Runtime/AmaGDK.Adapters.cs +55 -77
  21. package/Runtime/AmaGDK.Ads.cs +155 -163
  22. package/Runtime/AmaGDK.Analytics.cs +245 -125
  23. package/Runtime/AmaGDK.Config.cs +2 -1
  24. package/Runtime/AmaGDK.IAP.cs +47 -48
  25. package/Runtime/AmaGDK.RemoteConfig.cs +38 -35
  26. package/Runtime/AmaGDK.UserProfile.cs +27 -19
  27. package/Runtime/AmaGDK.cs +158 -111
  28. package/Runtime/Core.meta +8 -0
  29. package/{Editor/Utils/AmaGDKEditor.GUI.cs → Runtime/Internal/AmaGDK.Internal.AmaGUI.cs} +110 -85
  30. package/{Editor/Utils/AmaGDKEditor.GUI.cs.meta → Runtime/Internal/AmaGDK.Internal.AmaGUI.cs.meta} +1 -1
  31. package/Runtime/{AmaGDK.Internal.SemVer.cs → Internal/AmaGDK.Internal.SemVer.cs} +21 -17
  32. package/Runtime/{AmaGDK.Internal.cs → Internal/AmaGDK.Internal.cs} +17 -6
  33. package/Runtime/{AmaGDK.Utils.cs → Internal/AmaGDK.Utils.cs} +91 -17
  34. package/Runtime/Internal.meta +8 -0
  35. package/package.json +1 -1
  36. package/Packages/AppsFlyerAdapter_v6.5.4.unitypackage +0 -0
  37. package/Packages/FirebaseAnalyticsAdapter_v9.1.0.unitypackage +0 -0
  38. package/Packages/FirebaseRemoteConfigAdapter_v9.1.0.unitypackage +0 -0
  39. package/Packages/IronSourceAdapter_v7.5.2.unitypackage +0 -0
  40. package/Packages/IronsourceAdapter_v7.2.6.unitypackage +0 -0
  41. package/Packages/IronsourceAdapter_v7.2.6.unitypackage.meta +0 -7
  42. package/Packages/RevenueCatAdapter_v6.0.0.unitypackage +0 -0
  43. package/Packages/RevenueCatAdapter_v6.0.0.unitypackage.meta +0 -7
  44. /package/Runtime/{AmaGDK.Internal.SemVer.cs.meta → Internal/AmaGDK.Internal.SemVer.cs.meta} +0 -0
  45. /package/Runtime/{AmaGDK.Internal.cs.meta → Internal/AmaGDK.Internal.cs.meta} +0 -0
  46. /package/Runtime/{AmaGDK.Utils.cs.meta → Internal/AmaGDK.Utils.cs.meta} +0 -0
  47. /package/Runtime/{AmaGDK.WebUtils.cs → Internal/AmaGDK.WebUtils.cs} +0 -0
  48. /package/Runtime/{AmaGDK.WebUtils.cs.meta → Internal/AmaGDK.WebUtils.cs.meta} +0 -0
package/Runtime/AmaGDK.cs CHANGED
@@ -6,7 +6,9 @@ using System.IO;
6
6
  using System.Text;
7
7
  using System.Text.RegularExpressions;
8
8
  using Amanotes.Core.Internal;
9
+ using System.Linq;
9
10
  using UnityEngine;
11
+ using UnityEngine.Profiling;
10
12
  using static Amanotes.Core.Internal.Logging;
11
13
  using static Amanotes.Core.Internal.Messsage;
12
14
  using Debug = UnityEngine.Debug;
@@ -15,18 +17,17 @@ namespace Amanotes.Core
15
17
  {
16
18
  public partial class AmaGDK : MonoBehaviour
17
19
  {
18
- public const string VERSION = "0.2.45";
20
+ public const string VERSION = "0.2.47";
19
21
 
20
22
  internal static AmaGDK _instance;
21
23
  internal static Status _status = Status.None;
22
24
  internal static Action _onReadyCallback;
23
- internal static Action<AdapterInfo> _onAdapterReadyCallback;
25
+ internal static Action<string> _onAdapterReadyCallback;
24
26
  internal static bool _allowInit = false;
25
27
  public bool autoInit = true;
26
28
 
27
29
  private static ConfigAsset _config = null;
28
- private static readonly Dictionary<string, AdapterInfo> _adapters = new Dictionary<string, AdapterInfo>();
29
- private static readonly List<string> _firebaseServices = new List<string>() { AdapterID.FIREBASE_REMOTE_CONFIG, AdapterID.FIREBASE_ANALYTICS };
30
+ // private static readonly Dictionary<string, AdapterInfo> _adapters = new Dictionary<string, AdapterInfo>();
30
31
 
31
32
  public static ConfigAsset Config
32
33
  {
@@ -34,7 +35,6 @@ namespace Amanotes.Core
34
35
  {
35
36
  if (_config != null) return _config;
36
37
  _config = Resources.Load<ConfigAsset>("AmaGDKConfig");
37
-
38
38
  // if (_config == null) LogWarningOnce(CONFIG_NOT_FOUND);
39
39
  return _config;
40
40
  }
@@ -53,24 +53,36 @@ namespace Amanotes.Core
53
53
 
54
54
  _instance = this;
55
55
  DontDestroyOnLoad(this);
56
-
57
-
56
+
58
57
  _allowInit = _allowInit || autoInit;
59
58
  StartCoroutine(InitRoutine());
60
59
  }
61
60
 
62
- IEnumerator InitRoutine()
61
+ IEnumerator InitHook()
63
62
  {
64
- if (Config == null)
63
+ int nHooks = Hook.hooks.Count;
64
+ if (nHooks == 0)
65
65
  {
66
- throw new Exception("[AmaGDK] " + CONFIG_NOT_FOUND);
66
+ Log($"[Hook] No hook registered!");
67
+ yield break;
67
68
  }
68
-
69
- yield return StartCoroutine(User.Init());
70
-
71
- float time = 0;
72
- float timeout = 1;
73
-
69
+
70
+ //TODO: Sort Hook by orderId
71
+ var hookCompleted = false;
72
+
73
+ float stTime = Time.realtimeSinceStartup;
74
+
75
+ Hook.TriggerHooks(() =>
76
+ {
77
+ hookCompleted = true;
78
+ });
79
+ yield return new WaitUntil(() => hookCompleted);
80
+ float elapsed = Time.realtimeSinceStartup - stTime;
81
+ Log($"[Hook] {nHooks} hooks complete after " + elapsed);
82
+ }
83
+
84
+ IEnumerator WaitForManualInit()
85
+ {
74
86
  var counter = 0;
75
87
  const int INIT_TOLERANCE = 10 * 60;
76
88
  const int INIT_WARN_CYCLE = 5 * 60;
@@ -85,96 +97,97 @@ namespace Amanotes.Core
85
97
  LogWarning($"Waiting for manual Init() call (~ {Mathf.RoundToInt(counter / 60f)}s passed!)");
86
98
  }
87
99
  }
100
+ }
88
101
 
89
- _status = Status.Initialize;
90
- float startTime = Time.realtimeSinceStartup;
91
- StringBuilder adapterAnnounce = new StringBuilder();
102
+ void InitModules()
103
+ {
104
+ Profiler.BeginSample("AmaGDK.InitModules()");
105
+ {
106
+ User.InitModule();
107
+ Analytics.InitModule();
108
+ Ads.InitModule();
109
+ IAP.InitModule();
110
+ }
111
+ Profiler.EndSample();
112
+ }
92
113
 
93
- // sort on priority
94
- Adapter.listAdapters.Sort((a1, a2) => a1.initOrder.CompareTo(a2.initOrder));
95
- foreach (AdapterContext adapter in Adapter.listAdapters)
114
+ void StartModules()
115
+ {
116
+ Profiler.BeginSample("AmaGDK.StartModules()");
96
117
  {
97
- Log($"Initiating {adapter.adapterId} --> initOrder: {adapter.initOrder}");
98
- adapter.Init();
99
- RegisterUnityCallback(adapter);
100
-
101
- time = 0;
118
+ User.StartModule();
119
+ Analytics.StartModule();
120
+ Ads.StartModule();
121
+ IAP.StartModule();
122
+ }
123
+ Profiler.EndSample();
124
+ }
102
125
 
103
- while (adapter.status == Status.None || adapter.status == Status.Initialize)
126
+ IEnumerator InitAdapters(StringBuilder sb)
127
+ {
128
+ _status = Status.Initialize;
129
+ float TIMEOUT = 1;
130
+
131
+ // sort on priority
132
+ List<Adapter2> listAdapters = Adapter2.adapterMap
133
+ .Values.ToList();
134
+ listAdapters.Sort((a1, a2) => a1.initOrder.CompareTo(a2.initOrder));
135
+
136
+ foreach (Adapter2 adapter in listAdapters)
137
+ {
138
+ // Log($"Initiating {adapter.adapterId} --> initOrder: {adapter.initOrder} | {adapter.status}");
139
+ float startTime = Time.realtimeSinceStartup;
140
+ Profiler.BeginSample("AmaGDK.adapter.InitSDK()");
104
141
  {
105
- time += Time.deltaTime;
106
- yield return null;
107
- if (time <= timeout) continue;
108
- LogWarning($"{adapter.adapterId} init time out: {timeout}");
109
- break;
142
+ adapter.InitSDK();
110
143
  }
144
+ Profiler.EndSample();
111
145
 
112
- if (adapter.IsReady && _firebaseServices.Contains(adapter.adapterId))
146
+ yield return GDKUtils.Timeout(TIMEOUT,() => adapter.status != Status.Initialize);
147
+
148
+ if (adapter.status == Status.Initialize)
113
149
  {
114
- firebaseResolved = true;
150
+ LogWarning($"{adapter.adapterId} init time out: {TIMEOUT}");
115
151
  }
116
152
 
117
- var adapterInfo = new AdapterInfo(adapter.adapterId, adapter.adapterVersion, adapter.IsReady, adapter.refObj);
118
- _adapters[adapter.adapterId] = adapterInfo;
119
- _onAdapterReadyCallback?.Invoke(adapterInfo);
120
- adapterAnnounce.AppendLine(string.Format("[{0}] {1} (adapter v{2})", adapter.IsReady ? "OK" : "FAIL",
121
- adapter.adapterId, adapter.adapterVersion));
122
-
153
+ _onAdapterReadyCallback?.Invoke(adapter.adapterId);
154
+ sb.AppendLine($"[{(adapter.IsReady ? " OK " : "FAIL")}] {adapter.adapterId} (~ {Time.realtimeSinceStartup - startTime:#0.00}s)");
155
+
123
156
  // Wait for postprocessing of each adapter
124
157
  yield return null;
125
158
  }
126
159
  _onAdapterReadyCallback = null;
127
- User.UpdateUserId();
128
-
129
- // Init modules (Adapter managers)
130
- Analytics.Init();
131
- Ads.Init();
132
- IAP.Init();
133
-
134
- _status = Status.Ready;
135
- _onReadyCallback?.Invoke();
136
- _onReadyCallback = null;
137
- Log($"AmaGDK v{VERSION} | {READY} in {Time.realtimeSinceStartup - startTime}s\n\n{adapterAnnounce.ToString()}");
138
160
  }
139
-
140
- void RegisterUnityCallback(AdapterContext adapter)
161
+
162
+
163
+ IEnumerator InitRoutine()
141
164
  {
142
- switch (adapter)
165
+ if (Config == null)
143
166
  {
144
- case IOnFrameUpdate a: {
145
- onFrameUpdate -= a.OnFrameUpdate;
146
- onFrameUpdate += a.OnFrameUpdate;
147
- break;
148
- }
149
-
150
- case IOnApplicationPause a: {
151
- onApplicationPause -= a.OnApplicationPause;
152
- onApplicationPause += a.OnApplicationPause;
153
- break;
154
- }
155
-
156
- case IOnApplicationFocus a:
157
- {
158
- applicationFocus -= a.OnApplicationFocus;
159
- applicationFocus += a.OnApplicationFocus;
160
- break;
161
- }
162
-
163
- case IOnApplicationQuit a:
164
- {
165
- applicationQuit -= a.OnApplicationQuit;
166
- applicationQuit += a.OnApplicationQuit;
167
- break;
168
- }
167
+ throw new Exception("[AmaGDK] " + CONFIG_NOT_FOUND);
169
168
  }
169
+
170
+ float startTime = Time.realtimeSinceStartup;
171
+ yield return InitHook();
172
+
173
+ var sb = new StringBuilder();
174
+ InitModules();
175
+
176
+ yield return WaitForManualInit();
177
+ yield return InitAdapters(sb);
178
+
179
+ StartModules();
180
+
181
+ _status = Status.Ready;
182
+ _onReadyCallback?.Invoke();
183
+ _onReadyCallback = null;
184
+ Debug.Log($"AmaGDK v{VERSION} | {READY} in {Time.realtimeSinceStartup - startTime:#0.00}s\n\n{sb}");
170
185
  }
171
-
172
186
  }
173
187
 
174
188
  public partial class AmaGDK // PUBLIC APIS
175
189
  {
176
190
  public static bool isReady => _status == Status.Ready;
177
- public static bool firebaseResolved { get; private set; }
178
191
 
179
192
  public static void Init(Action onReady = null)
180
193
  {
@@ -222,33 +235,18 @@ namespace Amanotes.Core
222
235
  _onReadyCallback += onReady;
223
236
  }
224
237
 
225
- public static void SetAdapterReadyCallback(Action<AdapterInfo> onAdapterReady)
238
+ public static void SetAdapterReadyCallback(Action<string> onAdapterReady)
226
239
  {
227
240
  if (onAdapterReady == null)
228
241
  {
229
242
  LogWarning("Cannot add a null callback!");
230
243
  return;
231
244
  }
245
+
232
246
  _onAdapterReadyCallback -= onAdapterReady;
233
247
  _onAdapterReadyCallback += onAdapterReady;
234
248
  }
235
249
 
236
- public static AdapterInfo GetAdapterInfo(string id)
237
- {
238
- if (string.IsNullOrWhiteSpace(id))
239
- {
240
- LogWarning("Please provide Adapter ID to get the info.");
241
- return default;
242
- }
243
-
244
- if (!_adapters.ContainsKey(id))
245
- {
246
- LogWarning($"Adapter {id} is not found.");
247
- return default;
248
- }
249
-
250
- return _adapters[id];
251
- }
252
250
  }
253
251
 
254
252
  public partial class AmaGDK
@@ -294,6 +292,7 @@ namespace Amanotes.Core
294
292
 
295
293
  public partial class AmaGDK // Switch dev mode
296
294
  {
295
+ #if UNITY_EDITOR
297
296
  [ContextMenu("Change Dev Mode")]
298
297
  public void ChangeDevMode()
299
298
  {
@@ -337,6 +336,7 @@ namespace Amanotes.Core
337
336
  output = output.Trim();
338
337
  UpdateManifest(output);
339
338
  Debug.Log("AmaGDK changes to dev mode successfully");
339
+ UnityEditor.AssetDatabase.Refresh();
340
340
  }
341
341
 
342
342
  private string RunShellCommand(string command)
@@ -363,21 +363,68 @@ namespace Amanotes.Core
363
363
  manifestJson = Regex.Replace(manifestJson, "\"com\\.amanotes\\.gdk\"\\s*:\\s*\"\\d+\\.\\d+\\.\\d+\"", $"\"com.amanotes.gdk\": \"{strDesired}\"");
364
364
  File.WriteAllText(manifestPath, manifestJson);
365
365
  }
366
+ #endif
366
367
  }
367
-
368
- public class AdapterInfo
369
- {
370
- public readonly string id;
371
- public readonly string version;
372
- public readonly bool isReady;
373
- public readonly GameObject refObj;
374
368
 
375
- public AdapterInfo(string id, string version, bool isReady, GameObject refObj)
369
+ public partial class AmaGDK // Switch dev mode
370
+ {
371
+ public static class Hook
376
372
  {
377
- this.id = id;
378
- this.version = version;
379
- this.isReady = isReady;
380
- this.refObj = refObj;
373
+ internal static bool started;
374
+ internal static bool completed;
375
+ internal static Action onHookComplete;
376
+ internal static readonly Queue<Action<Action>> hooks = new Queue<Action<Action>>();
377
+
378
+ public static void Register(Action<Action> hook)
379
+ {
380
+ if (completed)
381
+ {
382
+ LogWarning("Register happen too late: Hook completed!");
383
+ return;
384
+ }
385
+
386
+ hooks.Enqueue(hook);
387
+ }
388
+
389
+ internal static void TriggerHooks(Action onComplete)
390
+ {
391
+ if (started || completed)
392
+ {
393
+ LogWarning("Multiple calls TriggerHooks - should call once!");
394
+ return;
395
+ }
396
+
397
+ started = true;
398
+ onHookComplete = onComplete;
399
+ Next();
400
+ }
401
+
402
+ internal static void Next()
403
+ {
404
+ if (hooks.Count == 0)
405
+ {
406
+ completed = true;
407
+ onHookComplete?.Invoke();
408
+ return;
409
+ }
410
+
411
+ Action<Action> h = hooks.Dequeue();
412
+ if (h == null)
413
+ {
414
+ LogWarning("Hook is null???");
415
+ return;
416
+ }
417
+
418
+ try
419
+ {
420
+ h?.Invoke(Next);
421
+ }
422
+ catch (Exception e)
423
+ {
424
+ Debug.LogWarning("Exception while triggering hook: " + e);
425
+ Next();
426
+ }
427
+ }
381
428
  }
382
429
  }
383
430
  }
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 5c409fb968e8e4ed0a49083934f184d6
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -1,8 +1,10 @@
1
- using System;
2
- using Amanotes.Core.Internal;
3
- using UnityEditor;
1
+ using System;
4
2
  using UnityEngine;
5
- namespace Amanotes.Editor
3
+
4
+ #if UNITY_EDITOR
5
+ using System.Collections.Generic;
6
+ using UnityEditor;
7
+ namespace Amanotes.Core.Internal
6
8
  {
7
9
  internal static class AmaGUI
8
10
  {
@@ -11,10 +13,9 @@ namespace Amanotes.Editor
11
13
  private static readonly Color DARK = new Color(0.15f, 0.15f, 0.15f, 1f);
12
14
 
13
15
  private static GUIStyle BIG_LABEL;
14
-
15
- private static readonly Texture2D TAG_0 = (Texture2D)EditorGUIUtility.IconContent("sv_label_0").image;
16
- private static readonly Texture2D TAG_1 = (Texture2D)EditorGUIUtility.IconContent("sv_icon_dot1_pix16_gizmo").image;
17
- private static GUIStyle versionStyle = new GUIStyle(EditorStyles.miniBoldLabel)
16
+ private static readonly Texture2D TAG_0 = (Texture2D) EditorGUIUtility.IconContent("sv_label_0").image;
17
+ private static readonly Texture2D TAG_1 = (Texture2D) EditorGUIUtility.IconContent("sv_icon_dot1_pix16_gizmo").image;
18
+ private static readonly GUIStyle versionStyle = new GUIStyle(EditorStyles.miniBoldLabel)
18
19
  {
19
20
  alignment = TextAnchor.MiddleCenter
20
21
  };
@@ -23,6 +24,82 @@ namespace Amanotes.Editor
23
24
  alignment = TextAnchor.MiddleCenter
24
25
  };
25
26
 
27
+ public static void DrawListColumn<T>(IList<T> list, Action<T> draw, float minColumnWidth = 300)
28
+ {
29
+ int nCols = Mathf.Max(1, Mathf.FloorToInt(Screen.width / minColumnWidth));
30
+ int n = Mathf.CeilToInt(list.Count / (float)nCols);
31
+
32
+ GUILayout.BeginHorizontal();
33
+ {
34
+ for (var c = 0; c < nCols; c++)
35
+ {
36
+ GUILayout.BeginVertical();
37
+ {
38
+ int min = c * n;
39
+ int max = Mathf.Min(min + n, list.Count);
40
+
41
+ for (int i = min; i < max; i++)
42
+ {
43
+ draw(list[i]);
44
+ }
45
+ }
46
+ GUILayout.EndVertical();
47
+ GUILayout.Space(4f);
48
+ }
49
+ }
50
+ GUILayout.EndHorizontal();
51
+ }
52
+
53
+
54
+ public static void DrawTag(Rect rect, string label, Color tagColor, float alpha = 1f, float margin = 1f)
55
+ {
56
+ rect.xMin += margin;
57
+ rect.xMax -= margin;
58
+ rect.yMin += margin;
59
+ rect.yMax -= margin;
60
+
61
+ tagColor.a = alpha;
62
+ GUI.DrawTexture(rect, Texture2D.whiteTexture, ScaleMode.StretchToFill, false, 1f, tagColor, 0f, 5f);
63
+
64
+ rect.xMin += 4f;
65
+ GUI.Label(rect, label, versionStyle);
66
+ }
67
+
68
+ public static void Draw9Slice(Rect rect, Texture2D texture, float l, float r, float t, float b)
69
+ {
70
+ float x = rect.x;
71
+ float y = rect.y;
72
+ float w = rect.width;
73
+ float h = rect.height;
74
+
75
+ float tw = texture.width;
76
+ float th = texture.height;
77
+
78
+ float lu = l / tw;
79
+ float ru = (tw - r) / tw;
80
+ float tv = (th - t) / th;
81
+ float bv = b / th;
82
+
83
+ // Calculate the sizes of the texture's center and corners.
84
+ float centerX = Mathf.Max(w - l - r, 0);
85
+ float centerY = Mathf.Max(h - t - b, 0);
86
+
87
+ // Draw the corners.
88
+ GUI.DrawTextureWithTexCoords(new Rect(x, y, l, t), texture, new Rect(0, tv, lu, t / th));
89
+ GUI.DrawTextureWithTexCoords(new Rect(x + w - r, y, r, t), texture, new Rect(ru, tv, r / tw, t / th));
90
+ GUI.DrawTextureWithTexCoords(new Rect(x, y + h - b, l, b), texture, new Rect(0, 0, lu, bv));
91
+ GUI.DrawTextureWithTexCoords(new Rect(x + w - r, y + h - b, r, b), texture, new Rect(ru, 0, r / tw, bv));
92
+
93
+ // Draw the edges.
94
+ GUI.DrawTextureWithTexCoords(new Rect(x + l, y, centerX, t), texture, new Rect(lu, tv, ru - lu, t / th));
95
+ GUI.DrawTextureWithTexCoords(new Rect(x, y + t, l, centerY), texture, new Rect(0, bv, lu, tv - bv));
96
+ GUI.DrawTextureWithTexCoords(new Rect(x + w - r, y + t, r, centerY), texture, new Rect(ru, bv, r / tw, tv - bv));
97
+ GUI.DrawTextureWithTexCoords(new Rect(x + l, y + h - b, centerX, b), texture, new Rect(lu, 0, ru - lu, bv));
98
+
99
+ // Draw the center.
100
+ GUI.DrawTextureWithTexCoords(new Rect(x + l, y + t, centerX, centerY), texture, new Rect(lu, bv, ru - lu, tv - bv));
101
+ }
102
+
26
103
  public static void SectionLabel(string text)
27
104
  {
28
105
  if (BIG_LABEL == null)
@@ -31,13 +108,12 @@ namespace Amanotes.Editor
31
108
  {
32
109
  fontSize = 18,
33
110
  alignment = TextAnchor.MiddleCenter,
34
- richText = true
111
+ richText = true,
112
+ normal = { textColor = Color.white }
35
113
  };
36
-
37
- BIG_LABEL.normal.textColor = Color.white;
38
114
  }
39
-
40
- var rect = GUILayoutUtility.GetRect(Screen.width, 32);
115
+
116
+ Rect rect = GUILayoutUtility.GetRect(Screen.width, 32);
41
117
  rect.xMin -= 16f;
42
118
  EditorGUI.DrawRect(rect, DARK);
43
119
  EditorGUI.LabelField(rect, text, BIG_LABEL);
@@ -50,7 +126,7 @@ namespace Amanotes.Editor
50
126
  bool result;
51
127
  if (color != null)
52
128
  {
53
- var c = colorMod < 0f ? Color.Lerp(color.Value, Color.black, -colorMod)
129
+ Color c = colorMod < 0f ? Color.Lerp(color.Value, Color.black, -colorMod)
54
130
  : colorMod > 0f ? Color.Lerp(color.Value, Color.white, colorMod) : color.Value;
55
131
  GUI.backgroundColor = c;
56
132
  }
@@ -67,16 +143,16 @@ namespace Amanotes.Editor
67
143
  EditorGUIUtility.labelWidth = 220f;
68
144
  bool newValue = EditorGUILayout.Toggle(label, value);
69
145
  EditorGUIUtility.labelWidth = lbWidth;
70
-
146
+
71
147
  if (newValue == value) return false;
72
148
  value = newValue;
73
149
  return true;
74
150
  }
75
151
 
76
- public static bool ToggleGroup(string label, ref bool isOpen, Action drawFunc, Action titleFunc = null)
152
+ public static bool Foldout(string label, ref bool isOpen, Action drawFunc, Action titleFunc = null, GUIStyle style = null)
77
153
  {
78
154
  GUILayout.BeginHorizontal();
79
- bool newValue = EditorGUILayout.Foldout(isOpen, label);
155
+ bool newValue = EditorGUILayout.Foldout(isOpen, label, EditorStyles.foldoutHeader);
80
156
  bool changed = newValue != isOpen;
81
157
  titleFunc?.Invoke();
82
158
  GUILayout.EndHorizontal();
@@ -93,92 +169,41 @@ namespace Amanotes.Editor
93
169
  isOpen = newValue;
94
170
  return true;
95
171
  }
96
-
172
+
97
173
  public static void SemVerGUI(string title, SemVer version, Color? color1 = null, Color? color2 = null)
98
174
  {
99
175
  const int TAG_SIZE = 60;
100
- var rect = GUILayoutUtility.GetRect(120, 16f);
101
- var rect1 = rect;
176
+ Rect rect = GUILayoutUtility.GetRect(120, 16f);
177
+ Rect rect1 = rect;
102
178
 
103
179
  rect1.width /= 2;
104
- var rect2 = rect1;
180
+ Rect rect2 = rect1;
105
181
  rect2.x += rect.width / 2f;
106
-
182
+
107
183
  GUI.Box(rect, GUIContent.none);
108
- rect2.xMin += (rect2.width-TAG_SIZE);
184
+ rect2.xMin += (rect2.width - TAG_SIZE);
109
185
  rect2.width = TAG_SIZE;
110
186
 
111
- if (!color1.HasValue) color1 = LIGHT_BLUE;
112
- if (!color2.HasValue) color2 = LIGHT_GRAY;
187
+ color1 ??= LIGHT_BLUE;
188
+ color2 ??= LIGHT_GRAY;
113
189
  DrawTag(rect2, version.ToString(), version.isValid ? color1.Value : color2.Value, 0.5f);
114
190
 
115
191
  rect1.xMin += 4f;
116
192
  rect1.width = rect.width - rect2.width;
117
193
  GUI.Label(rect1, title, versionStyle);
118
194
  }
119
-
120
- public static void DrawSDKStatus(string sdkId)
121
- {
122
- var status = SDKStatus.Get(sdkId);
123
- GUILayout.BeginHorizontal();
124
- {
125
- GUILayout.Label(ObjectNames.NicifyVariableName(sdkId), EditorStyles.boldLabel);
126
- GUILayout.FlexibleSpace();
127
- SemVerGUI("SDK", status.sdkVersion);
128
- GUILayout.Space(4);
129
- SemVerGUI("Adapter", status.adapterVersion);
130
- }
131
- GUILayout.EndHorizontal();
132
- }
133
-
134
- public static void DrawTag(Rect rect, string label, Color tagColor, float alpha = 1f, float margin = 1f)
195
+
196
+ public static void DrawVersionTag(SemVer version, bool? isValid = null)
135
197
  {
136
- rect.xMin += margin;
137
- rect.xMax -= margin;
138
- rect.yMin += margin;
139
- rect.yMax -= margin;
140
-
141
- tagColor.a = alpha;
142
- GUI.DrawTexture(rect, Texture2D.whiteTexture, ScaleMode.StretchToFill, false, 1f, tagColor, 0f, 5f);
143
-
144
- rect.xMin += 4f;
145
- GUI.Label(rect, label, versionStyle);
198
+ Rect rect = GUILayoutUtility.GetRect(60f, 60f, 18f, 18f);
199
+ DrawVersionTag(rect, version, isValid);
146
200
  }
147
-
148
- public static void Draw9Slice(Rect rect, Texture2D texture,
149
- float l, float r, float t, float b)
201
+
202
+ public static void DrawVersionTag(Rect rect, SemVer version, bool? isValid = null)
150
203
  {
151
- float x = rect.x;
152
- float y = rect.y;
153
- float w = rect.width;
154
- float h = rect.height;
155
-
156
- float tw = texture.width;
157
- float th = texture.height;
158
-
159
- float lu = l / tw;
160
- float ru = (tw - r) / tw;
161
- float tv = (th - t) / th;
162
- float bv = b / th;
163
-
164
- // Calculate the sizes of the texture's center and corners.
165
- float centerX = Mathf.Max(w - l - r, 0);
166
- float centerY = Mathf.Max(h - t - b, 0);
167
-
168
- // Draw the corners.
169
- GUI.DrawTextureWithTexCoords(new Rect(x, y, l, t), texture, new Rect(0, tv, lu, t / th));
170
- GUI.DrawTextureWithTexCoords(new Rect(x + w - r, y, r, t), texture, new Rect(ru, tv, r / tw, t / th));
171
- GUI.DrawTextureWithTexCoords(new Rect(x, y + h - b, l, b), texture, new Rect(0, 0, lu, bv));
172
- GUI.DrawTextureWithTexCoords(new Rect(x + w - r, y + h - b, r, b), texture, new Rect(ru, 0, r / tw, bv));
173
-
174
- // Draw the edges.
175
- GUI.DrawTextureWithTexCoords(new Rect(x + l, y, centerX, t), texture, new Rect(lu, tv, ru - lu, t / th));
176
- GUI.DrawTextureWithTexCoords(new Rect(x, y + t, l, centerY), texture, new Rect(0, bv, lu, tv - bv));
177
- GUI.DrawTextureWithTexCoords(new Rect(x + w - r, y + t, r, centerY), texture, new Rect(ru, bv, r / tw, tv - bv));
178
- GUI.DrawTextureWithTexCoords(new Rect(x + l, y + h - b, centerX, b), texture, new Rect(lu, 0, ru - lu, bv));
179
-
180
- // Draw the center.
181
- GUI.DrawTextureWithTexCoords(new Rect(x + l, y + t, centerX, centerY), texture, new Rect(lu, bv, ru - lu, tv - bv));
204
+ isValid ??= version.isValid;
205
+ DrawTag(rect, version.ToString(), isValid.Value ? LIGHT_BLUE : LIGHT_GRAY, 0.5f);
182
206
  }
183
207
  }
184
208
  }
209
+ #endif
@@ -1,5 +1,5 @@
1
1
  fileFormatVersion: 2
2
- guid: 3e22cadf10a36442f9c330cd96560105
2
+ guid: af9c65abd69234ff6bc2f3c8b9f3d92f
3
3
  MonoImporter:
4
4
  externalObjects: {}
5
5
  serializedVersion: 2