com.amanotes.gdk 0.1.13 → 0.1.16

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.16 - 2023-03-10]
4
+ ### Release AmaGDK v0.1.16
5
+ ### SemVer supports 4 parts
6
+ ### Analytics supports event config
7
+
8
+ ## [0.1.15 - 2023-03-06]
9
+ ### Release AmaGDK v0.1.15
10
+ ### Fix null exception in VersionExtractor
11
+ ### Warn unhandle platform in Appsflyer initialization
12
+ ### Allow dev to SetPermittedEvents and SetForbiddenEvents to the adapter config
13
+
14
+ ## [0.1.14 - 2023-03-02]
15
+ ### Release AmaGDK v0.1.14
16
+
3
17
  ## [0.1.13 - 2023-03-01]
4
18
  ### Release AmaGDK v0.1.13
5
19
  ### Fix Semver parser
@@ -185,7 +185,7 @@ namespace Amanotes.Editor
185
185
  DrawGUI_AutoInit();
186
186
  ToggleGroup("Config", ref showConfigDetail, DrawGUI_ConfigDetail, DrawGUI_ConfigAsset);
187
187
  ToggleGroup("Adapters", ref showAdapterInstaller, DrawGUI_AdapterList);
188
- ToggleGroup("Example", ref showExampleDetail, DrawGUI_ExampleScene);
188
+ //("Example", ref showExampleDetail, DrawGUI_ExampleScene);
189
189
  }
190
190
 
191
191
  private static void DrawVersion(string label, string version){
@@ -50,7 +50,7 @@ namespace Amanotes.Editor
50
50
  {
51
51
  public static string GDKAdapter(string sdkId)
52
52
  {
53
- string version = null;
53
+ string version = "";
54
54
  var adapterId = sdkId + "Adapter";
55
55
  // Debug.Log($"Searching for AdapterId: {adapterId}");
56
56
  List<Assembly> assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
@@ -73,12 +73,12 @@ namespace Amanotes.Editor
73
73
  }
74
74
  }
75
75
  }
76
- return version;
76
+ return version.Trim();
77
77
  }
78
78
 
79
79
  public static string ThirdParty(string sdkId)
80
80
  {
81
- string version = null;
81
+ string version = "";
82
82
  switch (sdkId)
83
83
  {
84
84
  case FIREBASE_ANALYTICS : return FirebaseAnalytics();
@@ -95,7 +95,7 @@ namespace Amanotes.Editor
95
95
 
96
96
  internal static string FirebaseAnalytics()
97
97
  {
98
- string version = null;
98
+ string version = "";
99
99
  string[] filesFirebase = Directory.GetFiles("Assets", "maven-metadata.xml", SearchOption.AllDirectories);
100
100
  if (filesFirebase != null && filesFirebase.Length > 0)
101
101
  {
@@ -116,12 +116,12 @@ namespace Amanotes.Editor
116
116
  }
117
117
  }
118
118
  }
119
- return version;
119
+ return version.Trim();
120
120
  }
121
121
 
122
122
  internal static string FirebaseRemoteConfig()
123
123
  {
124
- string version = null;
124
+ string version = "";
125
125
  string[] filesFirebase = Directory.GetFiles("Assets", "maven-metadata.xml", SearchOption.AllDirectories);
126
126
  if (filesFirebase != null && filesFirebase.Length > 0)
127
127
  {
@@ -142,12 +142,12 @@ namespace Amanotes.Editor
142
142
  }
143
143
  }
144
144
  }
145
- return version;
145
+ return version.Trim();
146
146
  }
147
147
 
148
148
  internal static string AppsFlyer()
149
149
  {
150
- string version = null;
150
+ string version = "";
151
151
  List<Assembly> assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
152
152
  if (assemblies != null)
153
153
  {
@@ -163,12 +163,12 @@ namespace Amanotes.Editor
163
163
  }
164
164
  }
165
165
 
166
- return version;
166
+ return version.Trim();
167
167
  }
168
168
 
169
169
  internal static string Ironsource()
170
170
  {
171
- string version = null;
171
+ string version = "";
172
172
  string[] issdk = Directory.GetFiles("Assets", "IronSourceSDKDependencies.xml", System.IO.SearchOption.AllDirectories);
173
173
  if (issdk != null && issdk.Length > 0)
174
174
  {
@@ -178,14 +178,14 @@ namespace Amanotes.Editor
178
178
  XmlNode dataVersion2 = root2.SelectSingleNode("unityversion");
179
179
  version = dataVersion2.InnerText;
180
180
  }
181
- return version;
181
+ return version.Trim();
182
182
  }
