com.amanotes.gdk 0.2.45 → 0.2.46-2

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 (29) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/Editor/AmaGDKEditor.cs +95 -67
  3. package/Editor/Utils/AmaGDKEditor.ExtractVersion.cs +1 -3
  4. package/Extra/AmaGDKInstaller.unitypackage +0 -0
  5. package/Extra/AmaGDKProject.unitypackage +0 -0
  6. package/Packages/AmaGDKConfig.unitypackage +0 -0
  7. package/Packages/AmaGDKExample.unitypackage +0 -0
  8. package/Packages/AmaGDKTest.unitypackage +0 -0
  9. package/Packages/AppsFlyerAdapter_v6.5.4.unitypackage +0 -0
  10. package/Packages/FirebaseAnalyticsAdapter_v9.1.0.unitypackage +0 -0
  11. package/Packages/FirebaseRemoteConfigAdapter_v9.1.0.unitypackage +0 -0
  12. package/Packages/IronSourceAdapter_v7.5.2.unitypackage +0 -0
  13. package/Packages/RevenueCatAdapter_v6.0.0.unitypackage +0 -0
  14. package/Runtime/AmaGDK.Ads.cs +11 -5
  15. package/Runtime/AmaGDK.Analytics.cs +57 -29
  16. package/Runtime/AmaGDK.UserProfile.cs +113 -104
  17. package/Runtime/AmaGDK.cs +1 -1
  18. package/{Editor/Utils/AmaGDKEditor.GUI.cs → Runtime/Internal/AmaGDK.Internal.AmaGUI.cs} +106 -86
  19. package/{Editor/Utils/AmaGDKEditor.GUI.cs.meta → Runtime/Internal/AmaGDK.Internal.AmaGUI.cs.meta} +1 -1
  20. package/Runtime/{AmaGDK.Utils.cs → Internal/AmaGDK.Utils.cs} +13 -6
  21. package/Runtime/Internal.meta +8 -0
  22. package/package.json +1 -1
  23. /package/Runtime/{AmaGDK.Internal.SemVer.cs → Internal/AmaGDK.Internal.SemVer.cs} +0 -0
  24. /package/Runtime/{AmaGDK.Internal.SemVer.cs.meta → Internal/AmaGDK.Internal.SemVer.cs.meta} +0 -0
  25. /package/Runtime/{AmaGDK.Internal.cs → Internal/AmaGDK.Internal.cs} +0 -0
  26. /package/Runtime/{AmaGDK.Internal.cs.meta → Internal/AmaGDK.Internal.cs.meta} +0 -0
  27. /package/Runtime/{AmaGDK.Utils.cs.meta → Internal/AmaGDK.Utils.cs.meta} +0 -0
  28. /package/Runtime/{AmaGDK.WebUtils.cs → Internal/AmaGDK.WebUtils.cs} +0 -0
  29. /package/Runtime/{AmaGDK.WebUtils.cs.meta → Internal/AmaGDK.WebUtils.cs.meta} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.46-2 - 2024-01-18]
4
+ - Update UserId every session
5
+ - Migrate accumulated_count gradually
6
+
7
+ ## [0.2.46 - 2023-12-19]
8
+ - Cleaner UI interface for AmaGDK Inspector
9
+ - Add AmaGUI to centralize all GUI handles
10
+ - [Fix] OnAdResult callback being looped through calling StopWaitForAd
11
+ - [Fix] Exception while loading / parsing LoadJsonFromFile
12
+
3
13
  ## [0.2.45 - 2023-12-13]
4
14
  - [Fix] Able to assign ama_device_id in Editor
5
15
 
@@ -7,7 +7,6 @@ using System.IO;
7
7
  using UnityEditor;
8
8
  using UnityEngine;
9
9
  using static Amanotes.Core.Internal.Logging;
10
- using static Amanotes.Editor.AmaGUI;
11
10
  using static Amanotes.Core.AmaGDK.AdapterID;
12
11
 
13
12
  namespace Amanotes.Editor
@@ -67,7 +66,7 @@ namespace Amanotes.Editor
67
66
 
68
67
  GUILayout.BeginHorizontal();
