Skip to content

Commit dfb6a7e

Browse files
authored
Connect Wallet Prefab Callback Support (#36)
1 parent aa72ba3 commit dfb6a7e

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

Assets/Thirdweb/Examples/Prefabs/Prefab_ConnectWallet.prefab

+11-2
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ MonoBehaviour:
965965
m_OnCullStateChanged:
966966
m_PersistentCalls:
967967
m_Calls: []
968-
m_Sprite: {fileID: 21300000, guid: 874d8401331ede14087e8d8d486ddda6, type: 3}
968+
m_Sprite: {fileID: 21300000, guid: 4a851c149a30f1e4b8088ab52b81444d, type: 3}
969969
m_Type: 0
970970
m_PreserveAspect: 1
971971
m_FillCenter: 1
@@ -2145,7 +2145,7 @@ MonoBehaviour:
21452145
m_OnCullStateChanged:
21462146
m_PersistentCalls:
21472147
m_Calls: []
2148-
m_Sprite: {fileID: 21300000, guid: 6d6088174bb906b49ad8428526ee337b, type: 3}
2148+
m_Sprite: {fileID: 21300000, guid: 97e254ea33741df4686d7097f9d1435b, type: 3}
21492149
m_Type: 0
21502150
m_PreserveAspect: 1
21512151
m_FillCenter: 1
@@ -2286,6 +2286,15 @@ MonoBehaviour:
22862286
m_EditorClassIdentifier:
22872287
supportedWallets: 010000000200000003000000
22882288
supportSwitchingNetwork: 1
2289+
OnConnectedCallback:
2290+
m_PersistentCalls:
2291+
m_Calls: []
2292+
OnDisconnectedCallback:
2293+
m_PersistentCalls:
2294+
m_Calls: []
2295+
OnSwitchNetworkCallback:
2296+
m_PersistentCalls:
2297+
m_Calls: []
22892298
connectButton: {fileID: 1335404547334051784}
22902299
connectDropdown: {fileID: 1335404547797609896}
22912300
walletButtons:

Assets/Thirdweb/Examples/Scripts/Prefabs/Prefab_ConnectWallet.cs

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using TMPro;
66
using UnityEngine.UI;
7+
using UnityEngine.Events;
78

89
public enum Wallet
910
{
@@ -35,6 +36,11 @@ public class Prefab_ConnectWallet : MonoBehaviour
3536
public List<Wallet> supportedWallets;
3637
public bool supportSwitchingNetwork;
3738

39+
[Header("CUSTOM CALLBACKS")]
40+
public UnityEvent OnConnectedCallback;
41+
public UnityEvent OnDisconnectedCallback;
42+
public UnityEvent OnSwitchNetworkCallback;
43+
3844
[Header("UI ELEMENTS (DO NOT EDIT)")]
3945
// Connecting
4046
public GameObject connectButton;
@@ -109,6 +115,8 @@ public async void OnConnect(Wallet _wallet)
109115

110116
wallet = _wallet;
111117
OnConnected();
118+
if (OnConnectedCallback != null)
119+
OnConnectedCallback.Invoke();
112120
print($"Connected successfully to: {address}");
113121
}
114122
catch (Exception e)
@@ -150,6 +158,8 @@ public async void OnDisconnect()
150158
{
151159
await ThirdwebManager.Instance.SDK.wallet.Disconnect();
152160
OnDisconnected();
161+
if (OnDisconnectedCallback != null)
162+
OnDisconnectedCallback.Invoke();
153163
print($"Disconnected successfully.");
154164

155165
}
@@ -178,6 +188,8 @@ public async void OnSwitchNetwork(Chain _chain)
178188
ThirdwebManager.Instance.chain = _chain;
179189
await ThirdwebManager.Instance.SDK.wallet.SwitchNetwork((int)_chain);
180190
OnConnected();
191+
if (OnSwitchNetworkCallback != null)
192+
OnSwitchNetworkCallback.Invoke();
181193
print($"Switched Network Successfully: {_chain}");
182194

183195
}

0 commit comments

Comments
 (0)