183
183
 
184
184
  internal static string RevenueCat()
185
185
  {
186
186
  string[] files = Directory.GetFiles("Assets", "PurchasesWrapper.java", SearchOption.AllDirectories);
187
187
  string searchString = "PLUGIN_VERSION";
188
- string version = null;
188
+ string version = "";
189
189
  if (files.Length < 1)
190
190
  {
191
191
  return version;
@@ -206,7 +206,7 @@ namespace Amanotes.Editor
206
206
  }
207
207
  }
208
208
  }
209
- return version;
209
+ return version.Trim();
210
210
  }
211
211
  }
212
212
  }
Binary file
Binary file
@@ -54,7 +54,7 @@ namespace Amanotes.Core
54
54
  get { return !string.IsNullOrEmpty(funnelSignature); }
55
55
  }
56
56
 
57
- public bool IsForbidden(string adapterId)
57
+ public bool IsForbiddenByAdapterConfig(string adapterId)
58
58
  {
59
59
  if (ignoreAdapterIds.Count > 0)
60
60
  {
@@ -69,10 +69,24 @@ namespace Amanotes.Core
69
69
  Debug.LogWarning("[AmaGDK] Should never be here: overrideConfig == true but no id in listAdapterIds!");
70
70
  return false;
71
71
  }
72
+
73
+ public bool IsForbiddenByLogAtCountConfig()
74
+ {
75
+ if (!logAtCount.TryGetValue(eventName, out var logAtCountConfig)) return false;
76
+
77
+ int accumulatedCount = GetAccumulatedCount(eventName, logAtCountConfig.withinSession);
78
+ return !logAtCountConfig.listCount.Contains(accumulatedCount);
79
+ }
72
80
  }
73
81
 
74
82
  public static IEventParamsBuilder LogEvent(string eventName)
75
83
  {
84
+ if (string.IsNullOrWhiteSpace(eventName))
85
+ {
86
+ LogWarningOnce($"Invalid EventName: <{eventName}> ");
87
+ return null;
88
+ }
89
+
76
90
  var result = new EventParams(eventName);
77
91
  eventQueue.Enqueue(result);
78
92
  return result;
@@ -80,20 +94,16 @@ namespace Amanotes.Core
80
94
 
81
95
  public static IEventParamsBuilder LogEvent(string eventName, Dictionary<string, object> parameters)
82
96
  {
83
- var result = new EventParams(eventName);
84
- result.AddParam(parameters);
85
- eventQueue.Enqueue(result);
86
- return result;
97
+ return LogEvent(eventName).AddParam(parameters);
87
98
  }
88
99
 
89
100
  public static IEventParamsBuilder LogEvent(string eventName, params (string, object)[] parameters)
90
101
  {
91
- var result = new EventParams(eventName);
102
+ var result = LogEvent(eventName);
92
103
  for (var i = 0;i < parameters.Length; i++)
93
104
  {
94
105
  result.AddParam(parameters[i].Item1, parameters[i].Item2);
95
- }
96
- eventQueue.Enqueue(result);
106
+ }
97
107
  return result;
98
108
  }
99
109
 
@@ -215,11 +225,59 @@ namespace Amanotes.Core
215
225
 
216
226
  localData.UpdateMigrationLog();
217
227
  }
228
+
229
+ public static void SetPermittedEvents(List<string> eventNames, params string[] adapterIDs)
230
+ {
231
+ foreach (var adapterID in adapterIDs)
232
+ {
233
+ var adapter = listAdapters.Find(a => a.id == adapterID)?.GetAdapterApi<IAnalyticAdapter>();
234
+ adapter?.SetPermittedEvents(eventNames);
235
+ }
236
+ }
237
+
238
+ public static void SetForbiddenEvents(List<string> eventNames, params string[] adapterIDs)
239
+ {
240
+ foreach (var adapterID in adapterIDs)
241
+ {
242
+ var adapter = listAdapters.Find(a => a.id == adapterID)?.GetAdapterApi<IAnalyticAdapter>();
243
+ adapter?.SetForbiddenEvents(eventNames);
244
+ }
245
+ }
246
+
247
+ public static void SetLogAtCount(string eventName, List<int> listCount, bool withinSession = false, bool appendCountToEventName = false, string numberFormat = "00")
248
+ {
249
+ var config = new EventConfig
250
+ {
251
+ listCount = listCount,
252
+ withinSession = withinSession,
253
+ appendCountToEventName = appendCountToEventName,
254
+ numberFormat = numberFormat
255
+ };
256
+
257
+ if (logAtCount.ContainsKey(eventName))
258
+ {
259
+ LogWarning($"{eventName} has already been set list of count number to log.");
260
+ logAtCount[eventName] = config;
261
+ }
262
+ else
263
+ {
264
+ logAtCount.Add(eventName, config);
265
+ }
266
+ }
218
267
  }