69
68
  {
70
- if (BigButton("CREATE", 40f, BLUE))
69
+ if (AmaGUI.BigButton("CREATE", 40f, BLUE))
71
70
  {
72
71
  try
73
72
  {
@@ -94,13 +93,13 @@ namespace Amanotes.Editor
94
93
  {
95
94
  if (sdk.autoInit)
96
95
  {
97
- Toggle("Auto Init", ref sdk.autoInit);
96
+ AmaGUI.Toggle("Auto Init", ref sdk.autoInit);
98
97
  EditorUtility.SetDirty(sdk);
99
98
  return;
100
99
  }
101
100
 
102
101
  EditorGUILayout.HelpBox("You disabled AmaGDK AutoInit\nMake sure to call AmaGDK.Init() manually!", MessageType.Warning);
103
- if (BigButton("Enable AutoInit", 40f, BLUE))
102
+ if (AmaGUI.BigButton("Enable AutoInit", 40f, BLUE))
104
103
  {
105
104
  sdk.autoInit = true;
106
105
  EditorUtility.SetDirty(sdk);
@@ -128,17 +127,18 @@ namespace Amanotes.Editor
128
127
 
129
128
  adapterScanned = true;
130
129
 
131
- var adapterPath = Directory.GetFiles(Res.PACKAGE_PATH, "*Adapter*.unitypackage", SearchOption.AllDirectories);
130
+ string[] adapterPath = Directory.GetFiles(Res.PACKAGE_PATH, "*Adapter*.unitypackage", SearchOption.AllDirectories);
132
131
 
133
- for (int i = 0; i < adapterPath.Length; i++)
132
+ for (var i = 0; i < adapterPath.Length; i++)
134
133
  {
135
134
  lstAdapter.Add(Path.GetFileName(adapterPath[i]));
136
135
  }
137
136
  }
137
+
138
138
  private void DrawGUI_AdapterList()
139
139
  {
140
140
  UpdateListAdapter();
141
- foreach (var adapter in lstAdapter)
141
+ foreach (string adapter in lstAdapter)
142
142
  {
143
143
  if (GUILayout.Button(ObjectNames.NicifyVariableName(adapter)))
144
144
  {
@@ -157,6 +157,7 @@ namespace Amanotes.Editor
157
157
  AssetDatabase.ImportPackage(package, false);
158
158
  }
159
159
  }
160
+
160
161
  private void DrawGUI_ColorPicker()
161
162
  {
162
163
  GUILayout.BeginHorizontal();
@@ -166,67 +167,55 @@ namespace Amanotes.Editor
166
167
  }
167
168
  GUILayout.EndHorizontal();
168
169
  }
169
-
170
+
171
+ public void CopyVersion()
172
+ {
173
+ var sb = new StringBuilder();
174
+ sb.AppendLine("ID\tSDK VERSION\tADAPTER VERSION");
175
+ for (var i = 0; i < SDK_IDS.Length; i++)
176
+ {
177
+ var status = SDKStatus.Get(SDK_IDS[i]);
178
+ sb.AppendLine(status.ToTSVString());
179
+ if (status.sdkId != IRONSOURCE) continue;
180
+ if (!status.sdkInstalled || !status.adapterInstalled) continue;
181
+
182
+ List<IronSourceSDKAdapter> list = ExtractVersion.IronSourceAdapter();
183
+ for (var j = 0; j < list.Count; j++)
184
+ {
185
+ IronSourceSDKAdapter item = list[j];
186
+ sb.AppendLine($"IS{item.name}Adapter\t{item.version}");
187
+ }
188
+ }
189
+
190
+ var tsv = sb.ToString();
191
+ EditorGUIUtility.systemCopyBuffer = tsv;
192
+ Debug.Log($"Content of version_info.tsv copied to clipboard!\n\n{tsv}\n\n");
193
+ }
194
+
170
195
  public override void OnInspectorGUI()
171
196
  {
172
197
  if (sdk == null) return;
173
198
 
174
199
  // DrawGUI_ColorPicker();
175
- SectionLabel($"<b>AmaGDK</b> <size=12><color=gray>v{AmaGDK.VERSION}</color></size>");
200
+ AmaGUI.SectionLabel($"<b>AmaGDK</b> <size=12><color=gray>v{AmaGDK.VERSION}</color></size>");
176
201
  EditorGUILayout.Space();
177
-
202
+
178
203
  for (var i = 0; i < SDK_IDS.Length; i++)
179
204
  {
180
205
  string id = SDK_IDS[i];
181
- AmaGUI.DrawSDKStatus(SDK_IDS[i]);
182
-
183
- if (id == IRONSOURCE)
184
- {
185
- var lastRect = GUILayoutUtility.GetLastRect();
186
- lastRect.width = 18f;
187
- lastRect.y += 2f;
188
- showIronSourceSDKAdapter = EditorGUI.Foldout(lastRect, showIronSourceSDKAdapter, "");
189
- if (showIronSourceSDKAdapter)
190
- {
191
- DrawIRSAdapterVersions();
192
- }
193
- }
206
+ DrawAdapterDetail(id);
194
207
  }
195
208
  EditorGUILayout.Space();
196
-
197
- if (GUILayout.Button("version_info.tsv -> Clipboard"))
198
- {
199
- var sb = new StringBuilder();
200
- sb.AppendLine("ID\tSDK VERSION\tADAPTER VERSION");
201
- for (var i = 0; i < SDK_IDS.Length; i++)
202
- {
203
- var status = SDKStatus.Get(SDK_IDS[i]);
204
- sb.AppendLine(status.ToTSVString());
205
- if (status.sdkId != IRONSOURCE) continue;
206
- if (!status.sdkInstalled || !status.adapterInstalled) continue;
207
-
208
- List<IronSourceSDKAdapter> list = ExtractVersion.IronSourceAdapter();
209
- for (var j = 0; j < list.Count; j++)
210
- {
211
- var item = list[j];
212
- sb.AppendLine($"IS{item.name}Adapter\t{item.version}");
213
- }
214
- }
215
-
216
- var tsv = sb.ToString();
217
- EditorGUIUtility.systemCopyBuffer = tsv;
218
- Debug.Log($"Content of version_info.tsv copied to clipboard!\n\n{tsv}\n\n");
219
- }
220
-
209
+
221
210
  if (configAsset == null)
222
211
  {
223
212
  DrawGUI_ConfigMissing();
224
213
  return;
225
214
  }
226
-
215
+
227
216
  DrawGUI_AutoInit();
228
- ToggleGroup("Config", ref showConfigDetail, DrawGUI_ConfigDetail, DrawGUI_ConfigAsset);
229
- ToggleGroup("Adapters", ref showAdapterInstaller, DrawGUI_AdapterList);
217
+ AmaGUI.Foldout("Config", ref showConfigDetail, DrawGUI_ConfigDetail, DrawGUI_ConfigAsset);
218
+ AmaGUI.Foldout("Adapters", ref showAdapterInstaller, DrawGUI_AdapterList);
230
219
 
231
220
  //("Example", ref showExampleDetail, DrawGUI_ExampleScene);
232
221
 
@@ -236,32 +225,71 @@ namespace Amanotes.Editor
236
225
  }
237
226
  }
238
227
 
239
- private static void DrawVersion(string label, string version)
228
+ private static readonly Dictionary<string, bool> configOpen = new Dictionary<string, bool>();
229
+ private static void DrawAdapterDetail(string adapterId)
240
230
  {
241
- EditorGUI.BeginDisabledGroup(true);
231
+ if (!configOpen.TryGetValue(adapterId, out bool isOpen))
242
232
  {
243
- GUILayout.Label($"{label} v{version}", EditorStyles.largeLabel);
233
+ configOpen.Add(adapterId, isOpen = false);
244
234
  }
245
- EditorGUI.EndDisabledGroup();
235
+
236
+ SDKStatus status = SDKStatus.Get(adapterId);
237
+ bool changed = AmaGUI.Foldout(ObjectNames.NicifyVariableName(adapterId), ref isOpen, () =>
238
+ {
239
+ DrawSDKConfig(adapterId, status);
240
+ }, () =>
241
+ {
242
+ GUILayout.FlexibleSpace();
243
+ AmaGUI.DrawVersionTag(status.sdkVersion, status.adapterInstalled);
244
+ });
245
+
246
+ if (changed) configOpen[adapterId] = isOpen;
246
247
  }
247
- public static bool showIronSourceSDKAdapter = false;
248
248
 
249
- public static void DrawIRSAdapterVersions()
249
+ private static void DrawSDKConfig(string adapterId, SDKStatus status)
250
+ {
251
+ if (!status.sdkInstalled)
252
+ {
253
+ EditorGUILayout.HelpBox($"{adapterId} SDK not installed", MessageType.Warning);
254
+ return;
255
+ }
256
+ if (!status.adapterInstalled)
257
+ {
258
+ EditorGUILayout.HelpBox($"{adapterId}-GDKAdapter not installed", MessageType.Warning);
259
+ return;
260
+ }
261
+
262
+ if (adapterId == IRONSOURCE)
263
+ {
264
+ DrawIRSAdapterVersions();
265
+ } else
266
+ {
267
+ EditorGUILayout.HelpBox("Config for <" + adapterId + "> should be shown here!", MessageType.Info);
268
+ }
269
+ }
270
+
271
+ // private static void DrawVersion(string label, string version)
272
+ // {
273
+ // EditorGUI.BeginDisabledGroup(true);
274
+ // {
275
+ // GUILayout.Label($"{label} v{version}", EditorStyles.largeLabel);
276
+ // }
277
+ // EditorGUI.EndDisabledGroup();
278
+ // }
279
+
280
+ public static void DrawInitOrder()
250
281
  {
251
- SDKStatus status = SDKStatus.Get(IRONSOURCE);
252
- if (!status.sdkInstalled) return;
253
- if (!status.adapterInstalled) return;
254
- if (!showIronSourceSDKAdapter) return;
255
282
 
256
- // Get the list of installed SDK & versions
283
+ }
284
+
285
+ public static void DrawIRSAdapterVersions()
286
+ {
257
287
  List<IronSourceSDKAdapter> list = ExtractVersion.IronSourceAdapter();
258
-
259
288
  var color = new Color(0.0f, .5f, .5f, 1f);
260
- for (var i = 0; i < list.Count; i++)
289
+ AmaGUI.DrawListColumn(list, (item) =>
261
290
  {
262
- var item = list[i];
263
- SemVerGUI(item.name, item.semVer, color);
264
- }
291
+ AmaGUI.SemVerGUI(item.name, item.semVer, color);
292
+ });
265
293
  }
266
294
  }
267
295
  }
