com.amanotes.gdk 0.2.11 → 0.2.13

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,14 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.13 - 2023-07-20]
4
+ ### Fix error Remote Config JSON caused by special chars (", ', \)
5
+
6
+ ## [0.2.12 - 2023-07-07]
7
+ ### Restructure GDK - symlink GDK source to unity projects
8
+ ### Unity 2019 compatible - no null coalescing
9
+ ### Remove redundant AmaPassport config field
10
+ ### Auto request AmaId
11
+
3
12
  ## [0.2.11 - 2023-06-29]
4
13
  ### SetLogCondition with EventParam
5
14
  ### Rename Migrated -> HasMigrated
@@ -3,6 +3,7 @@ using System.Text;
3
3
  using Amanotes.Core;
4
4
  using Amanotes.Core.Internal;
5
5
  using System.Collections.Generic;
6
+ using System.IO;
6
7
  using UnityEditor;
7
8
  using UnityEngine;
8
9
  using static Amanotes.Core.Internal.Logging;
@@ -23,6 +24,8 @@ namespace Amanotes.Editor
23
24
  private static bool showConfigDetail;
24
25
  private static bool showAdapterInstaller;
25
26
  private static bool showExampleDetail;
27
+ private bool adapterScanned;
28
+ private readonly List<string> lstAdapter = new List<string>();
26
29
 
27
30
  public static Color btnColor;
28
31
  public static float btnLerp;
@@ -32,6 +35,7 @@ namespace Amanotes.Editor
32
35
  FIREBASE_ANALYTICS,
33
36
  FIREBASE_REMOTE_CONFIG,
34
37
  APPSFLYER,
38
+ ADJUST,
35
39
  IRONSOURCE,
36
40
  REVENUECAT
37
41
  };
@@ -118,14 +122,28 @@ namespace Amanotes.Editor
118
122
  EditorGUILayout.ObjectField(configAsset, configAsset.GetType(), false);
119
123
  }
120
124
 
125
+ private void UpdateListAdapter()
126
+ {
127
+ if(adapterScanned)
128
+ return;
129
+
130
+ adapterScanned = true;
131
+
132
+ var adapterPath = Directory.GetFiles(Res.PACKAGE_PATH, "*Adapter*.unitypackage", SearchOption.AllDirectories);
133
+
134
+ for (int i = 0; i < adapterPath.Length; i++)
135
+ {
136
+ lstAdapter.Add(Path.GetFileName(adapterPath[i]));
137
+ }
138
+ }
121
139
  private void DrawGUI_AdapterList()
122
140
  {
123
- for (var i = 0; i < Res.AMAGDK_ADAPTERS.Length; i++)
141
+ UpdateListAdapter();
142
+ foreach (var adapter in lstAdapter)
124
143
  {
125
- string adapterName = Res.AMAGDK_ADAPTERS[i];
126
- if (GUILayout.Button(ObjectNames.NicifyVariableName(adapterName)))
144
+ if (GUILayout.Button(ObjectNames.NicifyVariableName(adapter)))
127
145
  {
128
- var package = $"{Res.PACKAGE_PATH}{adapterName}.unitypackage";
146
+ var package = $"{Res.PACKAGE_PATH}{adapter}";
129
147
  AssetDatabase.ImportPackage(package, false);
130
148
  }
131
149
  }
@@ -0,0 +1,5 @@
1
+ using System.Runtime.CompilerServices;
2
+
3
+ #if UNITY_EDITOR
4
+ [assembly: InternalsVisibleTo("AmaGDK.Dev.Editor")]
5
+ #endif
@@ -0,0 +1,11 @@
1
+ fileFormatVersion: 2
2
+ guid: 702e20d6e8ffb452b83787a36bd81d81
3
+ MonoImporter:
4
+ externalObjects: {}
5
+ serializedVersion: 2
6
+ defaultReferences: []
7
+ executionOrder: 0
8
+ icon: {instanceID: 0}
9
+ userData:
10
+ assetBundleName:
11
+ assetBundleVariant:
@@ -101,6 +101,7 @@ namespace Amanotes.Editor
101
101
  case FIREBASE_ANALYTICS: return FirebaseAnalytics();
102
102
  case FIREBASE_REMOTE_CONFIG: return FirebaseRemoteConfig();
103
103
  case APPSFLYER: return AppsFlyer();
104
+ case ADJUST: return Adjust();
104
105
  case IRONSOURCE: return Ironsource();
105
106
  case REVENUECAT: return RevenueCat();
106
107
  default:
@@ -172,6 +173,25 @@ namespace Amanotes.Editor
172
173
 
173
174
  return version.Trim();
174
175
  }
