com.amanotes.gdk 0.2.46 → 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.
- package/CHANGELOG.md +4 -0
- package/Editor/AmaGDKEditor.cs +281 -104
- package/Editor/MatchSDKVersion.cs +3 -6
- package/Editor/Utils/AmaGDKEditor.ExtractVersion.cs +5 -1
- package/Extra/AmaGDKInstaller.unitypackage +0 -0
- package/Extra/AmaGDKProject.unitypackage +0 -0
- package/Packages/AmaGDKConfig.unitypackage +0 -0
- package/Packages/AmaGDKExample.unitypackage +0 -0
- package/Packages/AmaGDKTest.unitypackage +0 -0
- package/Packages/AppsFlyerAdapter.unitypackage +0 -0
- package/Packages/{FirebaseRemoteConfigAdapter_v9.1.0.unitypackage.meta → AppsFlyerAdapter.unitypackage.meta} +1 -1
- package/Packages/FirebaseAnalyticsAdapter.unitypackage +0 -0
- package/Packages/{AppsFlyerAdapter_v6.5.4.unitypackage.meta → FirebaseAnalyticsAdapter.unitypackage.meta} +1 -1
- package/Packages/FirebaseRemoteConfigAdapter.unitypackage +0 -0
- package/Packages/{IronSourceAdapter_v7.5.2.unitypackage.meta → FirebaseRemoteConfigAdapter.unitypackage.meta} +1 -1
- package/Packages/IronSourceAdapter.unitypackage +0 -0
- package/Packages/{FirebaseAnalyticsAdapter_v9.1.0.unitypackage.meta → IronSourceAdapter.unitypackage.meta} +1 -1
- package/Packages/RevenueCatAdapter.unitypackage +0 -0
- package/Packages/RevenueCatAdapter.unitypackage.meta +7 -0
- package/Runtime/AmaGDK.Adapters.cs +55 -77
- package/Runtime/AmaGDK.Ads.cs +160 -174
- package/Runtime/AmaGDK.Analytics.cs +245 -125
- package/Runtime/AmaGDK.Config.cs +2 -1
- package/Runtime/AmaGDK.IAP.cs +47 -48
- package/Runtime/AmaGDK.RemoteConfig.cs +38 -35
- package/Runtime/AmaGDK.UserProfile.cs +27 -19
- package/Runtime/AmaGDK.cs +158 -111
- package/Runtime/Core.meta +8 -0
- package/Runtime/Internal/AmaGDK.Internal.AmaGUI.cs +8 -3
- package/Runtime/Internal/AmaGDK.Internal.SemVer.cs +21 -17
- package/Runtime/Internal/AmaGDK.Internal.cs +17 -6
- package/Runtime/Internal/AmaGDK.Utils.cs +78 -11
- package/package.json +1 -1
- package/Packages/AppsFlyerAdapter_v6.5.4.unitypackage +0 -0
- package/Packages/FirebaseAnalyticsAdapter_v9.1.0.unitypackage +0 -0
- package/Packages/FirebaseRemoteConfigAdapter_v9.1.0.unitypackage +0 -0
- package/Packages/IronSourceAdapter_v7.5.2.unitypackage +0 -0
- package/Packages/IronsourceAdapter_v7.2.6.unitypackage +0 -0
- package/Packages/IronsourceAdapter_v7.2.6.unitypackage.meta +0 -7
- package/Packages/RevenueCatAdapter_v6.0.0.unitypackage +0 -0
- package/Packages/RevenueCatAdapter_v6.0.0.unitypackage.meta +0 -7
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.
|
|
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<
|
|
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
|
|
61
|
+
IEnumerator InitHook()
|
|
63
62
|
{
|
|
64
|
-
|
|
63
|
+
int nHooks = Hook.hooks.Count;
|
|
64
|
+
if (nHooks == 0)
|
|
65
65
|
{
|
|
66
|
-
|
|
66
|
+
Log($"[Hook] No hook registered!");
|
|
67
|
+
yield break;
|
|
67
68
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
float
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
114
|
+
void StartModules()
|
|
115
|
+
{
|
|
116
|
+
Profiler.BeginSample("AmaGDK.StartModules()");
|
|
96
117
|
{
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
118
|
+
User.StartModule();
|
|
119
|
+
Analytics.StartModule();
|
|
120
|
+
Ads.StartModule();
|
|
121
|
+
IAP.StartModule();
|
|
122
|
+
}
|
|
123
|
+
Profiler.EndSample();
|
|
124
|
+
}
|
|
102
125
|
|
|
103
|
-
|
|
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
|
-
|
|
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
|
-
|
|
146
|
+
yield return GDKUtils.Timeout(TIMEOUT,() => adapter.status != Status.Initialize);
|
|
147
|
+
|
|
148
|
+
if (adapter.status == Status.Initialize)
|
|
113
149
|
{
|
|
114
|
-
|
|
150
|
+
LogWarning($"{adapter.adapterId} init time out: {TIMEOUT}");
|
|
115
151
|
}
|
|
116
152
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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
|
-
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
IEnumerator InitRoutine()
|
|
141
164
|
{
|
|
142
|
-
|
|
165
|
+
if (Config == null)
|
|
143
166
|
{
|
|
144
|
-
|
|
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<
|
|
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
|
-
|
|
369
|
+
public partial class AmaGDK // Switch dev mode
|
|
370
|
+
{
|
|
371
|
+
public static class Hook
|
|
376
372
|
{
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
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
|
}
|
|
@@ -149,10 +149,10 @@ namespace Amanotes.Core.Internal
|
|
|
149
149
|
return true;
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
public static bool Foldout(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)
|
|
153
153
|
{
|
|
154
154
|
GUILayout.BeginHorizontal();
|
|
155
|
-
bool newValue = EditorGUILayout.Foldout(isOpen, label);
|
|
155
|
+
bool newValue = EditorGUILayout.Foldout(isOpen, label, EditorStyles.foldoutHeader);
|
|
156
156
|
bool changed = newValue != isOpen;
|
|
157
157
|
titleFunc?.Invoke();
|
|
158
158
|
GUILayout.EndHorizontal();
|
|
@@ -195,8 +195,13 @@ namespace Amanotes.Core.Internal
|
|
|
195
195
|
|
|
196
196
|
public static void DrawVersionTag(SemVer version, bool? isValid = null)
|
|
197
197
|
{
|
|
198
|
-
isValid ??= version.isValid;
|
|
199
198
|
Rect rect = GUILayoutUtility.GetRect(60f, 60f, 18f, 18f);
|
|
199
|
+
DrawVersionTag(rect, version, isValid);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
public static void DrawVersionTag(Rect rect, SemVer version, bool? isValid = null)
|
|
203
|
+
{
|
|
204
|
+
isValid ??= version.isValid;
|
|
200
205
|
DrawTag(rect, version.ToString(), isValid.Value ? LIGHT_BLUE : LIGHT_GRAY, 0.5f);
|
|
201
206
|
}
|
|
202
207
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
using System;
|
|
2
2
|
using System.Collections.Generic;
|
|
3
3
|
using System.Text.RegularExpressions;
|
|
4
|
+
using UnityEngine.Profiling;
|
|
4
5
|
using static Amanotes.Core.Internal.Logging;
|
|
5
6
|
|
|
6
7
|
namespace Amanotes.Core.Internal
|
|
@@ -8,6 +9,7 @@ namespace Amanotes.Core.Internal
|
|
|
8
9
|
public struct SemVer : IComparable<SemVer>, IComparer<SemVer>
|
|
9
10
|
{
|
|
10
11
|
public static readonly SemVer ZERO = new SemVer(0, 0, 0);
|
|
12
|
+
private static readonly Regex VERSION_PATTERN = new Regex(@"^(\d+)\.(\d+)\.(\d+)(?:\.(\d+))?$");
|
|
11
13
|
|
|
12
14
|
public int major;
|
|
13
15
|
public int minor;
|
|
@@ -30,25 +32,27 @@ namespace Amanotes.Core.Internal
|
|
|
30
32
|
extra = -1;
|
|
31
33
|
|
|
32
34
|
if (string.IsNullOrEmpty(version)) return;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var regex = new Regex(@"^(\d+)\.(\d+)\.(\d+)(?:\.(\d+))?$");
|
|
37
|
-
Match match = regex.Match(version);
|
|
38
|
-
if (!match.Success)
|
|
35
|
+
|
|
36
|
+
Profiler.BeginSample("AmaGDK.SemVer()");
|
|
39
37
|
{
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
version = version.Trim();
|
|
39
|
+
Match match = VERSION_PATTERN.Match(version);
|
|
40
|
+
if (!match.Success)
|
|
41
|
+
{
|
|
42
|
+
LogWarning($"Invalid SemVer string: [{version}]");
|
|
43
|
+
Profiler.EndSample();
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
major = int.Parse(match.Groups[1].Value);
|
|
47
|
+
minor = int.Parse(match.Groups[2].Value);
|
|
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
|
+
}
|
|
42
54
|
}
|
|
43
|
-
|
|
44
|
-
minor = int.Parse(match.Groups[2].Value);
|
|
45
|
-
patch = int.Parse(match.Groups[3].Value);
|
|
46
|
-
if (match.Groups.Count > 3)
|
|
47
|
-
{
|
|
48
|
-
if (!int.TryParse(match.Groups[4].Value, out extra))
|
|
49
|
-
extra = -1;
|
|
50
|
-
}
|
|
51
|
-
|
|
55
|
+
Profiler.EndSample();
|
|
52
56
|
}
|
|
53
57
|
|
|
54
58
|
public bool isValid => this != ZERO;
|
|
@@ -22,7 +22,7 @@ namespace Amanotes.Core.Internal
|
|
|
22
22
|
|
|
23
23
|
public static class Messsage
|
|
24
24
|
{
|
|
25
|
-
public const string READY = "
|
|
25
|
+
public const string READY = "Init success";
|
|
26
26
|
public const string SDK_INIT_CALLED = "init has been called!";
|
|
27
27
|
public const string MULTIPLE_INSTANCE = "multiple instance found!";
|
|
28
28
|
public const string CONFIG_NOT_FOUND = "AmaGDKConfig not found in Resources!";
|
|
@@ -52,11 +52,11 @@ namespace Amanotes.Core.Internal
|
|
|
52
52
|
return;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
GameObject go = UnityObject.Instantiate(prefab);
|
|
56
|
+
go.name = "AmaGDK";
|
|
57
|
+
go.transform.SetAsLastSibling();
|
|
58
58
|
Selection.activeObject = null;
|
|
59
|
-
Selection.activeObject =
|
|
59
|
+
Selection.activeObject = go;
|
|
60
60
|
}
|
|
61
61
|
#endif
|
|
62
62
|
}
|
|
@@ -113,7 +113,18 @@ namespace Amanotes.Core.Internal
|
|
|
113
113
|
// Logging.LogWarning("Something wrong: another AmaGDK instance found!");
|
|
114
114
|
UnityObject.Destroy(result[i].gameObject);
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
|
|
117
|
+
// Reset all adapter status
|
|
118
|
+
var allAdapters = Adapter2.GetAllAdapter<Adapter2>();
|
|
119
|
+
foreach (var adapter in allAdapters)
|
|
120
|
+
{
|
|
121
|
+
adapter.status = Status.None;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Reset all modules
|
|
125
|
+
Ads.context = null;
|
|
126
|
+
Ads._adapter = null;
|
|
127
|
+
|
|
117
128
|
_status = Status.None;
|
|
118
129
|
_allowInit = false;
|
|
119
130
|
|
|
@@ -2,9 +2,11 @@ using System;
|
|
|
2
2
|
using System.Collections;
|
|
3
3
|
using System.Collections.Generic;
|
|
4
4
|
using System.IO;
|
|
5
|
+
using System.Reflection;
|
|
5
6
|
using System.Text;
|
|
6
7
|
using System.Text.RegularExpressions;
|
|
7
8
|
using UnityEngine;
|
|
9
|
+
using UnityEngine.Profiling;
|
|
8
10
|
using static Amanotes.Core.Internal.Logging;
|
|
9
11
|
|
|
10
12
|
namespace Amanotes.Core.Internal
|
|
@@ -15,12 +17,75 @@ namespace Amanotes.Core.Internal
|
|
|
15
17
|
{
|
|
16
18
|
AmaGDK._instance.StartCoroutine(DelayCallRoutine(seconds, action));
|
|
17
19
|
}
|
|
20
|
+
|
|
21
|
+
public static void RegisterUnityCallbacks<T>(T target)
|
|
22
|
+
{
|
|
23
|
+
if (target == null)
|
|
24
|
+
{
|
|
25
|
+
LogWarning("RegisterUnityCallbacks: Target is null!");
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (target is IOnFrameUpdate u)
|
|
30
|
+
{
|
|
31
|
+
AmaGDK.onFrameUpdate -= u.OnFrameUpdate;
|
|
32
|
+
AmaGDK.onFrameUpdate += u.OnFrameUpdate;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (target is IOnApplicationPause p)
|
|
36
|
+
{
|
|
37
|
+
AmaGDK.onApplicationPause -= p.OnApplicationPause;
|
|
38
|
+
AmaGDK.onApplicationPause += p.OnApplicationPause;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (target is IOnApplicationFocus f)
|
|
42
|
+
{
|
|
43
|
+
AmaGDK.applicationFocus -= f.OnApplicationFocus;
|
|
44
|
+
AmaGDK.applicationFocus += f.OnApplicationFocus;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (target is IOnApplicationQuit q)
|
|
48
|
+
{
|
|
49
|
+
AmaGDK.applicationQuit -= q.OnApplicationQuit;
|
|
50
|
+
AmaGDK.applicationQuit += q.OnApplicationQuit;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
18
53
|
|
|
19
54
|
private static IEnumerator DelayCallRoutine(float seconds, Action callback)
|
|
20
55
|
{
|
|
21
56
|
yield return new WaitForSecondsRealtime(seconds);
|
|
22
57
|
callback();
|
|
23
58
|
}
|
|
59
|
+
|
|
60
|
+
public static IEnumerator Timeout(float timeoutInSecs, Func<bool> completeCheckFunc)
|
|
61
|
+
{
|
|
62
|
+
float time = Time.realtimeSinceStartup;
|
|
63
|
+
while (completeCheckFunc() == false)
|
|
64
|
+
{
|
|
65
|
+
yield return null;
|
|
66
|
+
if (Time.realtimeSinceStartup - time > timeoutInSecs) yield break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
public static class GDKReflection
|
|
72
|
+
{
|
|
73
|
+
internal static readonly BindingFlags FLAGS = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;
|
|
74
|
+
public static T GetFieldValue<T>(this object source, string fieldName, BindingFlags? flags = null)
|
|
75
|
+
{
|
|
76
|
+
if (source == null) return default(T);
|
|
77
|
+
Type sourceType = source.GetType();
|
|
78
|
+
FieldInfo field = sourceType.GetField(fieldName, flags ?? FLAGS);
|
|
79
|
+
|
|
80
|
+
if (field == null)
|
|
81
|
+
{
|
|
82
|
+
LogWarning($"fieldName <{fieldName}> not found in {sourceType}?");
|
|
83
|
+
return default(T);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return (T)field.GetValue(source);
|
|
87
|
+
}
|
|
88
|
+
|
|
24
89
|
}
|
|
25
90
|
|
|
26
91
|
internal static class GDKFileUtils
|
|
@@ -165,12 +230,12 @@ namespace Amanotes.Core.Internal
|
|
|
165
230
|
|
|
166
231
|
internal static void ClearCacheData()
|
|
167
232
|
{
|
|
168
|
-
|
|
169
|
-
|
|
233
|
+
var sb = new StringBuilder();
|
|
234
|
+
sb.AppendLine("[AmaGDK] All cached data & stats cleared");
|
|
170
235
|
|
|
171
236
|
if (!Directory.Exists(basePath))
|
|
172
237
|
{
|
|
173
|
-
|
|
238
|
+
sb.AppendLine("Cache path not exists: " + basePath);
|
|
174
239
|
return;
|
|
175
240
|
}
|
|
176
241
|
|
|
@@ -178,9 +243,9 @@ namespace Amanotes.Core.Internal
|
|
|
178
243
|
foreach (string path in filePaths)
|
|
179
244
|
{
|
|
180
245
|
Delete(path);
|
|
181
|
-
|
|
246
|
+
sb.AppendLine($"[deleted] - {path}");
|
|
182
247
|
}
|
|
183
|
-
Debug.Log(
|
|
248
|
+
Debug.Log(sb);
|
|
184
249
|
}
|
|
185
250
|
}
|
|
186
251
|
|
|
@@ -300,7 +365,8 @@ namespace Amanotes.Core.Internal
|
|
|
300
365
|
public static string DictionaryToJson(IDictionary inputDict, bool format = false, bool checkJsonInString = true)
|
|
301
366
|
{
|
|
302
367
|
if (inputDict == null) return "{}";
|
|
303
|
-
|
|
368
|
+
|
|
369
|
+
Profiler.BeginSample("AmaGDK.JsonUtils.DictionaryToJson()");
|
|
304
370
|
var jsonSb = new StringBuilder();
|
|
305
371
|
jsonSb.Append("{");
|
|
306
372
|
var isFirstElement = true;
|
|
@@ -318,12 +384,13 @@ namespace Amanotes.Core.Internal
|
|
|
318
384
|
|
|
319
385
|
jsonSb.AppendFormat("{0}\"{1}\":", format ? "\n" : "", key);
|
|
320
386
|
AppendJsonValue(ref jsonSb, key, value, format, checkJsonInString);
|
|
321
|
-
|
|
322
387
|
}
|
|
323
388
|
|
|
324
389
|
jsonSb.AppendFormat("{0}{1}", format ? "\n" : "", "}");
|
|
325
|
-
|
|
326
|
-
|
|
390
|
+
var result = jsonSb.ToString();
|
|
391
|
+
Profiler.EndSample();
|
|
392
|
+
|
|
393
|
+
return result;
|
|
327
394
|
}
|
|
328
395
|
|
|
329
396
|
private static void GetJsonIListValue(ref StringBuilder jsonSb, string key, IList list, bool format)
|
|
@@ -403,8 +470,8 @@ namespace Amanotes.Core.Internal
|
|
|
403
470
|
|
|
404
471
|
private static string EscapeJsonString(string input)
|
|
405
472
|
{
|
|
406
|
-
//Match any occurrence of a backslash(\)
|
|
407
|
-
string pattern = "[\\\
|
|
473
|
+
//Match any occurrence of a backslash(\) and double quotation (")
|
|
474
|
+
string pattern = "[\\\"]";
|
|
408
475
|
return Regex.Replace(input, pattern, match => $"\\{match.Value}");
|
|
409
476
|
}
|
|
410
477
|
|
package/package.json
CHANGED
|
Binary file
|