@@ -26,9 +26,7 @@ namespace Amanotes.Editor
26
26
 
27
27
  [Serializable] public class SDKStatus
28
28
  {
29
-
30
29
  //
31
-
32
30
  private static readonly Dictionary<string, SDKStatus> _cache = new Dictionary<string, SDKStatus>();
33
31
  public string sdkId;
34
32
  public SemVer adapterVersion;
@@ -184,7 +182,7 @@ namespace Amanotes.Editor
184
182
  if (oType.Name.Equals("AdjustAndroid") || oType.Name.Equals("AdjustiOS") )
185
183
  {
186
184
  version = oType.GetField("sdkPrefix", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null).ToString();
187
- version = version.StartsWith("unity") ? version.Substring(5) : "";
185
+ version = version != null && version.StartsWith("unity") ? version.Substring(5) : "";
188
186
  }
189
187
  }
190
188
  }
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -727,6 +727,14 @@ namespace Amanotes.Core.Internal
727
727
 
728
728
  private void ShowAdRoutineCompleted(bool isSuccess)
729
729
  {
730
+ ShowAdContext lastContext = Ads.context;
731
+ Ads.context = null;
732
+ if (lastContext == null)
733
+ {
734
+ LogWarning("Something wrong: lastContext == null!");
735
+ return;
736
+ }
737
+
730
738
  if (_loadState == LoadAdsState.Ready)
731
739
  {
732
740
  _loadState = isAdReady ? LoadAdsState.Ready : LoadAdsState.None;
@@ -736,8 +744,7 @@ namespace Amanotes.Core.Internal
736
744
  _showState = isSuccess ? ShowAdsState.ShowSuccess : ShowAdsState.ShowFail;
737
745
 
738
746
  // Extra callback
739
- Ads.context.showFinishAt = Time.realtimeSinceStartup;
740
- Ads.context.onAdResult?.Invoke(isSuccess);
747
+ lastContext.showFinishAt = Time.realtimeSinceStartup;
741
748
 
742
749
  var localData = Ads.localData;
743
750
  var stat = _isInterstitial ? localData.interstitial : localData.reward;
@@ -756,9 +763,8 @@ namespace Amanotes.Core.Internal
756
763
  localData.Save();
757
764
  HandleAfterAdShow();
758
765
 
759
- Log($"[Ad] {adType} ShowAdRoutineCompleted: {isSuccess}\n{JsonUtility.ToJson(Ads.context)}");
760
- Ads.context = null;
761
- _showState = ShowAdsState.None;
766
+ Log($"[Ad] {adType} ShowAdRoutineCompleted: {isSuccess}\n{JsonUtility.ToJson(lastContext)}");
767
+ lastContext.onAdResult?.Invoke(isSuccess);
762
768
  }
763
769
 
764
770
  private void HandleBeforeAdShow()
@@ -148,38 +148,40 @@ namespace Amanotes.Core
148
148
  {
149
149
  var flag = IntegrityFlag.Ok;
150
150
 
151
- foreach (string e in funnelEvents)
152
- {
153
- if (localData.funnelSignatures.Contains(e)) continue;
154
-
155
- flag |= IntegrityFlag.NewFunnel;
156
- localData.AddFunnelSignature(e);
157
- }
158
-
159
- foreach (KeyValuePair<string, int> e in eventCountMap)
160
- {
161
- EventDetail eventDetail = localData.GetEventDetail(e.Key);
162
- if (eventDetail == null)
151
+ if (funnelEvents != null)
152
+ foreach (string e in funnelEvents)
163
153
  {
164
- localData.eventDetails.Add(new EventDetail
165
- {
166
- eventName = e.Key,
167
- totalCount = e.Value
168
- });
169
- flag |= IntegrityFlag.NewEvent;
170
- continue;
171
- }
154
+ if (localData.funnelSignatures.Contains(e)) continue;
172
155
 
173
- if (eventDetail.totalCount != e.Value)
174
- {
175
- flag |= IntegrityFlag.DifferentCount;
156
+ flag |= IntegrityFlag.NewFunnel;
157
+ localData.AddFunnelSignature(e);
176
158
  }
177
159
 
178
- if (sumEventCount)
160
+ if (eventCountMap != null)
161
+ foreach (KeyValuePair<string, int> e in eventCountMap)
179
162
  {
180
- eventDetail.totalCount += e.Value;
163
+ EventDetail eventDetail = localData.GetEventDetail(e.Key);
164
+ if (eventDetail == null)
165
+ {
166
+ localData.eventDetails.Add(new EventDetail
167
+ {
168
+ eventName = e.Key,
169
+ totalCount = e.Value
170
+ });
171
+ flag |= IntegrityFlag.NewEvent;
172
+ continue;
173
+ }
174
+
175
+ if (eventDetail.totalCount != e.Value)
176
+ {
177
+ flag |= IntegrityFlag.DifferentCount;
178
+ }
179
+
180
+ if (sumEventCount)
181
+ {
182
+ eventDetail.totalCount += e.Value;
183
+ }
181
184
  }
182
- }
183
185
 
184
186
  return flag;
185
187
  }
@@ -279,12 +281,13 @@ namespace Amanotes.Core
279
281
  if (!ShouldSendEvent(eventData)) continue;
280
282
 
281
283
  var (countInSession, totalCount) = localData.IncreaseCounter(eventData);
282
- if (eventData.accumulated)
284
+ if (eventData.accumulated || eventData.parameters.ContainsKey("accumulated_count"))
283
285
  {
284
- eventData.AddParam("accumulated_count", eventData.withinSession ? countInSession : totalCount);
286
+ UpdateAccumulatedCount(eventData, countInSession, totalCount);
285
287
  }
286
288
 
287
- eventData.AddParam("ama_device_id", User.AmaDeviceId);
289
+ if (!eventData.parameters.ContainsKey("ama_device_id"))
290
+ eventData.AddParam("ama_device_id", User.AmaDeviceId);
288
291
 
289
292
  string eventNameToSend = GetEventNameToSend(eventData.eventName, countInSession, totalCount);
290
293
  if (common.normalizeEventName) NormalizeEventName(ref eventNameToSend);
@@ -308,6 +311,30 @@ namespace Amanotes.Core
308
311
  localData.SaveIfDirty();
309
312
  sessionStat.Save();
310
313
  }