176
+
177
+ internal static string Adjust()
178
+ {
179
+ var version = "";
180
+ List<Assembly> assemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
181
+ foreach (var assembly in assemblies)
182
+ {
183
+ foreach (var oType in assembly.GetTypes())
184
+ {
185
+ if (oType.Name.Equals("AdjustAndroid") || oType.Name.Equals("AdjustiOS") )
186
+ {
187
+ version = oType.GetField("sdkPrefix", BindingFlags.Static | BindingFlags.NonPublic)?.GetValue(null).ToString();
188
+ version = version.StartsWith("unity") ? version.Substring(5) : "";
189
+ }
190
+ }
191
+ }
192
+
193
+ return version.Trim();
194
+ }
175
195
 
176
196
  internal static string Ironsource()
177
197
  {
@@ -14,8 +14,14 @@ namespace Amanotes.Editor
14
14
 
15
15
  private static readonly Texture2D TAG_0 = (Texture2D)EditorGUIUtility.IconContent("sv_label_0").image;
16
16
  private static readonly Texture2D TAG_1 = (Texture2D)EditorGUIUtility.IconContent("sv_icon_dot1_pix16_gizmo").image;
17
- private static GUIStyle versionStyle;
18
- private static GUIStyle tagLabelStyle;
17
+ private static GUIStyle versionStyle = new GUIStyle(EditorStyles.miniBoldLabel)
18
+ {
19
+ alignment = TextAnchor.MiddleCenter
20
+ };
21
+ private static GUIStyle tagLabelStyle = new GUIStyle(EditorStyles.miniBoldLabel)
22
+ {
23
+ alignment = TextAnchor.MiddleCenter
24
+ };
19
25
 
20
26
  public static void SectionLabel(string text)
21
27
  {
@@ -88,11 +94,6 @@ namespace Amanotes.Editor
88
94
  public static void SemVerGUI(string title, SemVer version, Color? color1 = null, Color? color2 = null)
89
95
  {
90
96
  const int TAG_SIZE = 60;
91
- versionStyle ??= new GUIStyle(EditorStyles.miniBoldLabel)
92
- {
93
- alignment = TextAnchor.MiddleCenter
94
- };
95
-
96
97
  var rect = GUILayoutUtility.GetRect(120, 16f);
97
98
  var rect1 = rect;
98
99
 
@@ -104,8 +105,8 @@ namespace Amanotes.Editor
104
105
  rect2.xMin += (rect2.width-TAG_SIZE);
105
106
  rect2.width = TAG_SIZE;
106
107
 
107
- color1 ??= LIGHT_BLUE;
108
- color2 ??= LIGHT_GRAY;
108
+ if (!color1.HasValue) color1 = LIGHT_BLUE;
109
+ if (!color2.HasValue) color2 = LIGHT_GRAY;
109
110
  DrawTag(rect2, version.ToString(), version.isValid ? color1.Value : color2.Value, 0.5f);
110
111
 
111
112
  rect1.xMin += 4f;
@@ -129,11 +130,6 @@ namespace Amanotes.Editor
129
130
 
130
131
  public static void DrawTag(Rect rect, string label, Color tagColor, float alpha = 1f, float margin = 1f)
131
132
  {
132
- tagLabelStyle ??= new GUIStyle(EditorStyles.miniBoldLabel)
133
- {
134
- alignment = TextAnchor.MiddleCenter
135
- };
136
-
137
133
  rect.xMin += margin;
138
134
  rect.xMax -= margin;
139
135
  rect.yMin += margin;
Binary file
Binary file
@@ -0,0 +1,7 @@
1
+ fileFormatVersion: 2
2
+ guid: f2d9b3b564a254fc7914e00113b51329
3
+ DefaultImporter:
4
+ externalObjects: {}
5
+ userData:
6
+ assetBundleName:
7
+ assetBundleVariant:
Binary file
Binary file
Binary file
@@ -85,7 +85,7 @@ namespace Amanotes.Core
85
85
  public AdStat interstitial = new AdStat();
86
86
  public AdStat reward = new AdStat();
87
87
 
88
- internal int GetLastShowInSeconds(AdType adType)
88
+ internal int TimeSinceLastShow(AdType adType)
89
89
  {
90
90
  return (int)(Time.realtimeSinceStartup - (adType == AdType.Interstitial ? interstitial.lastSuccessTime : reward.lastSuccessTime));
91
91
  }
@@ -138,11 +138,11 @@ namespace Amanotes.Core
138
138
  _adapter?.rewardVideo.StartLoadAd();
139
139
  }
140
140
 
141
- public static bool hasInterstitial => _adapter.interstitial.hasAd;
142
- public static bool hasRewardedVideo => _adapter.rewardVideo.hasAd;
143
- public static bool showingBanner => _showingBanner;
144
- public static bool showingAd => context != null;
145
-
141
+ public static bool HasInterstitial => _adapter.interstitial.hasAd;
142
+ public static bool HasRewardedVideo => _adapter.rewardVideo.hasAd;
143
+ public static bool IsBannerShowing => _isBannerShowing;
144
+ public static bool IsAdShowing => context != null;
145
+
146
146
  private static bool ClearPrevContext()
147
147
  {
148
148
  if (context == null) return true;
@@ -176,6 +176,15 @@ namespace Amanotes.Core
176
176
  return context;
177
177
  }
178
178
 
179
+ public static bool IsInterstitialShowing
180
+ {
181
+ get
182
+ {
183
+ if (context == null) return false;
184
+ return context.adType == AdType.Interstitial;
185
+ }
186
+ }
187
+
179
188
  public static IAdCallback ShowRewardedVideo(string placementName = null, Dictionary<string, object> userData = null)
180
189
  {
181
190
  if (!ClearPrevContext()) return null;
@@ -184,19 +193,36 @@ namespace Amanotes.Core
184
193
  _adapter.rewardVideo.StartShowAd();
185
194
  return context;
186
195
  }
196
+
197
+ public static bool IsRewardedVideoShowing
198
+ {
199
+ get
200
+ {
201
+ if (context == null) return false;
202
+ return context.adType == AdType.VideoReward;
203
+ }
204
+ }
187
205
 
188
- private static bool _showingBanner;
189
- public static void ShowBanner()
206
+ private static bool _isBannerShowing;
207
+ public static void ShowBanner(BannerPosition? bannerPosition = null)
190
208
  {
191
- if (_showingBanner) return;
192
- _showingBanner = true;
193
- _adapter.ShowBanner(_adConfig.bannerPosition);
209
+ if (_isBannerShowing) return;
210
+ _isBannerShowing = true;
211
+
212
+ if (bannerPosition.HasValue)
213
+ {
214
+ _adapter.ShowBanner(bannerPosition.Value);
215
+ }
216
+ else
217
+ {
218
+ _adapter.ShowBanner(_adConfig.bannerPosition);
219
+ }
194
220
  }
195
221
 
196
222
  public static void HideBanner()
197
223
  {
198
- if (!_showingBanner) return;
199
- _showingBanner = false;
224
+ if (!_isBannerShowing) return;
225
+ _isBannerShowing = false;
200
226
  _adapter.HideBanner();
201
227
  }
202
228
 
@@ -210,6 +236,12 @@ namespace Amanotes.Core
210
236
  else
211
237
  _adapter.rewardVideo.StopShowAd();
212
238
  }
239
+
240
+ public static int TimeSinceLastInterstitial => localData.TimeSinceLastShow(AdType.Interstitial);
241
+
242
+ public static int TimeSinceLastVideoReward => localData.TimeSinceLastShow(AdType.VideoReward);
243
+
244
+ public static int TimeSinceLastAd => Math.Min(TimeSinceLastInterstitial, TimeSinceLastVideoReward) ;
213
245
  }
214
246
  }
