com.amanotes.gdk 0.1.3

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 (64) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/CHANGELOG.md.meta +7 -0
  3. package/Editor/AmaGDK.Editor.asmdef +18 -0
  4. package/Editor/AmaGDK.Editor.asmdef.meta +7 -0
  5. package/Editor/AmaGDKEditor.cs +210 -0
  6. package/Editor/AmaGDKEditor.cs.meta +11 -0
  7. package/Editor.meta +8 -0
  8. package/LICENSE.md +7 -0
  9. package/LICENSE.md.meta +7 -0
  10. package/Packages/AmaGDKConfig.unitypackage +0 -0
  11. package/Packages/AmaGDKConfig.unitypackage.meta +8 -0
  12. package/Packages/AppsflyerAdapter_v6.5.4.unitypackage +0 -0
  13. package/Packages/AppsflyerAdapter_v6.5.4.unitypackage.meta +7 -0
  14. package/Packages/FirebaseAnalyticsAdapter_v9.1.0.unitypackage +0 -0
  15. package/Packages/FirebaseAnalyticsAdapter_v9.1.0.unitypackage.meta +7 -0
  16. package/Packages.meta +8 -0
  17. package/README.md +44 -0
  18. package/README.md.meta +7 -0
  19. package/Runtime/AmaGDK.Adapters.cs +45 -0
  20. package/Runtime/AmaGDK.Adapters.cs.meta +11 -0
  21. package/Runtime/AmaGDK.Analytics.cs +454 -0
  22. package/Runtime/AmaGDK.Analytics.cs.meta +11 -0
  23. package/Runtime/AmaGDK.Config.cs +13 -0
  24. package/Runtime/AmaGDK.Config.cs.meta +11 -0
  25. package/Runtime/AmaGDK.Internal.cs +133 -0
  26. package/Runtime/AmaGDK.Internal.cs.meta +11 -0
  27. package/Runtime/AmaGDK.UserProfile.cs +41 -0
  28. package/Runtime/AmaGDK.UserProfile.cs.meta +11 -0
  29. package/Runtime/AmaGDK.Utils.cs +121 -0
  30. package/Runtime/AmaGDK.Utils.cs.meta +11 -0
  31. package/Runtime/AmaGDK.asmdef +14 -0
  32. package/Runtime/AmaGDK.asmdef.meta +7 -0
  33. package/Runtime/AmaGDK.cs +159 -0
  34. package/Runtime/AmaGDK.cs.meta +11 -0
  35. package/Runtime/AmaGDK.prefab +46 -0
  36. package/Runtime/AmaGDK.prefab.meta +8 -0
  37. package/Runtime/AssemblyInfo.cs +8 -0
  38. package/Runtime/AssemblyInfo.cs.meta +11 -0
  39. package/Runtime/Interfaces/Analytics/IAnalytics.cs +6 -0
  40. package/Runtime/Interfaces/Analytics/IAnalytics.cs.meta +11 -0
  41. package/Runtime/Interfaces/Analytics.meta +8 -0
  42. package/Runtime/Interfaces.meta +8 -0
  43. package/Runtime.meta +8 -0
  44. package/Tests/Editor/AmaGDK.Editor.Test.asmdef +23 -0
  45. package/Tests/Editor/AmaGDK.Editor.Test.asmdef.meta +7 -0
  46. package/Tests/Editor.meta +8 -0
  47. package/Tests/Runtime/AmaGDK.Test.asmdef +20 -0
  48. package/Tests/Runtime/AmaGDK.Test.asmdef.meta +7 -0
  49. package/Tests/Runtime/AmaGDKCoreTest.cs +229 -0
  50. package/Tests/Runtime/AmaGDKCoreTest.cs.meta +11 -0
  51. package/Tests/Runtime/MigrationTest.cs +165 -0
  52. package/Tests/Runtime/MigrationTest.cs.meta +11 -0
  53. package/Tests/Runtime.meta +8 -0
  54. package/Tests/TestScene00.unity +125 -0
  55. package/Tests/TestScene00.unity.meta +7 -0
  56. package/Tests/TestScene01.unity +199 -0
  57. package/Tests/TestScene01.unity.meta +7 -0
  58. package/Tests/TestScene02.unity +209 -0
  59. package/Tests/TestScene02.unity.meta +7 -0
  60. package/Tests/TestScene03.unity +599 -0
  61. package/Tests/TestScene03.unity.meta +7 -0
  62. package/Tests.meta +8 -0
  63. package/package.json +18 -0
  64. package/package.json.meta +7 -0