314
+
315
+ internal static void UpdateAccumulatedCount(EventParams eventData, int countInSession, int totalCount)
316
+ {
317
+ var ACCUMULATED_COUNT = "accumulated_count";
318
+ var countByGDK = eventData.withinSession ? countInSession : totalCount;
319
+
320
+ if (!eventData.parameters.ContainsKey(ACCUMULATED_COUNT))
321
+ {
322
+ eventData.AddParam(ACCUMULATED_COUNT, countByGDK);
323
+ return;
324
+ }
325
+
326
+ int.TryParse(eventData.parameters[ACCUMULATED_COUNT].ToString(), out int oriAccCount);
327
+ if (oriAccCount != countByGDK)
328
+ {
329
+ LogWarning($"[Analytics] event <{eventData.eventName}> has difference in accumulated count. Original count: {oriAccCount}. AmaGDK count: {countByGDK}");
330
+ if (Config.common.migrateAccumulatedCount && !eventData.withinSession)
331
+ {
332
+ Log($"[Analytics] Update count of <{eventData.eventName}> from {countByGDK} to {oriAccCount}");
333
+ eventData.EventDetail.totalCount = oriAccCount;
334
+ localData._dirty = true;
335
+ }
336
+ }
337
+ }
311
338
 
312
339
  internal static bool IsAdapterForbidden(AdapterContext adapterContext, EventParams eventData)
