com.amanotes.gdk 0.2.65-2 → 0.2.65-4
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/Editor/Extra/GDKLocalBuild.cs +24 -57
- 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/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.Analytics.cs +10 -4
- package/Runtime/AmaGDK.Mono.cs +0 -2
- package/Runtime/AmaGDK.UserProfile.cs +1 -1
- package/Runtime/AmaGDK.cs +2 -1
- package/Runtime/AudioToolkit/AmaGDK.Audio.Latency.cs +165 -0
- package/Runtime/AudioToolkit/AmaGDK.Audio.Latency.cs.meta +11 -0
- package/Runtime/AudioToolkit/AmaGDK.Audio.cs +158 -0
- package/Runtime/AudioToolkit/AmaGDK.Audio.cs.meta +11 -0
- package/Runtime/AudioToolkit/Plugins/Android/AudioDeviceDetector.java +321 -0
- package/Runtime/AudioToolkit/Plugins/Android/AudioDeviceDetector.java.meta +32 -0
- package/Runtime/AudioToolkit/Plugins/Android.meta +8 -0
- package/Runtime/AudioToolkit/Plugins/AudioDeviceDetector.cs +208 -0
- package/Runtime/AudioToolkit/Plugins/AudioDeviceDetector.cs.meta +3 -0
- package/Runtime/AudioToolkit/Plugins/iOS/AudioDeviceDetector.mm +163 -0
- package/Runtime/AudioToolkit/Plugins/iOS/AudioDeviceDetector.mm.meta +33 -0
- package/Runtime/AudioToolkit/Plugins/iOS.meta +8 -0
- package/Runtime/AudioToolkit/Plugins.meta +8 -0
- package/Runtime/AudioToolkit/Resources/device-latency.txt +256 -0
- package/Runtime/AudioToolkit/Resources/device-latency.txt.meta +7 -0
- package/Runtime/AudioToolkit/Resources.meta +8 -0
- package/Runtime/AudioToolkit.meta +3 -0
- package/package.json +1 -1
|
@@ -148,34 +148,7 @@ namespace Amanotes.Editor
|
|
|
148
148
|
{
|
|
149
149
|
var buildDir = new DirectoryInfo(buildFolder);
|
|
150
150
|
if (!buildDir.Exists) Directory.CreateDirectory(buildDir.FullName);
|
|
151
|
-
|
|
152
|
-
// Check for existed build with the same name
|
|
153
|
-
if (info.overwrite == false)
|
|
154
|
-
{
|
|
155
|
-
if (info.target == BuildTarget.Android)
|
|
156
|
-
{
|
|
157
|
-
string[] apkNames = info.GetAPKNames(buildFolder);
|
|
158
|
-
for (var i = 0; i < apkNames.Length; i++)
|
|
159
|
-
{
|
|
160
|
-
string item = apkNames[i];
|
|
161
|
-
if (!File.Exists(item)) continue;
|
|
162
|
-
Debug.LogWarning("Exporting file existed! " + item);
|
|
163
|
-
|
|
164
|
-
// return;
|
|
165
|
-
}
|
|
166
|
-
} else
|
|
167
|
-
{
|
|
168
|
-
string fullBuildPath = info.fullBuildPath(buildFolder);
|
|
169
|
-
if (Directory.Exists(fullBuildPath))
|
|
170
|
-
{
|
|
171
|
-
Debug.LogWarning("Exporting target existed! " + fullBuildPath);
|
|
172
|
-
EditorUtility.RevealInFinder(fullBuildPath);
|
|
173
|
-
|
|
174
|
-
// return;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
151
|
+
|
|
179
152
|
RemoveUnusedAssets();
|
|
180
153
|
if (info.target == BuildTarget.Android) keystore.Write();
|
|
181
154
|
|
|
@@ -322,9 +295,9 @@ namespace Amanotes.Editor
|
|
|
322
295
|
public Texture2D buildIcon;
|
|
323
296
|
public BuildTarget target;
|
|
324
297
|
|
|
325
|
-
public bool isAAB;
|
|
326
|
-
public bool splitAPK = true;
|
|
327
|
-
public bool overwrite = true;
|
|
298
|
+
// public bool isAAB;
|
|
299
|
+
// public bool splitAPK = true;
|
|
300
|
+
// public bool overwrite = true;
|
|
328
301
|
public string buildVersion;
|
|
329
302
|
public int buildNumber;
|
|
330
303
|
|
|
@@ -348,10 +321,10 @@ namespace Amanotes.Editor
|
|
|
348
321
|
if (isAndroid)
|
|
349
322
|
{
|
|
350
323
|
PlayerSettings.Android.bundleVersionCode = buildNumber;
|
|
351
|
-
PlayerSettings.Android.buildApkPerCpuArchitecture = splitAPK;
|
|
324
|
+
PlayerSettings.Android.buildApkPerCpuArchitecture = false;//splitAPK;
|
|
352
325
|
PlayerSettings.Android.targetArchitectures = AndroidArchitecture.ARM64 | AndroidArchitecture.ARMv7;
|
|
353
|
-
|
|
354
|
-
EditorUserBuildSettings.buildAppBundle = isAAB;
|
|
326
|
+
|
|
327
|
+
EditorUserBuildSettings.buildAppBundle = false;//isAAB;
|
|
355
328
|
EditorUserBuildSettings.exportAsGoogleAndroidProject = false;
|
|
356
329
|
|
|
357
330
|
#if UNITY_2021_1_OR_NEWER
|
|
@@ -368,7 +341,7 @@ namespace Amanotes.Editor
|
|
|
368
341
|
string tempName = apkName.Replace(buildName, Application.productName);
|
|
369
342
|
|
|
370
343
|
if (File.Exists(tempName)) File.Delete(tempName); // always delete temp file no matter what
|
|
371
|
-
if (
|
|
344
|
+
if (File.Exists(apkName)) File.Delete(apkName);
|
|
372
345
|
}
|
|
373
346
|
|
|
374
347
|
return;
|
|
@@ -377,8 +350,6 @@ namespace Amanotes.Editor
|
|
|
377
350
|
if (isIOS)
|
|
378
351
|
{
|
|
379
352
|
PlayerSettings.iOS.buildNumber = buildNumber.ToString();
|
|
380
|
-
if (!overwrite) return;
|
|
381
|
-
|
|
382
353
|
string path = fullBuildPath(buildFolder);
|
|
383
354
|
if (Directory.Exists(path)) Directory.Delete(path, true);
|
|
384
355
|
return;
|
|
@@ -392,17 +363,17 @@ namespace Amanotes.Editor
|
|
|
392
363
|
var buildDir = new DirectoryInfo(buildFolder);
|
|
393
364
|
string fullName = buildDir.FullName;
|
|
394
365
|
|
|
395
|
-
if (isAAB)
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
if (splitAPK)
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
366
|
+
// if (isAAB)
|
|
367
|
+
// return new[]
|
|
368
|
+
// {
|
|
369
|
+
// Path.Combine(fullName, buildName + ".aab")
|
|
370
|
+
// };
|
|
371
|
+
//
|
|
372
|
+
// if (splitAPK)
|
|
373
|
+
// return new[]
|
|
374
|
+
// {
|
|
375
|
+
// Path.Combine(fullName, buildName + ".arm64-v8a.apk"), Path.Combine(fullName, buildName + ".armeabi-v7a.apk")
|
|
376
|
+
// };
|
|
406
377
|
|
|
407
378
|
return new[]
|
|
408
379
|
{
|
|
@@ -413,7 +384,7 @@ namespace Amanotes.Editor
|
|
|
413
384
|
public void PostProcessBuild(string buildFolder)
|
|
414
385
|
{
|
|
415
386
|
if (target != BuildTarget.Android) return;
|
|
416
|
-
if (isAAB) return;
|
|
387
|
+
// if (isAAB) return;
|
|
417
388
|
|
|
418
389
|
// var productName = Application.productName;
|
|
419
390
|
string[] listAPKNames = GetAPKNames(buildFolder);
|
|
@@ -439,8 +410,8 @@ namespace Amanotes.Editor
|
|
|
439
410
|
|
|
440
411
|
if (isAndroid)
|
|
441
412
|
{
|
|
442
|
-
if (isAAB) return Path.Combine(buildDir.FullName, buildName + ".aab");
|
|
443
|
-
if (splitAPK) return buildDir.FullName;
|
|
413
|
+
// if (isAAB) return Path.Combine(buildDir.FullName, buildName + ".aab");
|
|
414
|
+
// if (splitAPK) return buildDir.FullName;
|
|
444
415
|
return Path.Combine(buildDir.FullName, buildName + ".apk");
|
|
445
416
|
}
|
|
446
417
|
|
|
@@ -737,15 +708,11 @@ namespace Amanotes.Editor
|
|
|
737
708
|
{
|
|
738
709
|
new GDKLocalBuild.BuildInfo
|
|
739
710
|
{
|
|
740
|
-
target = BuildTarget.Android
|
|
741
|
-
}.Read(),
|
|
742
|
-
new GDKLocalBuild.BuildInfo
|
|
743
|
-
{
|
|
744
|
-
target = BuildTarget.Android, isAAB = true, splitAPK = true
|
|
711
|
+
target = BuildTarget.Android
|
|
745
712
|
}.Read(),
|
|
746
713
|
new GDKLocalBuild.BuildInfo
|
|
747
714
|
{
|
|
748
|
-
target = BuildTarget.iOS
|
|
715
|
+
target = BuildTarget.iOS
|
|
749
716
|
}.Read()
|
|
750
717
|
};
|
|
751
718
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1100,8 +1100,14 @@ namespace Amanotes.Core.Internal
|
|
|
1100
1100
|
[HideInNormalInspector] public bool checkMigrationIntegrity = true;
|
|
1101
1101
|
[HideInNormalInspector] public bool migrateAccumulatedCount = true;
|
|
1102
1102
|
[HideInNormalInspector] public bool enableEventStat;
|
|
1103
|
-
[
|
|
1104
|
-
|
|
1103
|
+
[HideInInspector] public List<string> immediatelyLoggedEvents = new List<string>()
|
|
1104
|
+
{
|
|
1105
|
+
"ad_impression",
|
|
1106
|
+
"ad_impression_ama",
|
|
1107
|
+
"fullads_impression",
|
|
1108
|
+
"videoads_impression",
|
|
1109
|
+
};
|
|
1110
|
+
public AnalyticQualityConfig quality = new AnalyticQualityConfig();
|
|
1105
1111
|
}
|
|
1106
1112
|
|
|
1107
1113
|
[Serializable]
|
|
@@ -1126,8 +1132,8 @@ namespace Amanotes.Core.Internal
|
|
|
1126
1132
|
|
|
1127
1133
|
public abstract class AnalyticsAdapter : Adapter2
|
|
1128
1134
|
{
|
|
1129
|
-
[
|
|
1130
|
-
[
|
|
1135
|
+
[HideInInspector] public List<string> NeverSend = new List<string>();
|
|
1136
|
+
[HideInInspector] public List<string> AlwaysSend = new List<string>();
|
|
1131
1137
|
protected abstract bool SendEventByDefault { get; }
|
|
1132
1138
|
|
|
1133
1139
|
public bool IsForbidden(string eventName)
|
package/Runtime/AmaGDK.Mono.cs
CHANGED
package/Runtime/AmaGDK.cs
CHANGED
|
@@ -17,7 +17,7 @@ namespace Amanotes.Core
|
|
|
17
17
|
{
|
|
18
18
|
public partial class AmaGDK : MonoBehaviour
|
|
19
19
|
{
|
|
20
|
-
public const string VERSION = "0.2.65-
|
|
20
|
+
public const string VERSION = "0.2.65-4";
|
|
21
21
|
|
|
22
22
|
internal static Status _status = Status.None;
|
|
23
23
|
private static ConfigAsset _config = null;
|
|
@@ -102,6 +102,7 @@ namespace Amanotes.Core
|
|
|
102
102
|
Ads.InitModule();
|
|
103
103
|
IAP.InitModule();
|
|
104
104
|
RemoteConfig.InitModule();
|
|
105
|
+
Audio.InitModule();
|
|
105
106
|
}
|
|
106
107
|
Profiler.EndSample();
|
|
107
108
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections;
|
|
3
|
+
using Amanotes.Core.Internal;
|
|
4
|
+
using UnityEngine;
|
|
5
|
+
|
|
6
|
+
namespace Amanotes.Core
|
|
7
|
+
{
|
|
8
|
+
internal class DeviceLatency
|
|
9
|
+
{
|
|
10
|
+
internal string deviceName;
|
|
11
|
+
internal int latencyIOS;
|
|
12
|
+
internal int latencyAndroid;
|
|
13
|
+
|
|
14
|
+
private DeviceLatency(string deviceName, int latencyIOS, int latencyAndroid)
|
|
15
|
+
{
|
|
16
|
+
this.deviceName = deviceName;
|
|
17
|
+
this.latencyIOS = latencyIOS;
|
|
18
|
+
this.latencyAndroid = latencyAndroid;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
internal static DeviceLatency FromTSVString(string tsvLine)
|
|
22
|
+
{
|
|
23
|
+
string[] cols = tsvLine.Split(new[] { '\t' }, StringSplitOptions.RemoveEmptyEntries);
|
|
24
|
+
|
|
25
|
+
string name = cols.Length > 0 ? cols[0] : "";
|
|
26
|
+
int iosLatency = ParseLatency(cols, 1);
|
|
27
|
+
int androidLatency = ParseLatency(cols, 2);
|
|
28
|
+
|
|
29
|
+
return new DeviceLatency(name, iosLatency, androidLatency);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
internal int GetSimilarityScore(string[] token)
|
|
33
|
+
{
|
|
34
|
+
int result = 0;
|
|
35
|
+
string lowerLongString = deviceName.ToLower();
|
|
36
|
+
for (int i = 0, n = token.Length; i < n; i++)
|
|
37
|
+
{
|
|
38
|
+
string word = token[i];
|
|
39
|
+
if (word.Length < 2) continue;
|
|
40
|
+
if (lowerLongString.Contains(word))
|
|
41
|
+
{
|
|
42
|
+
result++;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private static int ParseLatency(string[] cols, int index)
|
|
50
|
+
{
|
|
51
|
+
int latency = 0;
|
|
52
|
+
if (cols.Length > index)
|
|
53
|
+
{
|
|
54
|
+
int.TryParse(cols[index], out latency);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return latency;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
public partial class AmaGDK
|
|
61
|
+
{
|
|
62
|
+
public partial class Audio
|
|
63
|
+
{
|
|
64
|
+
private const string PREF_AUDIO_LATENCY = "AUDIO_LATENCY_";
|
|
65
|
+
private const int ANDROID_DEFAULT_LATENCY_FOR_HEADSET = 400;
|
|
66
|
+
private const int IOS_DEFAULT_LATENCY_FOR_HEADSET = 200;
|
|
67
|
+
private const int DEFAULT_FOR_SPEAKER = 30;
|
|
68
|
+
|
|
69
|
+
private static DeviceLatency[] _deviceLatency;
|
|
70
|
+
|
|
71
|
+
private static int GetAudioDeviceLatency()
|
|
72
|
+
{
|
|
73
|
+
if (!IsConnectingBluetoothHeadset())
|
|
74
|
+
{
|
|
75
|
+
return DEFAULT_FOR_SPEAKER;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
string deviceName = DeviceInfo.Name;
|
|
79
|
+
int savedLatency = PlayerPrefs.GetInt(PREF_AUDIO_LATENCY + deviceName, -1);
|
|
80
|
+
|
|
81
|
+
if (savedLatency >= 0)
|
|
82
|
+
{
|
|
83
|
+
return savedLatency;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
int result = GetLatencyByDevice(deviceName);
|
|
87
|
+
|
|
88
|
+
if (result <= 0)
|
|
89
|
+
{
|
|
90
|
+
return GetDefaultLatency();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
SaveLatencyValue(deviceName, result);
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
private static int GetDefaultLatency()
|
|
98
|
+
{
|
|
99
|
+
int result = DEFAULT_FOR_SPEAKER;
|
|
100
|
+
#if UNITY_ANDROID
|
|
101
|
+
result = ANDROID_DEFAULT_LATENCY_FOR_HEADSET;
|
|
102
|
+
#else
|
|
103
|
+
result = IOS_DEFAULT_LATENCY_FOR_HEADSET;
|
|
104
|
+
#endif
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
private static void SaveLatencyValue(string deviceName, int latency)
|
|
109
|
+
{
|
|
110
|
+
PlayerPrefs.SetInt(PREF_AUDIO_LATENCY + deviceName, latency);
|
|
111
|
+
PlayerPrefs.Save();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
private static void Initialize()
|
|
115
|
+
{
|
|
116
|
+
if (_deviceLatency != null) return;
|
|
117
|
+
_deviceLatency = LoadDeviceLatencyData();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
private static DeviceLatency[] LoadDeviceLatencyData()
|
|
121
|
+
{
|
|
122
|
+
DeviceLatency[] result = Array.Empty<DeviceLatency>();
|
|
123
|
+
|
|
124
|
+
TextAsset textAsset = Resources.Load<TextAsset>("device-latency");
|
|
125
|
+
if (textAsset == null)
|
|
126
|
+
return result;
|
|
127
|
+
|
|
128
|
+
string[] lines = textAsset.text.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
|
|
129
|
+
result = new DeviceLatency[lines.Length - 1];
|
|
130
|
+
|
|
131
|
+
for (int i = 1; i < lines.Length; i++)
|
|
132
|
+
{
|
|
133
|
+
DeviceLatency device = DeviceLatency.FromTSVString(lines[i]);
|
|
134
|
+
result[i - 1] = device;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private static int GetLatencyByDevice(string deviceName)
|
|
141
|
+
{
|
|
142
|
+
Initialize();
|
|
143
|
+
int result = 0;
|
|
144
|
+
int maxSimilar = 0;
|
|
145
|
+
string[] tokens = deviceName.Trim().ToLower()
|
|
146
|
+
.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
|
147
|
+
for (int i = 0, n = _deviceLatency.Length; i < n; i++)
|
|
148
|
+
{
|
|
149
|
+
DeviceLatency device = _deviceLatency[i];
|
|
150
|
+
int similar = device.GetSimilarityScore(tokens);
|
|
151
|
+
if (similar <= maxSimilar)
|
|
152
|
+
continue;
|
|
153
|
+
maxSimilar = similar;
|
|
154
|
+
#if UNITY_ANDROID
|
|
155
|
+
result = device.latencyAndroid;
|
|
156
|
+
#else
|
|
157
|
+
result = device.latencyIOS;
|
|
158
|
+
#endif
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
using UnityEngine;
|
|
2
|
+
using System;
|
|
3
|
+
using System.Collections;
|
|
4
|
+
using System.Text;
|
|
5
|
+
using Amanotes.Core.Internal;
|
|
6
|
+
|
|
7
|
+
namespace Amanotes.Core
|
|
8
|
+
{
|
|
9
|
+
public partial class AmaGDK
|
|
10
|
+
{
|
|
11
|
+
internal static partial class Event
|
|
12
|
+
{
|
|
13
|
+
public const string GDK_AUDIO_INFO_CHANGE = nameof(GDK_AUDIO_INFO_CHANGE);
|
|
14
|
+
public const string GDK_AUDIO_INTERRUPT_BEGIN = nameof(GDK_AUDIO_INTERRUPT_BEGIN);
|
|
15
|
+
public const string GDK_AUDIO_INTERRUPT_END = nameof(GDK_AUDIO_INTERRUPT_END);
|
|
16
|
+
}
|
|
17
|
+
public class AudioDeviceInfo
|
|
18
|
+
{
|
|
19
|
+
internal AudioDeviceType Type;
|
|
20
|
+
internal string RawType;
|
|
21
|
+
public string Name;
|
|
22
|
+
public int LatencyMs;
|
|
23
|
+
}
|
|
24
|
+
// Public Usage
|
|
25
|
+
public partial class Audio
|
|
26
|
+
{
|
|
27
|
+
public static AudioDeviceInfo DeviceInfo;
|
|
28
|
+
|
|
29
|
+
private static readonly AudioDeviceInfo NO_DEVICE = new AudioDeviceInfo()
|
|
30
|
+
{
|
|
31
|
+
LatencyMs = DEFAULT_FOR_SPEAKER
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/// <remarks>
|
|
35
|
+
/// The <paramref name="onAudioDeviceChange"/> action takes two parameters:
|
|
36
|
+
/// <list type="bullet">
|
|
37
|
+
/// <item><term><c>bool</c></term><description> : <c>True</c> indicates that an audio device has been added - <c>False</c> indicates that an audio device has been removed.</description></item>
|
|
38
|
+
/// <item><term><c>string</c> : the name of the audio device.</term></item>
|
|
39
|
+
/// </list>
|
|
40
|
+
/// </remarks>
|
|
41
|
+
public static void SetOnAudioDeviceChangeCallback(Action<AudioDeviceInfo> onAudioDeviceChange)
|
|
42
|
+
{
|
|
43
|
+
if (onAudioDeviceChange == null)
|
|
44
|
+
{
|
|
45
|
+
Logging.LogWarning("Cannot add a null callback!");
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
dispatcher.AddListener(Event.GDK_AUDIO_INFO_CHANGE, onAudioDeviceChange, false);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public static void SetOnAudioInterruptedCallback(Action beginCallback, Action endCallback)
|
|
53
|
+
{
|
|
54
|
+
if (beginCallback != null)
|
|
55
|
+
{
|
|
56
|
+
dispatcher.AddListener(Event.GDK_AUDIO_INTERRUPT_BEGIN, beginCallback, false);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (endCallback != null)
|
|
60
|
+
{
|
|
61
|
+
dispatcher.AddListener(Event.GDK_AUDIO_INTERRUPT_END, endCallback, false);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Detector
|
|
67
|
+
public partial class Audio
|
|
68
|
+
{
|
|
69
|
+
private static AudioDeviceDetector _audioDeviceDetector;
|
|
70
|
+
|
|
71
|
+
internal static void InitModule()
|
|
72
|
+
{
|
|
73
|
+
_audioDeviceDetector = _instance.gameObject.AddComponent<AudioDeviceDetector>();
|
|
74
|
+
_audioDeviceDetector.RegisterEvents();
|
|
75
|
+
RegisterCallbacks();
|
|
76
|
+
|
|
77
|
+
DeviceInfo = DetectAudioInfo();
|
|
78
|
+
DeviceInfo.LatencyMs = GetAudioDeviceLatency();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private static AudioDeviceInfo DetectAudioInfo()
|
|
82
|
+
{
|
|
83
|
+
if (_audioDeviceDetector == null)
|
|
84
|
+
{
|
|
85
|
+
Logging.LogWarning("AmaGDK | [Audio] Module has not been initialized!");
|
|
86
|
+
return NO_DEVICE;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
var info = _audioDeviceDetector.GetInfo();
|
|
90
|
+
return new AudioDeviceInfo
|
|
91
|
+
{
|
|
92
|
+
Type = info.AudioDeviceType,
|
|
93
|
+
RawType = info.RawType,
|
|
94
|
+
Name = info.Name
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Event Handler
|
|
100
|
+
public partial class Audio
|
|
101
|
+
{
|
|
102
|
+
private static void RegisterCallbacks()
|
|
103
|
+
{
|
|
104
|
+
_audioDeviceDetector.onChanged -= OnAudioDeviceChanged;
|
|
105
|
+
_audioDeviceDetector.onChanged += OnAudioDeviceChanged;
|
|
106
|
+
|
|
107
|
+
_audioDeviceDetector.onInterrupted -= OnAudioInterrupted;
|
|
108
|
+
_audioDeviceDetector.onInterrupted += OnAudioInterrupted;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private static void OnAudioDeviceChanged(string param)
|
|
112
|
+
{
|
|
113
|
+
GDKUtils.DelayCall(1f, () =>
|
|
114
|
+
{
|
|
115
|
+
DeviceInfo = DetectAudioInfo();
|
|
116
|
+
DeviceInfo.LatencyMs = GetAudioDeviceLatency();
|
|
117
|
+
dispatcher.Dispatch(Event.GDK_AUDIO_INFO_CHANGE, DeviceInfo);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private static void OnAudioInterrupted(string param)
|
|
122
|
+
{
|
|
123
|
+
dispatcher.Dispatch(param == "began" ? Event.GDK_AUDIO_INTERRUPT_BEGIN : Event.GDK_AUDIO_INTERRUPT_END);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Util
|
|
128
|
+
public partial class Audio
|
|
129
|
+
{
|
|
130
|
+
public static bool IsConnectingBluetoothHeadset()
|
|
131
|
+
{
|
|
132
|
+
return DeviceInfo != null
|
|
133
|
+
&& (DeviceInfo.RawType == "AVAudioSessionPortBluetoothA2DP"
|
|
134
|
+
|| DeviceInfo.RawType == "TYPE_BLUETOOTH_A2DP"
|
|
135
|
+
|| DeviceInfo.RawType == "AVAudioSessionPortBluetoothHFP");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private static string GetCurrentRouteInputs()
|
|
139
|
+
{
|
|
140
|
+
#if !UNITY_EDITOR
|
|
141
|
+
return _audioDeviceDetector.GetCurrentRouteInputs();
|
|
142
|
+
#else
|
|
143
|
+
return string.Empty;
|
|
144
|
+
#endif
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
public static bool IsRecordingWithMicrophone()
|
|
148
|
+
{
|
|
149
|
+
#if UNITY_IOS
|
|
150
|
+
string currentAudioInputs = GetCurrentRouteInputs();
|
|
151
|
+
return string.IsNullOrWhiteSpace(currentAudioInputs) == false;
|
|
152
|
+
#else
|
|
153
|
+
return false;
|
|
154
|
+
#endif
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|