219
268
 
220
269
  //INTERNAL
221
270
  public static partial class Analytics
222
271
  {
272
+ internal class EventConfig
273
+ {
274
+ public List<int> listCount;
275
+ public bool withinSession;
276
+ public bool appendCountToEventName;
277
+ public string numberFormat;
278
+ }
279
+
280
+ internal static readonly Dictionary<string, EventConfig> logAtCount = new Dictionary<string, EventConfig>();
223
281
  internal static Predicate<EventDetail> logEventHook = null;
224
282
  internal static readonly Queue<EventParams> eventQueue = new Queue<EventParams>();
225
283
  internal static readonly List<AdapterInfo> listAdapters = new List<AdapterInfo>();
@@ -242,10 +300,6 @@ namespace Amanotes.Core
242
300
  while (eventQueue.Count > 0)
243
301
  {
244
302
  var eventData = eventQueue.Dequeue();
245
-
246
- if (!NormalizeEventName(ref eventData.eventName))
247
- continue;
248
-
249
303
  var (countInSession, totalCount) = localData.IncreaseCounter(eventData.eventName);
250
304
 
251
305
  if (!ShouldSendEvent(eventData))
@@ -256,24 +310,29 @@ namespace Amanotes.Core
256
310
  eventData.AddParam("accumulated_count", eventData.withinSession ? countInSession : totalCount);
257
311
  }
258
312
 
259
- if (showAnalyticsLog) Debug.Log($"[AmaGDK] Event <{eventData.eventName}> (in session: {countInSession}, total: {totalCount})");
313
+ var eventNameToSend = GetEventNameToSend(eventData.eventName, countInSession, totalCount);
314
+ NormalizeEventName(ref eventNameToSend);
315
+
316
+ if (showAnalyticsLog) Debug.Log($"[AmaGDK] Event <{eventNameToSend}> (in session: {countInSession}, total: {totalCount})");
260
317
  foreach (var m in listAdapters)
261
318
  {
262
- m.GetAdapterApi<IAnalyticAdapter>().LogEvent(eventData);
319
+ m.GetAdapterApi<IAnalyticAdapter>().LogEvent(eventNameToSend, eventData);
263
320
  }
264
321
  }
265
322
 
266
323
  localData.SaveIfDirty();
267
324
  }
268
325
 
269
- internal static bool NormalizeEventName(ref string eventName)
326
+ internal static string GetEventNameToSend(string eventName, int countInSession, int totalCount)
270
327
  {
271
- if (string.IsNullOrWhiteSpace(eventName))
272
- {
273
- LogWarningOnce($"Invalid EventName: <{eventName}> ");
274
- return false;
275
- }
328
+ if (!logAtCount.TryGetValue(eventName, out var config)) return eventName;
329
+ if (!config.appendCountToEventName) return eventName;
276
330
 
331
+ return $"{eventName}_{(config.withinSession ? countInSession : totalCount).ToString(config.numberFormat)}";
332
+ }
333
+
334
+ internal static bool NormalizeEventName(ref string eventName)
335
+ {
277
336
  var sb = tmpWarningSB;
278
337
  sb.Clear();
279
338
 
@@ -307,10 +366,20 @@ namespace Amanotes.Core
307
366
  return localData.AddFunnelSignature(eventData.funnelSignature);
308
367
  }
309
368
 
369
+ //Check predefined event count config
370
+ if (eventData.IsForbiddenByLogAtCountConfig())
371
+ {
372
+ return false;
373
+ }
374
+
310
375
  //Check the rule to log event
311
- if (logEventHook == null) return true;
312
- var eventDetail = localData.GetEventDetail(eventData.eventName, true);
313
- return logEventHook(eventDetail);
376
+ if (logEventHook != null)
377
+ {
378
+ var eventDetail = localData.GetEventDetail(eventData.eventName, true);
379
+ return logEventHook(eventDetail);
380
+ }
381
+
382
+ return true;
314
383
  }
315
384
  }
316
385
 
@@ -566,7 +635,7 @@ namespace Amanotes.Core
566
635
  }
567
636
 
568
637
  return true;
569
- }
638
+ }
570
639
 
571
640
  }
572
641
  }
@@ -582,10 +651,14 @@ namespace Amanotes.Core.Internal
582
651
 
583
652
  public interface IAnalyticAdapter