215
247
  }
@@ -287,7 +319,7 @@ namespace Amanotes.Core.Internal
287
319
  // Stats
288
320
  public float showCallAt;
289
321
  public float showFinishAt;
290
-
322
+
291
323
  public ShowAdContext(AdType adType, string placementName, Dictionary<string, object> userData)
292
324
  {
293
325
  this.adType = adType;
@@ -585,7 +585,7 @@ namespace Amanotes.Core
585
585
  contents.AppendLine(stat.ToTsv());
586
586
  }
587
587
 
588
- FileUtils.SaveAppend(fileName, contents.ToString());
588
+ GDKFileUtils.SaveAppend(fileName, contents.ToString());
589
589
  }
590
590
  }
591
591
  }
@@ -40,14 +40,6 @@ namespace Amanotes.Core.Internal
40
40
  public const string AMAGDK_PREFAB = BASE_PATH + "Runtime/AmaGDK.prefab";
41
41
  public const string AMAGDK_CONFIG_PACKAGE = PACKAGE_PATH + "AmaGDKConfig.unitypackage";
42
42
 
43
- public static readonly string[] AMAGDK_ADAPTERS =
44
- {
45
- "FirebaseAnalyticsAdapter_v9.1.0",
46
- "AppsFlyerAdapter_v6.5.4",
47
- "IronsourceAdapter_v7.2.6",
48
- "FirebaseRemoteConfigAdapter_v9.1.0"
49
- };
50
-
51
43
  #if UNITY_EDITOR
