-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCrossPlatformUnityBrowser.cs
executable file
·50 lines (46 loc) · 1.67 KB
/
CrossPlatformUnityBrowser.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
namespace Thirdweb.Unity
{
public class CrossPlatformUnityBrowser : IThirdwebBrowser
{
IThirdwebBrowser _unityBrowser;
public CrossPlatformUnityBrowser(string htmlOverride = null)
{
if (string.IsNullOrEmpty(htmlOverride) || string.IsNullOrWhiteSpace(htmlOverride))
{
htmlOverride = null;
}
#if UNITY_EDITOR
_unityBrowser = new InAppWalletBrowser(htmlOverride);
#elif UNITY_WEBGL
#if UNITY_6000_0_OR_NEWER
var existingBrowser = UnityEngine.Object.FindAnyObjectByType<WebGLInAppWalletBrowser>();
#else
var existingBrowser = GameObject.FindObjectOfType<WebGLInAppWalletBrowser>();
#endif
if (existingBrowser != null)
{
_unityBrowser = existingBrowser;
}
else
{
var go = new GameObject("WebGLInAppWalletBrowser");
_unityBrowser = go.AddComponent<WebGLInAppWalletBrowser>();
}
#elif UNITY_ANDROID
_unityBrowser = new AndroidBrowser();
#elif UNITY_IOS
_unityBrowser = new IOSBrowser();
#else
_unityBrowser = new InAppWalletBrowser(htmlOverride);
#endif
}
public async Task<BrowserResult> Login(ThirdwebClient client, string loginUrl, string customScheme, Action<string> browserOpenAction, CancellationToken cancellationToken = default)
{
return await _unityBrowser.Login(client, loginUrl, customScheme, browserOpenAction, cancellationToken);
}
}
}