584
653
  {
585
- void LogEvent(EventParams eventData);
654
+ void LogEvent(string eventNameToSend, EventParams eventData);
586
655
 
587
656
  void SetUserId(string userId);
588
657
 
589
658
  void SetUserProperty(string key, string value);
659
+
660
+ void SetPermittedEvents(List<string> eventNames);
661
+
662
+ void SetForbiddenEvents(List<string> eventNames);
590
663
  }
591
664
  }
@@ -12,12 +12,14 @@ namespace Amanotes.Core.Internal
12
12
  public int major;
13
13
  public int minor;
14
14
  public int patch;
15
+ public int extra;
15
16
 
16
- public SemVer(int major, int minor, int patch)
17
+ public SemVer(int major, int minor, int patch, int extra = -1)
17
18
  {
18
19
  this.major = major;
19
20
  this.minor = minor;
20
21
  this.patch = patch;
22
+ this.extra = extra;
21
23
  }
22
24
 
23
25
  public SemVer(string version)
@@ -25,6 +27,7 @@ namespace Amanotes.Core.Internal
25
27
  major = 0;
26
28
  minor = 0;
27
29
  patch = 0;
30
+ extra = -1;
28
31
 
29
32
  if (string.IsNullOrEmpty(version))
30
33
  {
@@ -33,7 +36,7 @@ namespace Amanotes.Core.Internal
33
36
 
34
37
  version = version.Trim();
35
38
 
36
- Regex regex = new Regex(@"^(\d+)\.(\d+)\.(\d+)$");
39
+ Regex regex = new Regex(@"^(\d+)\.(\d+)\.(\d+)(?:\.(\d+))?$");
37
40
  Match match = regex.Match(version);
38
41
  if (!match.Success)
39
42
  {
@@ -43,6 +46,12 @@ namespace Amanotes.Core.Internal
43
46
  major = int.Parse(match.Groups[1].Value);
44
47
  minor = int.Parse(match.Groups[2].Value);
45
48
  patch = int.Parse(match.Groups[3].Value);
49
+ if (match.Groups.Count > 3)
50
+ {
51
+ if (!int.TryParse(match.Groups[4].Value, out extra))
52
+ extra = -1;
53
+ }
54
+
46
55
  }
47
56
 
48
57
  public bool isValid { get { return this != ZERO; } }
@@ -50,6 +59,7 @@ namespace Amanotes.Core.Internal
50
59
  public override string ToString()
51
60
  {
52
61
  if (this == ZERO) return "-";
62
+ if (extra != -1) return $"{major}.{minor}.{patch}.{extra}";
53
63
  return $"{major}.{minor}.{patch}";
54
64
  }
55
65
 
@@ -67,6 +77,10 @@ namespace Amanotes.Core.Internal
67
77
  {
68
78
  return patch.CompareTo(other.patch);
69
79
  }
80
+ if (extra != other.extra)
81
+ {
82
+ return extra.CompareTo(other.extra);
83
+ }
70
84
  return 0;
71
85
  }
72
86
 
@@ -82,7 +96,7 @@ namespace Amanotes.Core.Internal
82
96
  return false;
83
97
  }
84
98
  SemVer other = (SemVer)obj;
85
- return major == other.major && minor == other.minor && patch == other.patch;
99
+ return major == other.major && minor == other.minor && patch == other.patch && extra == other.extra;
86
100
  }
87
101
 
88
102
  public static bool operator >(SemVer x, SemVer y)
@@ -117,7 +131,7 @@ namespace Amanotes.Core.Internal
117
131
 
118
132
  public override int GetHashCode()
119
133
  {
120
- return (major << 16) | (minor << 8) | patch;
134
+ return (major << 24) | (minor << 16) | (patch << 8) | extra;
121
135
  }
122
136
  }
123
137
  }
@@ -1,4 +1,5 @@
1
1
  using System;
2
+ using System.Collections.Generic;
2
3
  using System.IO;
3
4
  using UnityEngine;
4
5
 
@@ -75,7 +76,7 @@ namespace Amanotes.Core.Internal
75
76
  catch (Exception ex)
76
77
  {
77
78
  LogWarningOnce(path + "\n" + ex);
78
- }
79
+ }
79
80
  }
80
81
 
81
82
  private static string _basePath;
@@ -92,7 +93,73 @@ namespace Amanotes.Core.Internal
92
93
  return _basePath;
93
94
  }
94
95
  }