52
44
 
53
45
  [MenuItem("GameObject/AmaGDK/Add AmaGDK Prefab", false, 10)]
@@ -34,7 +34,7 @@ namespace Amanotes.Core
34
34
  get
35
35
  {
36
36
  if (_cacheExisted == null)
37
- _cacheExisted = FileUtils.Exist(fileName);
37
+ _cacheExisted = GDKFileUtils.Exist(fileName);
38
38
  return _cacheExisted.GetValueOrDefault();
39
39
  }
40
40
  }
@@ -199,8 +199,8 @@ namespace Amanotes.Core
199
199
  }
200
200
  #endif
201
201
 
202
- string filePath = FileUtils.GetPath(fileName);
203
- FileUtils.Save(filePath, sb.ToString());
202
+ string filePath = GDKFileUtils.GetPath(fileName);
203
+ GDKFileUtils.Save(filePath, sb.ToString());
204
204
  Log($"[RemoteConfig] Saved remote config to {filePath}");
205
205
  NextState();
206
206
  }
@@ -218,7 +218,7 @@ namespace Amanotes.Core
218
218
  try
219
219
  {
220
220
  dictConfig.Clear();
221
- using (StreamReader sr = new StreamReader(FileUtils.GetPath(fileName)))
221
+ using (StreamReader sr = new StreamReader(GDKFileUtils.GetPath(fileName)))
222
222
  {
223
223
  string line;
224
224
  int lineIdx = 0;
@@ -15,12 +15,12 @@ namespace Amanotes.Core
15
15
 
16
16
  public void Save()
17
17
  {
18
- FileUtils.Save(FILE_NAME, JsonUtility.ToJson(this));
18
+ GDKFileUtils.Save(FILE_NAME, JsonUtility.ToJson(this));
19
19
  }
20
20
 
21
21
  public UserProfile Load()
22
22
  {
23
- string json = FileUtils.Load(FILE_NAME);
23
+ string json = GDKFileUtils.Load(FILE_NAME);
24
24
  if (string.IsNullOrEmpty(json)) return this;
25
25
  JsonUtility.FromJsonOverwrite(json, this);
26
26
  return this;
@@ -3,12 +3,13 @@ using System.Collections;
3
3
  using System.Collections.Generic;
4
4
  using System.IO;
5
5
  using System.Text;
6
+ using System.Text.RegularExpressions;
6
7
  using UnityEngine;
7
8
  using static Amanotes.Core.Internal.Logging;
8
9
 
9
10
  namespace Amanotes.Core.Internal
10
11
  {
11
- public class Utils
12
+ public class GDKUtils
12
13
  {
13
14
  public static void DelayCall(float seconds, Action action)
14
15
  {
@@ -22,7 +23,7 @@ namespace Amanotes.Core.Internal
22
23
  }
23
24
  }
24
25
 
25
- internal class FileUtils
26
+ internal class GDKFileUtils
26
27
  {
27
28
 
28
29
  private static string _basePath;
@@ -39,6 +40,7 @@ namespace Amanotes.Core.Internal
39
40
  return _basePath;
40
41
  }
41
42
  }
43
+
42
44
  internal static string GetPath(string fileName)
43
45
  {
44
46
  return Path.Combine(basePath, fileName);
@@ -161,6 +163,26 @@ namespace Amanotes.Core.Internal
161
163
  LogWarningOnce(path + "\n" + ex);
162
164
  }
163
165
  }
166
+
167
+ internal static void ClearCacheData()
168
+ {
169
+ StringBuilder logBuilder = new StringBuilder();
170
+ logBuilder.AppendLine("[AmaGDK] All cached data & stats cleared");
171
+
172
+ if (!Directory.Exists(_basePath))
173
+ {
174
+ logBuilder.AppendLine("Cache path not exists: " + _basePath);
175
+ return;
176
+ }
177
+
178
+ string[] filePaths = Directory.GetFiles(_basePath);
179
+ foreach (string path in filePaths)
180
+ {
181
+ Delete(path);
182
+ logBuilder.AppendLine($"[deleted] - {path}");
183
+ }
184
+ Debug.Log(logBuilder);
185
+ }
164
186
  }
165
187
 
166
188
  public class ActionQueue
@@ -238,7 +260,7 @@ namespace Amanotes.Core.Internal
238
260
  instance = result;
239
261
  }
