@@ -10,8 +10,7 @@ namespace Thirdweb.Unity
10
10
{
11
11
public class WebGLMetaMask : MonoBehaviour
12
12
{
13
- #region WebGL Imports
14
-
13
+ #if UNITY_WEBGL && ! UNITY_EDITOR
15
14
[ DllImport ( "__Internal" ) ]
16
15
private static extern void EnableEthereum ( string gameObjectName , string callback , string fallback ) ;
17
16
@@ -30,7 +29,7 @@ public class WebGLMetaMask : MonoBehaviour
30
29
[ DllImport ( "__Internal" ) ]
31
30
private static extern void Request ( string rpcRequestMessage , string gameObjectName , string callback , string fallback ) ;
32
31
33
- #endregion
32
+ #endif
34
33
35
34
private static WebGLMetaMask _instance ;
36
35
private BigInteger _activeChainId ;
@@ -72,7 +71,9 @@ public async Task<bool> EnableEthereumAsync()
72
71
{
73
72
_enableEthereumTaskCompletionSource = new TaskCompletionSource < bool > ( ) ;
74
73
74
+ #if UNITY_WEBGL && ! UNITY_EDITOR
75
75
EnableEthereum ( gameObject . name , nameof ( OnEnableEthereum ) , nameof ( OnEnableEthereumFallback ) ) ;
76
+ #endif
76
77
77
78
return await _enableEthereumTaskCompletionSource . Task ;
78
79
}
@@ -82,7 +83,9 @@ public void OnEnableEthereum(string result)
82
83
ThirdwebDebug . Log ( $ "OnEnableEthereum: { result } ") ;
83
84
_selectedAddress = result ;
84
85
_isConnected = true ;
86
+ #if UNITY_WEBGL && ! UNITY_EDITOR
85
87
EthereumInit ( gameObject . name , nameof ( OnAccountChange ) , nameof ( OnChainChange ) ) ;
88
+ #endif
86
89
_enableEthereumTaskCompletionSource . SetResult ( true ) ;
87
90
}
88
91
@@ -96,13 +99,17 @@ public void OnEnableEthereumFallback(string result)
96
99
public void OnAccountChange ( string result )
97
100
{
98
101
ThirdwebDebug . Log ( $ "OnAccountChange: { result } ") ;
102
+ #if UNITY_WEBGL && ! UNITY_EDITOR
99
103
_selectedAddress = GetSelectedAddress ( ) ;
104
+ #endif
100
105
}
101
106
102
107
public void OnChainChange ( string result )
103
108
{
104
109
ThirdwebDebug . Log ( $ "OnChainChange: { result } ") ;
110
+ #if UNITY_WEBGL && ! UNITY_EDITOR
105
111
GetChainId ( gameObject . name , nameof ( OnChainId ) , nameof ( OnChainIdFallback ) ) ;
112
+ #endif
106
113
}
107
114
108
115
public void OnChainId ( string result )
@@ -121,7 +128,9 @@ public async Task<T> RequestAsync<T>(RpcRequest rpcRequest)
121
128
var rpcRequestMessage = JsonConvert . SerializeObject ( rpcRequest ) ;
122
129
_rpcResponseCompletionSource = new TaskCompletionSource < string > ( ) ;
123
130
131
+ #if UNITY_WEBGL && ! UNITY_EDITOR
124
132
Request ( rpcRequestMessage , gameObject . name , nameof ( OnRequestCallback ) , nameof ( OnRequestFallback ) ) ;
133
+ #endif
125
134
126
135
var response = await _rpcResponseCompletionSource . Task ;
127
136
var rpcResponseRaw = JsonConvert . DeserializeObject < RpcResponse < T > > ( response ) ;
@@ -144,7 +153,11 @@ public void OnRequestFallback(string result)
144
153
145
154
public bool IsMetaMaskAvailable ( )
146
155
{
156
+ #if UNITY_WEBGL && ! UNITY_EDITOR
147
157
return IsMetamaskAvailable ( ) ;
158
+ #else
159
+ return false ;
160
+ #endif
148
161
}
149
162
150
163
public string GetAddress ( )
0 commit comments