95
- }
96
+ }
97
+
98
+ public class ActionQueue
99
+ {
100
+ private Queue<Action<Action>> queue;
101
+ private bool isProcessing = false;
102
+ private Action onComplete;
103
+
104
+ public ActionQueue(Action onComplete)
105
+ {
106
+ queue = new Queue<Action<Action>>();
107
+ this.onComplete = onComplete;
108
+ }
109
+
110
+ public void EnqueueAction(params Action<Action>[] actions)
111
+ {
112
+ if (isProcessing)
113
+ {
114
+ LogWarning("queue is processing!");
115
+ return;
116
+ }
117
+
118
+ foreach (var action in actions)
119
+ {
120
+ if (action == null)
121
+ {
122
+ LogWarning("action is null!");
123
+ continue;
124
+ }
125
+ queue.Enqueue(action);
126
+ }
127
+
128
+ ProcessQueue();
129
+ }
130
+
131
+ private void ProcessQueue()
132
+ {
133
+ if (isProcessing)
134
+ return;
135
+ if (queue.Count == 0)
136
+ {
137
+ onComplete?.Invoke();
138
+ return;
139
+ }
140
+
141
+ Action<Action> nextAction = null;
142
+ while (queue.Count > 0)
143
+ {
144
+ nextAction = queue.Dequeue();
145
+ if (nextAction != null)
146
+ {
147
+ isProcessing = true;
148
+ nextAction.Invoke(ActionCompleted);
149
+ return;
150
+ }
151
+ }
152
+
153
+ if(nextAction == null)
154
+ onComplete?.Invoke();
155
+ }
156
+
157
+ private void ActionCompleted()
158
+ {
159
+ isProcessing = false;
160
+ ProcessQueue();
161
+ }
162
+ }
96
163
 
97
164
  internal interface IJsonFile { }
98
165
 
@@ -0,0 +1,43 @@
1
+ using System.Collections;
2
+ using UnityEngine.Networking;
3
+ using System;
4
+ using System.Collections.Generic;
5
+ using static Amanotes.Core.Internal.Logging;
6
+
7
+ namespace Amanotes.Core.Internal
8
+ {
9
+ internal class WebUtils
10
+ {
11
+ public static void PostJson(string url, string jsonData, Action<bool, string> onComplete = null, Dictionary<string, string> headers = null)
12
+ {
13
+ AmaGDK._instance.StartCoroutine(PostJsonCoroutine(url, jsonData, onComplete, headers));
14
+ }
15
+
16
+ static IEnumerator PostJsonCoroutine(string url, string jsonData, Action<bool, string> onComplete = null, Dictionary<string, string> headers = null)
17
+ {
18
+ UnityWebRequest webRequest = new UnityWebRequest(url, "POST");
19
+ if (headers != null)
20
+ {
21
+ foreach (KeyValuePair<string, string> kvp in headers)
22
+ {
23
+ webRequest.SetRequestHeader(kvp.Key, kvp.Value);
24
+ }
25
+ }
26
+
27
+ byte[] bodyRaw = System.Text.Encoding.UTF8.GetBytes(jsonData);
28
+ webRequest.uploadHandler = new UploadHandlerRaw(bodyRaw);
29
+ webRequest.downloadHandler = new DownloadHandlerBuffer();
30
+ yield return webRequest.SendWebRequest();
31
+
32
+ if (webRequest.result != UnityWebRequest.Result.Success)
33
+ {
34
+ LogWarning("POST request failed: " + webRequest.error);
35
+ onComplete?.Invoke(false, webRequest.error);
36
+ }
37
+ else
38
+ {
39
+ onComplete?.Invoke(true, webRequest.downloadHandler.text);
40
+ }
41
+ }
42
+ }
43
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: fe77d47845d9e4132b8837f07079a6dd
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
package/Runtime/AmaGDK.cs CHANGED
@@ -12,7 +12,7 @@ namespace Amanotes.Core
12
12
  {
13
13
  public partial class AmaGDK : MonoBehaviour
14
14
  {
15
- public const string VERSION = "0.1.13";
15
+ public const string VERSION = "0.1.16";
16
16
 
17
17
  internal static AmaGDK _instance;
18
18
  internal static event Action _frameUpdate;
@@ -100,7 +100,7 @@ namespace Amanotes.Core
100
100
 
101
101
  // Init modules (Adapter managers)
102
102
  Analytics.Init();
103
- Ads.Init();
103
+ //Ads.Init();
104
104
 
105
105
  _status = Status.Ready;
106
106
  _onReadyCallback?.Invoke();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.amanotes.gdk",
3
- "version": "0.1.13",
3
+ "version": "0.1.16",
4
4
  "displayName": "AmaGDK",
5
5
  "description": "Amanotes Game Development Kit",
6
6
  "unity": "2020.3",