com.amanotes.gdk 0.2.63 → 0.2.65-1
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 +25 -0
- package/Editor/AmaGDKEditor.cs +23 -7
- package/Editor/HideInNormalInspectorDrawer.cs +22 -0
- package/Editor/HideInNormalInspectorDrawer.cs.meta +3 -0
- package/Extra/AmaGDKInstaller.unitypackage +0 -0
- package/Extra/CheckDiskSpace.unitypackage +0 -0
- package/Extra/ForceUpdate.unitypackage +0 -0
- package/Extra/GoogleCMP.unitypackage +0 -0
- package/Extra/GoogleCMP.unitypackage.meta +7 -0
- package/Extra/PostProcessor.unitypackage +0 -0
- package/Extra/SDKVersionTracking.unitypackage +0 -0
- package/Packages/AmaGDKConfig.unitypackage +0 -0
- package/Packages/AmaGDKExample.unitypackage +0 -0
- package/Packages/AmaGDKTest.unitypackage +0 -0
- package/Packages/AppsFlyerAdapter.PurchaseConnector.unitypackage +0 -0
- package/Packages/AppsFlyerAdapter.PurchaseConnector.unitypackage.meta +7 -0
- package/Packages/AppsFlyerAdapter.unitypackage +0 -0
- package/Packages/FirebaseAnalyticsAdapter.unitypackage +0 -0
- package/Packages/FirebaseRemoteConfigAdapter.unitypackage +0 -0
- package/Packages/IronSourceAdapter.unitypackage +0 -0
- package/Packages/RevenueCatAdapter.unitypackage +0 -0
- package/Packages/SqliteAnalyticsAdapter.unitypackage +0 -0
- package/Runtime/AmaGDK.Adapters.cs +14 -3
- package/Runtime/AmaGDK.Ads.cs +29 -2
- package/Runtime/AmaGDK.Analytics.cs +9 -20
- package/Runtime/AmaGDK.Mono.cs +111 -0
- package/Runtime/AmaGDK.Mono.cs.meta +3 -0
- package/Runtime/AmaGDK.RemoteConfig.cs +3 -0
- package/Runtime/AmaGDK.Singleton.cs +27 -0
- package/Runtime/AmaGDK.Singleton.cs.meta +3 -0
- package/Runtime/AmaGDK.UserProfile.cs +119 -40
- package/Runtime/AmaGDK.cs +38 -59
- package/Runtime/Core/GDKRoutine.cs +61 -0
- package/Runtime/Core/GDKRoutine.cs.meta +3 -0
- package/Runtime/Core/GDKUnityCallback.cs +141 -0
- package/Runtime/Core/GDKUnityCallback.cs.meta +3 -0
- package/Runtime/Core.meta +8 -0
- package/Runtime/Internal/AmaGDK.Internal.AmaGUI.cs +19 -2
- package/Runtime/Internal/AmaGDK.Internal.cs +4 -8
- package/Runtime/Internal/AmaGDK.Utils.cs +3 -56
- package/Runtime/Internal/HideInNormalInspectorAttribute.cs +9 -0
- package/Runtime/Internal/HideInNormalInspectorAttribute.cs.meta +3 -0
- package/Runtime/Klavar/Attributes/AccumulatedCountAttribute.cs +0 -1
- package/Runtime/Klavar/Attributes/MinMaxAttribute.cs +86 -79
- package/Runtime/Klavar/Attributes/MinMaxLengthAttribute.cs +47 -26
- package/Runtime/Klavar/Attributes/NotNullAttribute.cs +1 -1
- package/Runtime/Klavar/Attributes/RegexPatternAttribute.cs +10 -7
- package/Runtime/Klavar/Attributes/ToStringAttribute.cs +1 -1
- package/Runtime/Klavar/KlavarContainer.cs +21 -5
- package/Runtime/Klavar/KlavarEvent.cs +4 -1
- package/Runtime/Utils/GDKUtils.cs +35 -0
- package/Runtime/Utils/GDKUtils.cs.meta +3 -0
- package/Runtime/Utils.meta +8 -0
- package/package.json +1 -1
|
@@ -87,12 +87,13 @@ namespace Amanotes.Core.Internal
|
|
|
87
87
|
public static void LogError(string message)
|
|
88
88
|
{
|
|
89
89
|
if (Config.common.logLevel >= LogLevel.Error) Debug.LogError($"AmaGDK {message}");
|
|
90
|
-
if (logNonfatalErrorHook
|
|
90
|
+
if (logNonfatalErrorHook == null) return;
|
|
91
|
+
GDKUtils.DoOnMainThread(() =>
|
|
91
92
|
{
|
|
92
93
|
if (nonFatalDict.Contains(message)) return; // LogOnce
|
|
93
94
|
nonFatalDict.Add(message);
|
|
94
|
-
logNonfatalErrorHook(message);
|
|
95
|
-
}
|
|
95
|
+
logNonfatalErrorHook(message);
|
|
96
|
+
});
|
|
96
97
|
}
|
|
97
98
|
public static void Log(string message)
|
|
98
99
|
{
|
|
@@ -184,11 +185,6 @@ namespace Amanotes.Core.Internal
|
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
187
|
|
|
187
|
-
public interface IOnApplicationPause { void OnApplicationPause(bool pauseStatus); }
|
|
188
|
-
public interface IOnApplicationQuit { void OnApplicationQuit(); }
|
|
189
|
-
public interface IOnApplicationFocus { void OnApplicationFocus(bool hasFocus); }
|
|
190
|
-
public interface IOnFrameUpdate { void OnFrameUpdate(); }
|
|
191
|
-
|
|
192
188
|
public static class Utils // Hidden Utils
|
|
193
189
|
{
|
|
194
190
|
private static readonly Dictionary<string, float> LastFireInSessions = new Dictionary<string, float>();
|
|
@@ -12,61 +12,8 @@ using static Amanotes.Core.Internal.Logging;
|
|
|
12
12
|
|
|
13
13
|
namespace Amanotes.Core.Internal
|
|
14
14
|
{
|
|
15
|
-
public static class GDKUtils
|
|
15
|
+
public static partial class GDKUtils
|
|
16
16
|
{
|
|
17
|
-
public static void DelayCall(float seconds, Action action)
|
|
18
|
-
{
|
|
19
|
-
AmaGDK._instance.StartCoroutine(DelayCallRoutine(seconds, action));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
public static void RegisterUnityCallbacks<T>(T target)
|
|
23
|
-
{
|
|
24
|
-
if (target == null)
|
|
25
|
-
{
|
|
26
|
-
LogWarning("RegisterUnityCallbacks: Target is null!");
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (target is IOnFrameUpdate u)
|
|
31
|
-
{
|
|
32
|
-
AmaGDK.onFrameUpdate -= u.OnFrameUpdate;
|
|
33
|
-
AmaGDK.onFrameUpdate += u.OnFrameUpdate;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (target is IOnApplicationPause p)
|
|
37
|
-
{
|
|
38
|
-
AmaGDK.onApplicationPause -= p.OnApplicationPause;
|
|
39
|
-
AmaGDK.onApplicationPause += p.OnApplicationPause;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (target is IOnApplicationFocus f)
|
|
43
|
-
{
|
|
44
|
-
AmaGDK.applicationFocus -= f.OnApplicationFocus;
|
|
45
|
-
AmaGDK.applicationFocus += f.OnApplicationFocus;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (target is IOnApplicationQuit q)
|
|
49
|
-
{
|
|
50
|
-
AmaGDK.applicationQuit -= q.OnApplicationQuit;
|
|
51
|
-
AmaGDK.applicationQuit += q.OnApplicationQuit;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private static IEnumerator DelayCallRoutine(float seconds, Action callback)
|
|
56
|
-
{
|
|
57
|
-
yield return new WaitForSecondsRealtime(seconds);
|
|
58
|
-
callback();
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
public static IEnumerator Timeout(float timeoutInSecs, Func<bool> completeCheckFunc)
|
|
62
|
-
{
|
|
63
|
-
float time = Time.realtimeSinceStartup;
|
|
64
|
-
while (completeCheckFunc() == false)
|
|
65
|
-
{
|
|
66
|
-
yield return null;
|
|
67
|
-
if (Time.realtimeSinceStartup - time > timeoutInSecs) yield break;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
17
|
|
|
71
18
|
|
|
72
19
|
public static bool IsFromTemplate(string formattedString, string template)
|
|
@@ -153,7 +100,7 @@ namespace Amanotes.Core.Internal
|
|
|
153
100
|
segments[matches.Count] = template.Substring(lastIndex);
|
|
154
101
|
return segments;
|
|
155
102
|
}
|
|
156
|
-
|
|
103
|
+
|
|
157
104
|
internal static void ThrowIf(bool condition, string message)
|
|
158
105
|
{
|
|
159
106
|
if (condition)
|
|
@@ -321,7 +268,7 @@ namespace Amanotes.Core.Internal
|
|
|
321
268
|
}
|
|
322
269
|
}
|
|
323
270
|
|
|
324
|
-
|
|
271
|
+
public static void ClearCacheData()
|
|
325
272
|
{
|
|
326
273
|
var sb = new StringBuilder();
|
|
327
274
|
sb.AppendLine("[AmaGDK] All cached data & stats cleared");
|
|
@@ -1,128 +1,135 @@
|
|
|
1
1
|
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
2
3
|
using System.Reflection;
|
|
3
4
|
|
|
4
5
|
namespace Amanotes.Core
|
|
5
6
|
{
|
|
7
|
+
|
|
8
|
+
internal static class NumericValidationHelper
|
|
9
|
+
{
|
|
10
|
+
private static readonly HashSet<Type> NumericTypes = new HashSet<Type> { typeof(int), typeof(float), typeof(double) };
|
|
11
|
+
|
|
12
|
+
internal static bool IsNumeric(this object param)
|
|
13
|
+
{
|
|
14
|
+
return NumericTypes.Contains(param.GetType());
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
6
18
|
/// <summary>
|
|
7
19
|
/// Min, Max validate param
|
|
8
20
|
/// </summary>
|
|
9
21
|
public class MinMaxAttribute : ValidateLogEventAttribute
|
|
10
22
|
{
|
|
23
|
+
private readonly double min;
|
|
24
|
+
private readonly double max;
|
|
25
|
+
private readonly bool inclusiveMin;
|
|
26
|
+
private readonly bool inclusiveMax;
|
|
11
27
|
|
|
12
|
-
public
|
|
13
|
-
|
|
14
|
-
public readonly double max;
|
|
15
|
-
|
|
16
|
-
public MinMaxAttribute(double min, double max)
|
|
28
|
+
public MinMaxAttribute(double min, double max, bool inclusiveMin = true, bool inclusiveMax = true)
|
|
17
29
|
{
|
|
18
30
|
this.min = min;
|
|
19
31
|
this.max = max;
|
|
32
|
+
this.inclusiveMin = inclusiveMin;
|
|
33
|
+
this.inclusiveMax = inclusiveMax;
|
|
20
34
|
}
|
|
21
35
|
|
|
22
|
-
|
|
23
36
|
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
24
37
|
{
|
|
25
|
-
if (
|
|
26
|
-
|
|
38
|
+
if (param == null)
|
|
39
|
+
{
|
|
40
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Field '{fieldInfo.Name}' must not be null.");
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (!param.IsNumeric())
|
|
45
|
+
{
|
|
46
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Type of '{fieldInfo.Name}' must be int, float, or double.");
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
27
49
|
|
|
28
50
|
double val = Convert.ToDouble(param);
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
public class MinimumAttribute : ValidateLogEventAttribute
|
|
36
|
-
{
|
|
51
|
+
bool isMinValid = inclusiveMin ? val >= min : val > min;
|
|
52
|
+
bool isMaxValid = inclusiveMax ? val <= max : val < max;
|
|
37
53
|
|
|
38
|
-
|
|
54
|
+
if (isMinValid && isMaxValid) return;
|
|
39
55
|
|
|
56
|
+
string minBracket = inclusiveMin ? "[" : "(";
|
|
57
|
+
string maxBracket = inclusiveMax ? "]" : ")";
|
|
58
|
+
string rangeDescription = $"{minBracket}{min}, {max}{maxBracket}";
|
|
40
59
|
|
|
41
|
-
|
|
42
|
-
{
|
|
43
|
-
this.min = min;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
48
|
-
{
|
|
49
|
-
if (!(param is int) && !(param is float) && !(param is double))
|
|
50
|
-
throw new ArgumentException($"type of `{fieldInfo.Name}` is must be int, float or double");
|
|
51
|
-
|
|
52
|
-
double val = Convert.ToDouble(param);
|
|
53
|
-
if (val < min) throw new ArgumentException($"Field `{fieldInfo.Name}` must be greater or equal to {min}. Current value: {param}");
|
|
60
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Field '{fieldInfo.Name}' must be in the {rangeDescription}. Current value: {param}");
|
|
54
61
|
}
|
|
55
62
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
public class ExclusiveMinimumAttribute : ValidateLogEventAttribute
|
|
63
|
+
|
|
64
|
+
public class MinimumAttribute : ValidateLogEventAttribute
|
|
59
65
|
{
|
|
66
|
+
private readonly double min;
|
|
67
|
+
private readonly bool inclusive;
|
|
60
68
|
|
|
61
|
-
public
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
public ExclusiveMinimumAttribute(double min)
|
|
69
|
+
public MinimumAttribute(double min, bool inclusive = true)
|
|
65
70
|
{
|
|
66
71
|
this.min = min;
|
|
72
|
+
this.inclusive = inclusive;
|
|
67
73
|
}
|
|
68
|
-
|
|
69
|
-
|
|
74
|
+
|
|
70
75
|
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
71
76
|
{
|
|
72
|
-
if (
|
|
73
|
-
|
|
77
|
+
if (param == null)
|
|
78
|
+
{
|
|
79
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Field '{fieldInfo.Name}' must not be null.");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (!param.IsNumeric())
|
|
83
|
+
{
|
|
84
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Type of '{fieldInfo.Name}' must be int, float, or double.");
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
74
87
|
|
|
75
88
|
double val = Convert.ToDouble(param);
|
|
76
|
-
if (
|
|
89
|
+
if (inclusive)
|
|
90
|
+
{
|
|
91
|
+
if (val < min) KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Field '{fieldInfo.Name}' must be greater than or equal to {min}. Current value: {param}");
|
|
92
|
+
}
|
|
93
|
+
else
|
|
94
|
+
{
|
|
95
|
+
if (val <= min) KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Field '{fieldInfo.Name}' must be greater than {min}. Current value: {param}");
|
|
96
|
+
}
|
|
77
97
|
}
|
|
78
98
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
99
|
+
|
|
84
100
|
public class MaximumAttribute : ValidateLogEventAttribute
|
|
85
101
|
{
|
|
102
|
+
private readonly double max;
|
|
103
|
+
private readonly bool inclusive;
|
|
86
104
|
|
|
87
|
-
public
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
public MaximumAttribute(double max)
|
|
91
|
-
{
|
|
92
|
-
this.max = max;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
97
|
-
{
|
|
98
|
-
if (!(param is int) && !(param is float) && !(param is double))
|
|
99
|
-
throw new ArgumentException($"type of `{fieldInfo.Name}` is must be int, float or double");
|
|
100
|
-
|
|
101
|
-
double val = Convert.ToDouble(param);
|
|
102
|
-
if (val > max) throw new ArgumentException($"Field `{fieldInfo.Name}` must be smaller or equal to {max}. Current value: {param}");
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
public class ExclusiveMaximumAttribute : ValidateLogEventAttribute
|
|
108
|
-
{
|
|
109
|
-
|
|
110
|
-
public readonly double max;
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
public ExclusiveMaximumAttribute(double max)
|
|
105
|
+
public MaximumAttribute(double max, bool inclusive = true)
|
|
114
106
|
{
|
|
115
107
|
this.max = max;
|
|
108
|
+
this.inclusive = inclusive;
|
|
116
109
|
}
|
|
117
|
-
|
|
118
|
-
|
|
110
|
+
|
|
119
111
|
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
120
112
|
{
|
|
121
|
-
if (
|
|
122
|
-
|
|
113
|
+
if (param == null)
|
|
114
|
+
{
|
|
115
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Field '{fieldInfo.Name}' must not be null.");
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
if (!param.IsNumeric())
|
|
119
|
+
{
|
|
120
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Type of '{fieldInfo.Name}' must be int, float, or double.");
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
123
|
|
|
124
124
|
double val = Convert.ToDouble(param);
|
|
125
|
-
if (
|
|
125
|
+
if (inclusive)
|
|
126
|
+
{
|
|
127
|
+
if (val > max) KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Field '{fieldInfo.Name}' must be less than or equal to {max}. Current value: {param}");
|
|
128
|
+
}
|
|
129
|
+
else
|
|
130
|
+
{
|
|
131
|
+
if (val >= max) KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Field '{fieldInfo.Name}' must be less than {max}. Current value: {param}");
|
|
132
|
+
}
|
|
126
133
|
}
|
|
127
134
|
}
|
|
128
135
|
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
using System;
|
|
2
1
|
using System.Reflection;
|
|
3
2
|
|
|
4
3
|
namespace Amanotes.Core
|
|
5
4
|
{
|
|
5
|
+
|
|
6
6
|
/// <summary>
|
|
7
7
|
/// Min, Max length valudate validate param. (Just apply for string only)
|
|
8
8
|
/// </summary>
|
|
9
9
|
public class MinMaxLengthAttribute : ValidateLogEventAttribute
|
|
10
10
|
{
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
private readonly int min;
|
|
12
|
+
private readonly int max;
|
|
13
13
|
|
|
14
14
|
public MinMaxLengthAttribute(int min, int max)
|
|
15
15
|
{
|
|
@@ -17,58 +17,74 @@ namespace Amanotes.Core
|
|
|
17
17
|
this.max = max;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
21
20
|
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
22
21
|
{
|
|
23
|
-
if (
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
if (param is string text)
|
|
23
|
+
{
|
|
24
|
+
if (text.Length >= min && text.Length <= max) return;
|
|
25
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, $"The length of string field '{fieldInfo.Name}' must be between {min} and {max} (inclusive). Current length: {text.Length}");
|
|
26
|
+
}
|
|
27
|
+
else
|
|
28
|
+
{
|
|
29
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, param is null ? $"Field {fieldInfo.Name} must not be null." : $"Field {fieldInfo.Name} must be a string.");
|
|
30
|
+
}
|
|
27
31
|
}
|
|
28
32
|
}
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
|
|
31
34
|
public class MinLengthAttribute : ValidateLogEventAttribute
|
|
32
35
|
{
|
|
33
|
-
|
|
36
|
+
private readonly int min;
|
|
34
37
|
|
|
35
38
|
public MinLengthAttribute(int min)
|
|
36
39
|
{
|
|
37
40
|
this.min = min;
|
|
38
41
|
}
|
|
39
42
|
|
|
40
|
-
|
|
41
43
|
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
42
44
|
{
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
45
|
+
if (param is string text)
|
|
46
|
+
{
|
|
47
|
+
if (text.Length < min)
|
|
48
|
+
{
|
|
49
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, $"The length of string field '{fieldInfo.Name}' must be greater than or equal to {min}. Current length: {text.Length}");
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else
|
|
53
|
+
{
|
|
54
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, param is null ? $"Field {fieldInfo.Name} must not be null." : $"Field {fieldInfo.Name} must be a string.");
|
|
55
|
+
}
|
|
46
56
|
}
|
|
47
57
|
}
|
|
48
58
|
|
|
49
|
-
|
|
50
59
|
public class MaxLengthAttribute : ValidateLogEventAttribute
|
|
51
60
|
{
|
|
52
|
-
|
|
61
|
+
private readonly int max;
|
|
53
62
|
|
|
54
63
|
public MaxLengthAttribute(int max)
|
|
55
64
|
{
|
|
56
65
|
this.max = max;
|
|
57
66
|
}
|
|
58
67
|
|
|
59
|
-
|
|
60
68
|
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
61
69
|
{
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
70
|
+
if (param is string text)
|
|
71
|
+
{
|
|
72
|
+
if (text.Length > max)
|
|
73
|
+
{
|
|
74
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, $"The length of string field '{fieldInfo.Name}' must be less than or equal to {max}. Current length: {text.Length}");
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else
|
|
78
|
+
{
|
|
79
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, param is null ? $"Field {fieldInfo.Name} must not be null." : $"Field {fieldInfo.Name} must be a string.");
|
|
80
|
+
}
|
|
65
81
|
}
|
|
66
82
|
}
|
|
67
83
|
|
|
68
84
|
|
|
69
85
|
public class FixedLengthAttribute : ValidateLogEventAttribute
|
|
70
86
|
{
|
|
71
|
-
|
|
87
|
+
private readonly int length;
|
|
72
88
|
|
|
73
89
|
public FixedLengthAttribute(int length)
|
|
74
90
|
{
|
|
@@ -77,10 +93,15 @@ namespace Amanotes.Core
|
|
|
77
93
|
|
|
78
94
|
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
79
95
|
{
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
96
|
+
if (param is string text)
|
|
97
|
+
{
|
|
98
|
+
if (text.Length != length)
|
|
99
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo,$"The length of string field '{fieldInfo.Name}' must be equal to {length}. Current length: {text.Length}");
|
|
100
|
+
}
|
|
101
|
+
else
|
|
102
|
+
{
|
|
103
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, param is null ? $"Field {fieldInfo.Name} must not be null." : $"Field {fieldInfo.Name} must be string.");
|
|
104
|
+
}
|
|
84
105
|
}
|
|
85
106
|
}
|
|
86
107
|
}
|
|
@@ -10,7 +10,7 @@ namespace Amanotes.Core
|
|
|
10
10
|
{
|
|
11
11
|
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
12
12
|
{
|
|
13
|
-
if (param is null)
|
|
13
|
+
if (param is null) KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Field '{fieldInfo.Name}' must not be null");
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
using System;
|
|
2
|
+
using System.Globalization;
|
|
2
3
|
using System.Reflection;
|
|
3
4
|
using System.Text.RegularExpressions;
|
|
4
5
|
|
|
@@ -18,23 +19,25 @@ namespace Amanotes.Core
|
|
|
18
19
|
{
|
|
19
20
|
this.regexes = new string[] { regex };
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
public RegexPatternAttribute(string[] regexes)
|
|
24
24
|
{
|
|
25
25
|
this.regexes = regexes;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
28
|
public override void Validate(object parent, FieldInfo fieldInfo, object param)
|
|
30
29
|
{
|
|
31
|
-
if (param is null)
|
|
32
|
-
|
|
30
|
+
if (param is null)
|
|
31
|
+
{
|
|
32
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Field '{fieldInfo.Name}' must not be null");
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
foreach (string regex in regexes)
|
|
33
36
|
{
|
|
34
37
|
var match = Regex.Match(param.ToString(), regex);
|
|
35
|
-
if (match
|
|
38
|
+
if (match.Success) return;
|
|
36
39
|
}
|
|
37
|
-
|
|
40
|
+
KlavarException.ThrowErrorOnField(parent, fieldInfo, $"Field '{fieldInfo.Name}' is not match as {this.GetType().Name.Replace("Attribute", "")}");
|
|
38
41
|
}
|
|
39
42
|
}
|
|
40
43
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
using System;
|
|
2
|
+
using System.Reflection;
|
|
2
3
|
using Amanotes.Core.Internal;
|
|
3
4
|
using UnityEngine;
|
|
4
5
|
using GUID = System.Guid;
|
|
@@ -13,11 +14,7 @@ namespace Amanotes.Core
|
|
|
13
14
|
|
|
14
15
|
public static void LogEventError(string message)
|
|
15
16
|
{
|
|
16
|
-
|
|
17
|
-
throw new KlavarException(message);
|
|
18
|
-
#else
|
|
19
|
-
Logging.LogError(message);
|
|
20
|
-
#endif
|
|
17
|
+
KlavarException.ThrowIfEditor(message);
|
|
21
18
|
}
|
|
22
19
|
}
|
|
23
20
|
|
|
@@ -25,6 +22,25 @@ namespace Amanotes.Core
|
|
|
25
22
|
{
|
|
26
23
|
public KlavarException() { }
|
|
27
24
|
public KlavarException(string message) : base(message) { }
|
|
25
|
+
|
|
26
|
+
public static void ThrowIfEditor(string message)
|
|
27
|
+
{
|
|
28
|
+
#if UNITY_EDITOR
|
|
29
|
+
throw new KlavarException(message);
|
|
30
|
+
#else
|
|
31
|
+
Logging.LogError(message);
|
|
32
|
+
#endif
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public static void ThrowErrorOnField(object parent, FieldInfo fieldInfo, string message)
|
|
36
|
+
{
|
|
37
|
+
var classType = parent.GetType();
|
|
38
|
+
var eventNameAttr = (EventNameAttribute) Attribute.GetCustomAttribute(classType, typeof(EventNameAttribute), true);
|
|
39
|
+
string eventName = eventNameAttr?.name ?? classType.Name;
|
|
40
|
+
var paramNameAttr = fieldInfo.GetCustomAttribute<NameAttribute>(true);
|
|
41
|
+
string paramName = paramNameAttr?.name ?? fieldInfo.Name;
|
|
42
|
+
ThrowIfEditor($"Error at event '{eventName}' parameter '{paramName}': {message}");
|
|
43
|
+
}
|
|
28
44
|
}
|
|
29
45
|
}
|
|
30
46
|
|
|
@@ -23,7 +23,10 @@ namespace Amanotes.Core
|
|
|
23
23
|
var eventNameAttr = (EventNameAttribute)Attribute.GetCustomAttribute(type, typeof(EventNameAttribute));
|
|
24
24
|
|
|
25
25
|
if (eventNameAttr == null)
|
|
26
|
-
|
|
26
|
+
{
|
|
27
|
+
KlavarException.ThrowIfEditor($"Add `EventName` attribute to class {type.FullName}");
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
27
30
|
|
|
28
31
|
var @params = this.ToDict();
|
|
29
32
|
var eventName = eventNameAttr.name;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections;
|
|
3
|
+
using System.Threading;
|
|
4
|
+
using UnityEngine;
|
|
5
|
+
using static Amanotes.Core.Internal.Logging;
|
|
6
|
+
|
|
7
|
+
namespace Amanotes.Core.Internal
|
|
8
|
+
{
|
|
9
|
+
public static partial class GDKUtils
|
|
10
|
+
{
|
|
11
|
+
public static void SafeInvoke(Action action)
|
|
12
|
+
{
|
|
13
|
+
if (action == null) return;
|
|
14
|
+
|
|
15
|
+
if (Application.isEditor)
|
|
16
|
+
{
|
|
17
|
+
action.Invoke();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
try
|
|
22
|
+
{
|
|
23
|
+
action.Invoke();
|
|
24
|
+
} catch (Exception e)
|
|
25
|
+
{
|
|
26
|
+
LogError(e.ToString());
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public static void SafeInvoke<T>(Action<T> action, T eventObject)
|
|
31
|
+
{
|
|
32
|
+
SafeInvoke(() => action?.Invoke(eventObject));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|