240
262
  string fileName = instance.GetType().Name;
241
- string json = FileUtils.Load(fileName);
263
+ string json = GDKFileUtils.Load(fileName);
242
264
  JsonUtility.FromJsonOverwrite(json, instance);
243
265
  return instance;
244
266
  }
@@ -247,7 +269,7 @@ namespace Amanotes.Core.Internal
247
269
  {
248
270
  string fileName = instance.GetType().Name;
249
271
  string json = JsonUtility.ToJson(instance);
250
- FileUtils.Save(fileName, json);
272
+ GDKFileUtils.Save(fileName, json);
251
273
  }
252
274
  }
253
275
 
@@ -342,8 +364,7 @@ namespace Amanotes.Core.Internal
342
364
  return;
343
365
  }
344
366
  }
345
-
346
- jsonSb.Append($"\"{value}\"");
367
+ jsonSb.Append($"\"{EscapeJsonString(s)}\"");
347
368
  return;
348
369
  }
349
370
 
@@ -374,6 +395,13 @@ namespace Amanotes.Core.Internal
374
395
  jsonSb.Append($"{JsonUtility.ToJson(value, format)}");
375
396
  }
376
397
 
398
+ private static string EscapeJsonString(string input)
399
+ {
400
+ //Match any occurrence of a backslash(\), single quotation('), or double quotation (")
401
+ string pattern = "[\\\'\"]";
402
+ return Regex.Replace(input, pattern, match => $"\\{match.Value}");
403
+ }
404
+
377
405
  //public static T[] FromJsonToArray<T>(string json)
378
406
  //{
379
407
  // if (!json.StartsWith("{\"items\":"))
package/Runtime/AmaGDK.cs CHANGED
@@ -1,16 +1,20 @@
1
1
  using System;
2
2
  using System.Collections;
3
+ using System.Diagnostics;
4
+ using System.IO;
3
5
  using System.Text;
6
+ using System.Text.RegularExpressions;
4
7
  using Amanotes.Core.Internal;
5
8
  using UnityEngine;
6
9
  using static Amanotes.Core.Internal.Logging;
7
10
  using static Amanotes.Core.Internal.Messsage;
11
+ using Debug = System.Diagnostics.Debug;
8
12
 
