@@ -10,8 +10,7 @@ namespace Thirdweb.Unity
1010{
1111 public class WebGLMetaMask : MonoBehaviour
1212 {
13- #region WebGL Imports
14-
13+ #if UNITY_WEBGL && ! UNITY_EDITOR
1514 [ DllImport ( "__Internal" ) ]
1615 private static extern void EnableEthereum ( string gameObjectName , string callback , string fallback ) ;
1716
@@ -30,7 +29,7 @@ public class WebGLMetaMask : MonoBehaviour
3029 [ DllImport ( "__Internal" ) ]
3130 private static extern void Request ( string rpcRequestMessage , string gameObjectName , string callback , string fallback ) ;
3231
33- #endregion
32+ #endif
3433
3534 private static WebGLMetaMask _instance ;
3635 private BigInteger _activeChainId ;
@@ -72,7 +71,9 @@ public async Task<bool> EnableEthereumAsync()
7271 {
7372 _enableEthereumTaskCompletionSource = new TaskCompletionSource < bool > ( ) ;
7473
74+ #if UNITY_WEBGL && ! UNITY_EDITOR
7575 EnableEthereum ( gameObject . name , nameof ( OnEnableEthereum ) , nameof ( OnEnableEthereumFallback ) ) ;
76+ #endif
7677
7778 return await _enableEthereumTaskCompletionSource . Task ;
7879 }
@@ -82,7 +83,9 @@ public void OnEnableEthereum(string result)
8283 ThirdwebDebug . Log ( $ "OnEnableEthereum: { result } ") ;
8384 _selectedAddress = result ;
8485 _isConnected = true ;
86+ #if UNITY_WEBGL && ! UNITY_EDITOR
8587 EthereumInit ( gameObject . name , nameof ( OnAccountChange ) , nameof ( OnChainChange ) ) ;
88+ #endif
8689 _enableEthereumTaskCompletionSource . SetResult ( true ) ;
8790 }
8891
@@ -96,13 +99,17 @@ public void OnEnableEthereumFallback(string result)
9699 public void OnAccountChange ( string result )
97100 {
98101 ThirdwebDebug . Log ( $ "OnAccountChange: { result } ") ;
102+ #if UNITY_WEBGL && ! UNITY_EDITOR
99103 _selectedAddress = GetSelectedAddress ( ) ;
104+ #endif
100105 }
101106
102107 public void OnChainChange ( string result )
103108 {
104109 ThirdwebDebug . Log ( $ "OnChainChange: { result } ") ;
110+ #if UNITY_WEBGL && ! UNITY_EDITOR
105111 GetChainId ( gameObject . name , nameof ( OnChainId ) , nameof ( OnChainIdFallback ) ) ;
112+ #endif
106113 }
107114
108115 public void OnChainId ( string result )
@@ -121,7 +128,9 @@ public async Task<T> RequestAsync<T>(RpcRequest rpcRequest)
121128 var rpcRequestMessage = JsonConvert . SerializeObject ( rpcRequest ) ;
122129 _rpcResponseCompletionSource = new TaskCompletionSource < string > ( ) ;
123130
131+ #if UNITY_WEBGL && ! UNITY_EDITOR
124132 Request ( rpcRequestMessage , gameObject . name , nameof ( OnRequestCallback ) , nameof ( OnRequestFallback ) ) ;
133+ #endif
125134
126135 var response = await _rpcResponseCompletionSource . Task ;
127136 var rpcResponseRaw = JsonConvert . DeserializeObject < RpcResponse < T > > ( response ) ;
@@ -144,7 +153,11 @@ public void OnRequestFallback(string result)
144153
145154 public bool IsMetaMaskAvailable ( )
146155 {
156+ #if UNITY_WEBGL && ! UNITY_EDITOR
147157 return IsMetamaskAvailable ( ) ;
158+ #else
159+ return false ;
160+ #endif
148161 }
149162
150163 public string GetAddress ( )
0 commit comments