313
340
  {
@@ -760,6 +787,7 @@ namespace Amanotes.Core.Internal
760
787
  public bool showAnalyticsLog = true;
761
788
  public bool normalizeEventName = true;
762
789
  public bool checkMigrationIntegrity = true;
790
+ public bool migrateAccumulatedCount = true;
763
791
  public bool enableEventStat;
764
792
  public AnalyticQualityConfig quality;
765
793
  }
@@ -1,5 +1,6 @@
1
1
  using System;
2
2
  using System.Collections;
3
+ using System.Collections.Generic;
3
4
  using System.Text.RegularExpressions;
4
5
  using Amanotes.Core.Internal;
5
6
  using UnityEngine;
@@ -13,24 +14,28 @@ namespace Amanotes.Core
13
14
  [Serializable]
14
15
  public partial class UserProfile : IJsonFile
15
16
  {
16
- private const string FILE_NAME = nameof(UserProfile);
17
- [NonSerialized] internal bool _dirty;
18
-
19
17
  private void Save()
20
18
  {
21
- GDKFileUtils.Save(FILE_NAME, JsonUtility.ToJson(this));
22
- }
23
-
24
- internal void SaveIfDirty()
25
- {
26
- if (!_dirty) return;
27
- _dirty = false;
28
19
  this.SaveJsonToFile();
29
20
  }
30
21
  }