@@ -0,0 +1,121 @@
1
+ using System;
2
+ using System.IO;
3
+ using UnityEngine;
4
+
5
+ using static Amanotes.Core.Internal.Logging;
6
+
7
+ namespace Amanotes.Core.Internal
8
+ {
9
+ internal class FileUtils
10
+ {
11
+ internal static string GetPath(string fileName)
12
+ {
13
+ return Path.Combine(basePath, fileName);
14
+ }
15
+
16
+ internal static void Save(string fileName, string content)
17
+ {
18
+ if (string.IsNullOrWhiteSpace(fileName))
19
+ {
20
+ LogWarningOnce($"File name must be not null or empty");
21
+ return;
22
+ }
23
+
24
+ if (string.IsNullOrWhiteSpace(content))
25
+ {
26
+ LogWarningOnce($"Content for {fileName} is empty");
27
+ }
28
+
29
+ string path = GetPath(fileName);
30
+
31
+ try
32
+ {
33
+ File.WriteAllText(path, content);
34
+ }
35
+ catch (Exception ex)
36
+ {
37
+ LogWarningOnce(path + "\n" + ex);
38
+ }
39
+ }
40
+
41
+ internal static string Load(string fileName)
42
+ {
43
+ string content = "";
44
+
45
+ if (string.IsNullOrWhiteSpace(fileName))
46
+ {
47
+ LogWarningOnce($"File name must be not null or empty");
48
+ return content;
49
+ }
50
+
51
+ string path = GetPath(fileName);
52
+ if (!File.Exists(path)) return content;
53
+
54
+ try
55
+ {
56
+ content = File.ReadAllText(path);
57
+ }
58
+ catch (Exception ex)
59
+ {
60
+ LogWarningOnce(path + "\n" + ex);
61
+ }
62
+
63
+ return content;
64
+ }
65
+
66
+ internal static void Delete(string fileName)
67
+ {
68
+ string path = GetPath(fileName);
69
+ if (!File.Exists(path)) return;
70
+
71
+ try
72
+ {
73
+ File.Delete(path);
74
+ }
75
+ catch (Exception ex)
76
+ {
77
+ LogWarningOnce(path + "\n" + ex);
78
+ }
79
+ }
80
+
81
+ private static string _basePath;
82
+ private static string basePath
83
+ {
84
+ get
85
+ {
86
+ if (!string.IsNullOrEmpty(_basePath)) return _basePath;
87
+ _basePath = Application.isEditor
88
+ ? Path.Combine(Directory.GetCurrentDirectory(), "Library", "AmaGDK")
89
+ : Path.Combine(Application.persistentDataPath, "AmaGDK");
90
+
91
+ if (!Directory.Exists(_basePath)) Directory.CreateDirectory(_basePath);
92
+ return _basePath;
93
+ }
94
+ }
95
+ }
96
+
97
+ internal interface IJsonFile { }
98
+
99
+ internal static class JsonFileExtension
100
+ {
101
+ public static T LoadJsonFromFile<T>(this T instance) where T : IJsonFile, new()
102
+ {
103
+ if (instance == null)
104
+ {
105
+ var result = new T();
106
+ instance = result;
107
+ }
108
+ string fileName = instance.GetType().Name;
109
+ var json = FileUtils.Load(fileName);
110
+ JsonUtility.FromJsonOverwrite(json, instance);
111
+ return instance;
112
+ }
113
+
114
+ public static void SaveJsonToFile<T>(this T instance) where T : IJsonFile
115
+ {
116
+ string fileName = instance.GetType().Name;
117
+ var json = JsonUtility.ToJson(instance);
118
+ FileUtils.Save(fileName, json);
119
+ }
120
+ }
121
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 58950d8a11dbf4ede9a707b11debd9dd
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "AmaGDK",
3
+ "rootNamespace": "",
4
+ "references": [],
5
+ "includePlatforms": [],
6
+ "excludePlatforms": [],
7
+ "allowUnsafeCode": false,
8
+ "overrideReferences": false,
9
+ "precompiledReferences": [],
10
+ "autoReferenced": true,
11
+ "defineConstraints": [],
12
+ "versionDefines": [],
13
+ "noEngineReferences": false
14
+ }
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: de4bd4c73c80444c7affaa49ab0f66ec
3
+ AssemblyDefinitionImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
@@ -0,0 +1,159 @@
1
+ using System;
2
+ using System.Collections;
3
+ using Amanotes.Core.Internal;
4
+ using UnityEngine;
5
+
6
+ using ConfigAsset = Amanotes.Core.Internal.ConfigAsset;
7
+ using Status = Amanotes.Core.Internal.Status;
8
+ using static Amanotes.Core.Internal.Logging;
9
+ using static Amanotes.Core.Internal.Messsage;
10
+
11
+ namespace Amanotes.Core
12
+ {
13
+ public partial class AmaGDK : MonoBehaviour
14
+ {
15
+ public const string VERSION = "0.1.3";
16
+
17
+ internal static AmaGDK _instance;
18
+ private static ConfigAsset _config = null;
19
+ internal static ConfigAsset Config {
20
+ get {
21
+ if (_config != null) return _config;
22
+ _config = Resources.Load<ConfigAsset>("AmaGDKConfig");
23
+ // if (_config == null) LogWarningOnce(CONFIG_NOT_FOUND);
24
+ return _config;
25
+ }
26
+ }
27
+
28
+ internal static Status _status = Status.None;
29
+ internal static Action _onReadyCallback;
30
+ internal static bool _allowInit = false;
31
+ public bool autoInit = true;
32
+
33
+ void Awake()
34
+ {
35
+ if (_instance != null && _instance != this)
36
+ {
37
+ LogWarning(MULTIPLE_INSTANCE);
38
+ Destroy(this);
39
+ return;
40
+ }
41
+
42
+ if (_instance != null)
43
+ {
44
+ LogWarning("Should never be here!");
45
+ }
46
+
47
+ _instance = this;
48
+ DontDestroyOnLoad(this);
49
+
50
+
51
+ _allowInit = _allowInit || autoInit;
52
+ StartCoroutine(InitRoutine());
53
+ }
54
+
55
+
56
+
57
+ IEnumerator InitRoutine()
58
+ {
59
+ if (Config == null)
60
+ {
61
+ throw new Exception("[AmaGDK] " + CONFIG_NOT_FOUND);
62
+ }
63
+
64
+ float time = 0;
65
+ float timeout = 3;
66
+
67
+ // Wait 1 frame to make sure all adapters have finished registering
68
+ yield return null;
69
+
70
+ var counter = 0;
71
+ const int INIT_TOLERANCE = 10 * 60;
72
+ const int INIT_WARN_CYCLE = 5 * 60;
73
+
74
+ while (!_allowInit)
75
+ {
76
+ counter++;
77
+ yield return null;
78
+
79
+ if (counter > INIT_TOLERANCE && counter % INIT_WARN_CYCLE == 1)
80
+ {
81
+ LogWarning($"Waiting for manual Init() call (~ {Mathf.RoundToInt(counter / 60f)}s passed!)");
82
+ }
83
+ }
84
+
85
+ _status = Status.Initialize;
86
+ foreach (var adapter in Adapter.listAdapters)
87
+ {
88
+ adapter.Init();
89
+
90
+ while (!adapter.IsReady)
91
+ {
92
+ time += Time.deltaTime;
93
+ yield return null;
94
+ if (time <= timeout) continue;
95
+ LogWarningOnce($"{adapter.Id} is time out");
96
+ }
97
+ }
98
+
99
+ // Init adapters
100
+ Analytics.GetAnalyticAdapters();
101
+
102
+ _status = Status.Ready;
103
+ _onReadyCallback?.Invoke();
104
+ _onReadyCallback = null;
105
+ Log(READY);
106
+ }
107
+
108
+ private void Update()
109
+ {
110
+ if (!isReady) return;
111
+ Analytics.ProcessEventQueue();
112
+ }
113
+ }
114
+
115
+ public partial class AmaGDK // PUBLIC APIS
116
+ {
117
+ public static bool isReady => _status == Status.Ready;
118
+
119
+ public static void Init(Action onReady = null)
120
+ {
121
+ if (isReady)
122
+ {
123
+ LogWarning(SDK_INIT_CALLED);
124
+ onReady?.Invoke();
125
+ return;
126
+ }
127
+
128
+ if (onReady != null)
129
+ {
130
+ _onReadyCallback -= onReady;
131
+ _onReadyCallback += onReady;
132
+ }
133
+
134
+ if (_allowInit)
135
+ {
136
+ LogWarning(SDK_INIT_CALLED);
137
+ return;
138
+ }
139
+
140
+ _allowInit = true;
141
+
142
+ if (_instance != null) return;
143
+ var sdk = new GameObject("AmaGDK5");
144
+ _instance = sdk.AddComponent<AmaGDK>();
145
+ }
146
+
147
+ public static void AddCallback(Action onReady)
148
+ {
149
+ if (onReady == null)
150
+ {
151
+ LogWarning("Can not add a null callback!");
152
+ return;
153
+ }
154
+ _onReadyCallback -= onReady;
155
+ _onReadyCallback += onReady;
156
+ }
157
+
158
+ }
159
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: cda81c8f16b28442bb7294551256750b
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,46 @@
1
+ %YAML 1.1
2
+ %TAG !u! tag:unity3d.com,2011:
3
+ --- !u!1 &6540055444683718090
4
+ GameObject:
5
+ m_ObjectHideFlags: 0
6
+ m_CorrespondingSourceObject: {fileID: 0}
7
+ m_PrefabInstance: {fileID: 0}
8
+ m_PrefabAsset: {fileID: 0}
9
+ serializedVersion: 6
10
+ m_Component:
11
+ - component: {fileID: 6540055444683718088}
12
+ - component: {fileID: 1352151185728716944}
13
+ m_Layer: 0
14
+ m_Name: AmaGDK
15
+ m_TagString: Untagged
16
+ m_Icon: {fileID: 0}
17
+ m_NavMeshLayer: 0
18
+ m_StaticEditorFlags: 0
19
+ m_IsActive: 1
20
+ --- !u!4 &6540055444683718088
21
+ Transform:
22
+ m_ObjectHideFlags: 0
23
+ m_CorrespondingSourceObject: {fileID: 0}
24
+ m_PrefabInstance: {fileID: 0}
25
+ m_PrefabAsset: {fileID: 0}
26
+ m_GameObject: {fileID: 6540055444683718090}
27
+ m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
28
+ m_LocalPosition: {x: 0, y: 0, z: 0}
29
+ m_LocalScale: {x: 1, y: 1, z: 1}
30
+ m_Children: []
31
+ m_Father: {fileID: 0}
32
+ m_RootOrder: 0
33
+ m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
34
+ --- !u!114 &1352151185728716944
35
+ MonoBehaviour:
36
+ m_ObjectHideFlags: 0
37
+ m_CorrespondingSourceObject: {fileID: 0}
38
+ m_PrefabInstance: {fileID: 0}
39
+ m_PrefabAsset: {fileID: 0}
40
+ m_GameObject: {fileID: 6540055444683718090}
41
+ m_Enabled: 1
42
+ m_EditorHideFlags: 0
43
+ m_Script: {fileID: 11500000, guid: cda81c8f16b28442bb7294551256750b, type: 3}
44
+ m_Name:
45
+ m_EditorClassIdentifier:
46
+ autoInit: 1
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 43c132c3f4fe3438487d2fb2e40aaa5c
3
+ PrefabImporter:
4
+ externalObjects: {}
5
+ mainObjectFileID: 11400000
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ using System.Runtime.CompilerServices;
2
+
3
+ [assembly: InternalsVisibleTo("AmaGDK.Test")]
4
+
5
+ #if UNITY_EDITOR
6
+ [assembly: InternalsVisibleTo("AmaGDK.Editor")]
7
+ [assembly: InternalsVisibleTo("AmaGDK.Test.Editor")]
8
+ #endif
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: d4a4e2c38b6204fb9a260c3a16e2f5c2
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,6 @@
1
+ using System.Collections.Generic;
2
+
3
+ namespace Amanotes.Core
4
+ {
5
+
6
+ }
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 653a76219edea423ca7f51c1c4c9b02b
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: d1a686515ec7946df9492f35e9638fea
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: cfbb48f0167d74afa8a2099a218d698e
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
package/Runtime.meta ADDED
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: a4cc0a758b6f84cdcadff62c32e04641
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "AmaSDK.Editor.Test",
3
+ "references": [
4
+ "UnityEngine.TestRunner",
5
+ "UnityEditor.TestRunner",
6
+ "AmaSDK"
7
+ ],
8
+ "includePlatforms": [
9
+ "Editor"
10
+ ],
11
+ "excludePlatforms": [],
12
+ "allowUnsafeCode": false,
13
+ "overrideReferences": true,
14
+ "precompiledReferences": [
15
+ "nunit.framework.dll"
16
+ ],
17
+ "autoReferenced": false,
18
+ "defineConstraints": [
19
+ "UNITY_INCLUDE_TESTS"
20
+ ],
21
+ "versionDefines": [],
22
+ "noEngineReferences": false
23
+ }
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 4a92dfcb2b9404c15acb7c59fc29f9fe
3
+ AssemblyDefinitionImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
@@ -0,0 +1,8 @@
1
+ fileFormatVersion: 2
2
+ guid: 1ed01abc7bb114cabbe051176ae46507
3
+ folderAsset: yes
4
+ DefaultImporter:
5
+ externalObjects: {}
6
+ userData:
7
+ assetBundleName:
8
+ assetBundleVariant:
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "AmaGDK.Test",
3
+ "references": [
4
+ "UnityEngine.TestRunner",
5
+ "AmaGDK"
6
+ ],
7
+ "includePlatforms": [],
8
+ "excludePlatforms": [],
9
+ "allowUnsafeCode": false,
10
+ "overrideReferences": true,
11
+ "precompiledReferences": [
12
+ "nunit.framework.dll"
13
+ ],
14
+ "autoReferenced": false,
15
+ "defineConstraints": [
16
+ "UNITY_INCLUDE_TESTS"
17
+ ],
18
+ "versionDefines": [],
19
+ "noEngineReferences": false
20
+ }
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: 690b2b15d1f3c42e8867b870f5704a94
3
+ AssemblyDefinitionImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant: