com.amanotes.gdk 0.2.64 → 0.2.65-2
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 +13 -0
- package/Editor/Extra/SDKVersionTracking.AirTable.cs +73 -0
- package/Editor/Extra/SDKVersionTracking.AirTable.cs.meta +3 -0
- package/Editor/Extra/SDKVersionTracking.cs +232 -0
- package/Editor/Extra/SDKVersionTracking.cs.meta +11 -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.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 +1 -1
- package/Runtime/AmaGDK.Ads.cs +29 -2
- package/Runtime/AmaGDK.Analytics.cs +2 -2
- package/Runtime/AmaGDK.Mono.cs +111 -0
- package/Runtime/AmaGDK.Mono.cs.meta +3 -0
- package/Runtime/AmaGDK.RemoteConfig.cs +3 -4
- package/Runtime/AmaGDK.Singleton.cs +27 -0
- package/Runtime/AmaGDK.Singleton.cs.meta +3 -0
- package/Runtime/AmaGDK.UserProfile.cs +1 -2
- package/Runtime/AmaGDK.cs +10 -54
- 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.cs +5 -9
- package/Runtime/Internal/AmaGDK.Utils.cs +63 -80
- package/Runtime/Internal/ForceQuitMonitor.cs +111 -0
- package/Runtime/Internal/ForceQuitMonitor.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
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections.Generic;
|
|
3
|
+
using UnityEngine;
|
|
4
|
+
|
|
5
|
+
namespace Amanotes.Core.Internal
|
|
6
|
+
{
|
|
7
|
+
public class ForceQuitMonitor : IOnApplicationFocus, IOnApplicationPause
|
|
8
|
+
{
|
|
9
|
+
[Serializable]
|
|
10
|
+
internal class AdsEvent
|
|
11
|
+
{
|
|
12
|
+
[NonSerialized]
|
|
13
|
+
internal const string EVENT_NAME = "force_quit";
|
|
14
|
+
[SerializeField]
|
|
15
|
+
internal string reason;
|
|
16
|
+
[SerializeField]
|
|
17
|
+
internal string detail;
|
|
18
|
+
|
|
19
|
+
internal Dictionary<string, object> Parameters => new Dictionary<string, object>
|
|
20
|
+
{
|
|
21
|
+
{"reason", reason},
|
|
22
|
+
{"detail", detail}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
[Serializable]
|
|
27
|
+
private class ForceQuitData : IJsonFile
|
|
28
|
+
{
|
|
29
|
+
[SerializeField]
|
|
30
|
+
internal AdsEvent adsEvent;
|
|
31
|
+
[NonSerialized]
|
|
32
|
+
internal bool isDirty;
|
|
33
|
+
|
|
34
|
+
internal void SaveIfDirty(bool forceSave = false)
|
|
35
|
+
{
|
|
36
|
+
if (!isDirty && !forceSave) return;
|
|
37
|
+
this.SaveJsonToFile();
|
|
38
|
+
isDirty = false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private readonly ForceQuitData localData = new ForceQuitData();
|
|
43
|
+
|
|
44
|
+
private string GetStringValueOrDefault(Dictionary<string, object> dict, string key, string defaultValue = "")
|
|
45
|
+
{
|
|
46
|
+
return dict.TryGetValue(key, out object result)
|
|
47
|
+
? result.ToString().Trim().ToLower()
|
|
48
|
+
: defaultValue;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public void OnLogEvent(string eventNameToSend, Dictionary<string, object> parameters)
|
|
52
|
+
{
|
|
53
|
+
switch (eventNameToSend)
|
|
54
|
+
{
|
|
55
|
+
case "videoads_show_called":
|
|
56
|
+
localData.adsEvent = new AdsEvent { reason = "watch_videoads" };
|
|
57
|
+
localData.isDirty = true;
|
|
58
|
+
break;
|
|
59
|
+
case "fullads_show_called":
|
|
60
|
+
localData.adsEvent = new AdsEvent { reason = "watch_fullads" };
|
|
61
|
+
localData.isDirty = true;
|
|
62
|
+
break;
|
|
63
|
+
case "ad_impression":
|
|
64
|
+
string adFormat = GetStringValueOrDefault(parameters, "ad_format");
|
|
65
|
+
if (adFormat == "rewarded_video" || adFormat == "interstitial") break;
|
|
66
|
+
|
|
67
|
+
if (localData.adsEvent != null)
|
|
68
|
+
{
|
|
69
|
+
var detailParams = new Dictionary<string, object>
|
|
70
|
+
{
|
|
71
|
+
["ad_source"] = GetStringValueOrDefault(parameters, "ad_source"),
|
|
72
|
+
["ad_unit_name"] = GetStringValueOrDefault(parameters, "ad_unit_name")
|
|
73
|
+
};
|
|
74
|
+
localData.adsEvent.detail = JsonUtils.DictionaryToJson(detailParams);
|
|
75
|
+
localData.SaveIfDirty(true);
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
case "videoads_show_notready":
|
|
79
|
+
case "videoads_finish":
|
|
80
|
+
case "fullads_show_notready":
|
|
81
|
+
case "fullads_finish":
|
|
82
|
+
localData.adsEvent = null;
|
|
83
|
+
localData.isDirty = true;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public void Init()
|
|
89
|
+
{
|
|
90
|
+
GDKUtils.AddUnityCallbacks(this);
|
|
91
|
+
OnAppOpen();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public void OnAppOpen()
|
|
95
|
+
{
|
|
96
|
+
localData.LoadJsonFromFile();
|
|
97
|
+
if (localData.adsEvent == null || string.IsNullOrWhiteSpace(localData.adsEvent.reason)) return;
|
|
98
|
+
AmaGDK.Analytics.LogEvent(AdsEvent.EVENT_NAME, localData.adsEvent.Parameters);
|
|
99
|
+
localData.adsEvent = null;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public void OnApplicationFocus(bool hasFocus)
|
|
103
|
+
{
|
|
104
|
+
if (!hasFocus) localData.SaveIfDirty();
|
|
105
|
+
}
|
|
106
|
+
public void OnApplicationPause(bool pauseStatus)
|
|
107
|
+
{
|
|
108
|
+
if (pauseStatus) localData.SaveIfDirty();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
@@ -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
|
+
}
|