31
22
 
32
23
  public partial class UserProfile //PUBLIC
33
24
  {
25
+ public Dictionary<string, object> CollectAllUserIds()
26
+ {
27
+ var dic = new Dictionary<string, object>();
28
+ if (!string.IsNullOrWhiteSpace(IDFA)) dic["idfa"] = IDFA;
29
+ if (!string.IsNullOrWhiteSpace(IDFV)) dic["idfv"] = IDFV;
30
+ if (!string.IsNullOrWhiteSpace(GAId)) dic["gaid"] = GAId;
31
+ if (!string.IsNullOrWhiteSpace(AndroidId)) dic["android_id"] = AndroidId;
32
+ if (!string.IsNullOrWhiteSpace(PseudoId)) dic["pseudo_id"] = PseudoId;
33
+ if (!string.IsNullOrWhiteSpace(AmaDeviceId)) dic["ama_device_id"] = AmaDeviceId;
34
+ if (!string.IsNullOrWhiteSpace(AppsFlyerId)) dic["appsflyer_id"] = AppsFlyerId;
35
+ if (!string.IsNullOrWhiteSpace(InstallationId)) dic["installation_id"] = InstallationId;
36
+ return dic;
37
+ }
38
+
34
39
  public string UserId
35
40
  {
36
41
  get
@@ -101,6 +106,63 @@ namespace Amanotes.Core
101
106
  get => _installationId;
102
107
  set => _installationId = ValidateId(value, ALPHANUMERIC_PATTERN);
103
108
  }
109
+
110
+ public void UpdateUserId()
111
+ {
112
+ #if UNITY_ANDROID
113
+ if (!string.IsNullOrWhiteSpace(_gaid))
114
+ {
115
+ UserId = $"GAID-{_gaid}";
116
+ return;
117
+ }
118
+ #endif
119
+ #if UNITY_IOS
120
+ if (!string.IsNullOrWhiteSpace(_idfa))
121
+ {
122
+ UserId = $"IDFA-{_idfa}";
123
+ return;
124
+ }
125
+ #endif
126
+
127
+ if (!string.IsNullOrWhiteSpace(_pseudoId))
128
+ {
129
+ UserId = $"FRB-{_pseudoId}";
130
+ return;
131
+ }
132
+
133
+ #if UNITY_ANDROID
134
+ if (!string.IsNullOrWhiteSpace(_androidId))
135
+ {
136
+ UserId = $"ADR-{_androidId}";
137
+ return;
138
+ }
139
+ #endif
140
+ #if UNITY_IOS
141
+ if (!string.IsNullOrWhiteSpace(_idfv))
142
+ {
143
+ UserId = $"IDFV-{_idfv}";
144
+ return;
145
+ }
146
+ #endif
147
+
148
+ if (!string.IsNullOrWhiteSpace(_amaDeviceId))
149
+ {
150
+ UserId = $"AMA-{_amaDeviceId}";
151
+ return;
152
+ }
153
+
154
+ if (!string.IsNullOrWhiteSpace(_appsFlyerId))
155
+ {
156
+ UserId = $"AF-{_appsFlyerId}";
157
+ return;
158
+ }
159
+
160
+ if (!string.IsNullOrWhiteSpace(_installationId))
161
+ {
162
+ UserId = $"INS-{_installationId}";
163
+ return;
164
+ }
165
+ }
104
166
  }