9
13
  namespace Amanotes.Core
10
14
  {
11
15
  public partial class AmaGDK : MonoBehaviour
12
16
  {
13
- public const string VERSION = "0.2.11";
17
+ public const string VERSION = "0.2.13";
14
18
 
15
19
  internal static AmaGDK _instance;
16
20
  internal static Status _status = Status.None;
@@ -109,7 +113,7 @@ namespace Amanotes.Core
109
113
  _status = Status.Ready;
110
114
  _onReadyCallback?.Invoke();
111
115
  _onReadyCallback = null;
112
- Debug.Log($"AmaGDK v{VERSION} | {READY} in {Time.realtimeSinceStartup - startTime}s\n\n{adapterInfo.ToString()}");
116
+ Log($"AmaGDK v{VERSION} | {READY} in {Time.realtimeSinceStartup - startTime}s\n\n{adapterInfo.ToString()}");
113
117
  }
114
118
 
115
119
  void RegisterUnityCallback(AdapterContext adapter)
@@ -197,6 +201,7 @@ namespace Amanotes.Core
197
201
  public const string FIREBASE_ANALYTICS = "FirebaseAnalytics";
198
202
  public const string FIREBASE_REMOTE_CONFIG = "FirebaseRemoteConfig";
199
203
  public const string APPSFLYER = "AppsFlyer";
204
+ public const string ADJUST = "Adjust";
200
205
  public const string IRONSOURCE = "IronSource";
201
206
  public const string REVENUECAT = "RevenueCat";
202
207
  }
@@ -230,4 +235,48 @@ namespace Amanotes.Core
230
235
  applicationQuit?.Invoke();
231
236
  }
232
237
  }
238
+
239
+ public partial class AmaGDK // Switch dev mode
240
+ {
241
+ [ContextMenu("Change Dev Mode")]
242
+ public void ChangeDevMode()
243
+ {
244
+ string variableName = "GDK_HOME";
245
+ string output = RunShellCommand($"source ~/.zshrc && echo ${variableName}");
246
+ output = output.Trim();
247
+
248
+ if (string.IsNullOrEmpty(output))
249
+ {
250
+ LogWarning($"{variableName} environment variable is not set.");
251
+ return;
252
+ }
253
+
254
+ UpdateManifest(output);
255
+ }
256
+
257
+ private string RunShellCommand(string command)
258
+ {
259
+ Process process = new Process();
260
+ process.StartInfo.FileName = "/bin/zsh";
261
+ process.StartInfo.Arguments = $"-c \"{command}\"";
262
+ process.StartInfo.RedirectStandardOutput = true;
263
+ process.StartInfo.UseShellExecute = false;
264
+ process.StartInfo.CreateNoWindow = true;
265
+ process.Start();
266
+
267
+ string output = process.StandardOutput.ReadToEnd();
268
+ process.WaitForExit();
269
+
270
+ return output;
271
+ }
272
+
273
+ private void UpdateManifest(string strDesired)
274
+ {
275
+ const string manifestPath = "Packages/manifest.json";
276
+ string manifestJson = File.ReadAllText(manifestPath);
277
+
278
+ manifestJson = Regex.Replace(manifestJson, "\"com\\.amanotes\\.gdk\"\\s*:\\s*\"\\d+\\.\\d+\\.\\d+\"", $"\"com.amanotes.gdk\": \"{strDesired}\"");
279
+ File.WriteAllText(manifestPath, manifestJson);
280
+ }
281
+ }
233
282
  }
@@ -4,4 +4,5 @@
4
4
  #if UNITY_EDITOR
5
5
  [assembly: InternalsVisibleTo("AmaGDK.Editor")]
6
6
  [assembly: InternalsVisibleTo("AmaGDK.Test.Editor")]
7
- #endif
7
+ [assembly: InternalsVisibleTo("AmaGDK.Dev.Editor")]
8
+ #endif
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "com.amanotes.gdk",
3
- "version": "0.2.11",
3
+ "version": "0.2.13",
4
4
  "displayName": "AmaGDK",
5
5
  "description": "Amanotes Game Development Kit",
6
6
  "unity": "2020.3",