105
167
 
106
168
  public partial class UserProfile //INTERNAL
@@ -136,6 +198,14 @@ namespace Amanotes.Core
136
198
  internal IEnumerator Init()
137
199
  {
138
200
  User.LoadJsonFromFile();
201
+
202
+ #if UNITY_ANDROID
203
+ AndroidId = SystemInfo.deviceUniqueIdentifier;
204
+ #elif UNITY_IOS
205
+ IDFV = SystemInfo.deviceUniqueIdentifier;
206
+ #endif
207
+
208
+ // Always get the latest advertising id
139
209
  GetAdvertisingId();
140
210
 
141
211
  float time = 0;
@@ -149,67 +219,6 @@ namespace Amanotes.Core
149
219
  }
150
220
  }
151
221
 
152
- internal void UpdateUserId()
153
- {
154
- if (!string.IsNullOrWhiteSpace(_userId))
155
- {
156
- OnUserIdChanged?.Invoke(_userId);
157
- return;
158
- }
159
-
160
- #if UNITY_ANDROID
161
- if (!string.IsNullOrWhiteSpace(_gaid))
162
- {
163
- UserId = $"GAID-{_gaid}";
164
- return;
165
- }
166
-
167
- if (!string.IsNullOrWhiteSpace(_androidId))
168
- {
169
- UserId = $"ADR-{_androidId}";
170
- return;
171
- }
172
- #endif
173
-
174
- #if UNITY_IOS
175
- if (!string.IsNullOrWhiteSpace(_idfa))
176
- {
177
- UserId = $"IDFA-{_idfa}";
178
- return;
179
- }
180
-
181
- if (!string.IsNullOrWhiteSpace(_idfv))
182
- {
183
- UserId = $"IDFV-{_idfv}";
184
- return;
185
- }
186
- #endif
187
-
188
- if (!string.IsNullOrWhiteSpace(_pseudoId))
189
- {
190
- UserId = $"FRB-{_pseudoId}";
191
- return;
192
- }
193
-
194
- if (!string.IsNullOrWhiteSpace(_amaDeviceId))
195
- {
196
- UserId = $"AMA-{_amaDeviceId}";
197
- return;
198
- }
199
-
200
- if (!string.IsNullOrWhiteSpace(_appsFlyerId))
201
- {
202
- UserId = $"AF-{_appsFlyerId}";
203
- return;
204
- }
205
-
206
- if (!string.IsNullOrWhiteSpace(_installationId))
207
- {
208
- UserId = $"INS-{_installationId}";
209
- return;
210
- }
211
- }
212
-
213
222
  private bool IsAmaDeviceIdExist()
214
223
  {
215
224
  if (!string.IsNullOrEmpty(_amaDeviceId))
@@ -226,14 +235,9 @@ namespace Amanotes.Core
226
235
  {
227
236
  case RuntimePlatform.IPhonePlayer:
228
237
  IDFA = id;
229
- IDFV = SystemInfo.deviceUniqueIdentifier;
230
238
  break;
231
239
  case RuntimePlatform.Android:
232
240
  GAId = id;
233
- AndroidId = SystemInfo.deviceUniqueIdentifier;
234
- break;
235
- default:
236
- Logging.LogWarning($"Unsupported platform: {Application.platform}");
237
241
  break;
238
242
  }
239
243
  }
@@ -242,35 +246,40 @@ namespace Amanotes.Core
242
246
  {
243
247
  AdvertisingIdFetcher.RequestAdvertisingId(advertisingId =>
244
248
  {
245
- SetAdvertisingID(advertisingId);
246
- switch (Application.platform)
249
+ GDKUtils.DelayCall(0, () =>
247
250
  {
248
- case RuntimePlatform.IPhonePlayer:
249
- string v = KeyChain.GetKeyChain(AMA_DEVICE_ID_KEY);
250
- if (string.IsNullOrEmpty(v))
251
- {
252
- v = Guid.NewGuid().ToString();
253
- KeyChain.SetKeyChain(AMA_DEVICE_ID_KEY, v);
254
- }
255
- AmaDeviceId = v;
256
- break;
257
-
258
- case RuntimePlatform.Android:
259
- string cachedAmaDeviceId = PlayerPrefs.GetString(AMA_DEVICE_ID_KEY);
260
- if (string.IsNullOrEmpty(cachedAmaDeviceId))
261
- {
262
- cachedAmaDeviceId = SystemInfo.deviceUniqueIdentifier;
263
- PlayerPrefs.SetString(AMA_DEVICE_ID_KEY, cachedAmaDeviceId);
264
- }
265
- AmaDeviceId = cachedAmaDeviceId;
266
- break;
267
-
268
- default:
269
- AmaDeviceId = SystemInfo.deviceUniqueIdentifier;
270
- break;
271
- }
272
- Logging.Log($"Generate AmaDeviceId completed: {_amaDeviceId}");
273
- User.Save();
251
+ SetAdvertisingID(advertisingId);
252
+ switch (Application.platform)
253
+ {
254
+ case RuntimePlatform.IPhonePlayer:
255
+ string v = KeyChain.GetKeyChain(AMA_DEVICE_ID_KEY);
256
+ if (string.IsNullOrEmpty(v))
257
+ {
258
+ v = Guid.NewGuid().ToString();
259
+ KeyChain.SetKeyChain(AMA_DEVICE_ID_KEY, v);
260
+ }
261
+
262
+ AmaDeviceId = v;
263
+ break;
264
+
265
+ case RuntimePlatform.Android:
266
+ string cachedAmaDeviceId = PlayerPrefs.GetString(AMA_DEVICE_ID_KEY);
267
+ if (string.IsNullOrEmpty(cachedAmaDeviceId))
268
+ {
269
+ cachedAmaDeviceId = SystemInfo.deviceUniqueIdentifier;
270
+ PlayerPrefs.SetString(AMA_DEVICE_ID_KEY, cachedAmaDeviceId);
271
+ }
272
+
273
+ AmaDeviceId = cachedAmaDeviceId;
274
+ break;
275
+
276
+ default:
277
+ AmaDeviceId = SystemInfo.deviceUniqueIdentifier;
278
+ break;
279
+ }
280
+ Logging.Log($"Generate AmaDeviceId completed: {_amaDeviceId}");
281
+ User.Save();
282
+ });
274
283
  });
275
284
  }
276
285
 
package/Runtime/AmaGDK.cs CHANGED
@@ -15,7 +15,7 @@ namespace Amanotes.Core
15
15
  {
16
16
  public partial class AmaGDK : MonoBehaviour
17
17
  {
18
- public const string VERSION = "0.2.45";
18
+ public const string VERSION = "0.2.46-2";
19
19
 
20
20
  internal static AmaGDK _instance;
21
21
  internal static Status _status = Status.None;
@@ -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,13 +143,13 @@ 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)
77
153
  {
78
154
  GUILayout.BeginHorizontal();
79
155
  bool newValue = EditorGUILayout.Foldout(isOpen, label);
@@ -93,92 +169,36 @@ 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)
135
- {
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);
146
- }
147
-
148
- public static void Draw9Slice(Rect rect, Texture2D texture,
149
- float l, float r, float t, float b)
195
+
196
+ public static void DrawVersionTag(SemVer version, bool? isValid = null)
150
197
  {
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));
198
+ isValid ??= version.isValid;
199
+ Rect rect = GUILayoutUtility.GetRect(60f, 60f, 18f, 18f);
200
+ DrawTag(rect, version.ToString(), isValid.Value ? LIGHT_BLUE : LIGHT_GRAY, 0.5f);
182
201
  }
183
202
  }
184
203
  }
204
+ #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
@@ -253,14 +253,21 @@ namespace Amanotes.Core.Internal
253
253
  {
254
254
  public static T LoadJsonFromFile<T>(this T instance) where T : IJsonFile, new()
255
255
  {
256
- if (instance == null)
257
- {
258
- var result = new T();
259
- instance = result;
260
- }
256
+ instance ??= new T();
257
+
261
258
  string fileName = instance.GetType().Name;
262
259
  string json = GDKFileUtils.Load(fileName);
263
- JsonUtility.FromJsonOverwrite(json, instance);
260
+ if (!string.IsNullOrEmpty(json))
261
+ {
262
+ try
263
+ {
264
+ JsonUtility.FromJsonOverwrite(json, instance);
265
+ } catch (Exception e)
266
+ {
267
+ LogWarning("LoadJsonFromFile error: " + fileName + "\n" + e);
268
+ }
269
+ }
270
+
264
271
  return instance;
265
272
  }
266
273
 
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: cdfa0e7b648474e318ef91524d78c99a
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.amanotes.gdk",
3
- "version": "0.2.45",
3
+ "version": "0.2.46-2",
4
4
  "displayName": "AmaGDK",
5
5
  "description": "Amanotes Game Development Kit",
6
6
  "unity": "2019.4",