Skip to content

Commit 5194f68

Browse files
authored
Debugger popups instead of console logs (#31)
1 parent b548868 commit 5194f68

File tree

8 files changed

+632
-57
lines changed

8 files changed

+632
-57
lines changed

Assets/Thirdweb/Examples/Scenes/Scene_Prefabs.unity

+552
Large diffs are not rendered by default.

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

+8-12
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,11 @@ public async void GetEvents()
3535
EventQueryOptions options = new EventQueryOptions(filters);
3636

3737
List<ContractEvent<TransferEvent>> allEvents = await contract.events.Get<TransferEvent>("Transfer", options);
38-
Debug.Log($"[Get Events] Get - TransferEvent:\n{allEvents.ToString()}");
39-
foreach (ContractEvent<TransferEvent> contractEvent in allEvents)
40-
Debug.Log($"--[Get Events] ContractEvent:\n{contractEvent.ToString()}\n");
38+
Debugger.Instance.Log("[Get Events] Get - TransferEvent #1", allEvents[0].ToString());
4139
}
4240
catch (System.Exception e)
4341
{
44-
Debug.Log($"Error: {e.Message}");
42+
Debugger.Instance.Log("[Get Events] Error", e.Message);
4543
}
4644
}
4745

@@ -57,13 +55,11 @@ public async void GetAllEvents()
5755
EventQueryOptions options = new EventQueryOptions(null, 0, 16500000, "desc");
5856

5957
List<ContractEvent<object>> allContractEvents = await contract.events.GetAll(options);
60-
Debug.Log($"[Get All Events] GetAll:\n{allContractEvents.ToString()}");
61-
foreach (ContractEvent<object> contractEvent in allContractEvents)
62-
Debug.Log($"--[Get All Events] ContractEvent:\n{contractEvent.ToString()}\n");
58+
Debugger.Instance.Log("[Get All Events] Get - ContractEvent #1", allContractEvents[0].ToString());
6359
}
6460
catch (System.Exception e)
6561
{
66-
Debug.Log($"Error: {e.Message}");
62+
Debugger.Instance.Log("[Get All Events] Error", e.Message);
6763
}
6864
}
6965

@@ -73,7 +69,7 @@ public void ListenToAllEvents()
7369
{
7470
Contract contract = new Contract("goerli", "0x2e01763fA0e15e07294D74B63cE4b526B321E389");
7571
contract.events.ListenToAll((ContractEvent<object> anyEvent) => OnEventTriggered(anyEvent));
76-
Debug.Log("Listening to all events!");
72+
Debugger.Instance.Log("Listening to all events!", "Try to trigger an event on the specified contract to get a callback.");
7773
}
7874

7975
public async void RemoveAllEventListeners()
@@ -82,16 +78,16 @@ public async void RemoveAllEventListeners()
8278
{
8379
Contract contract = new Contract("goerli", "0x2e01763fA0e15e07294D74B63cE4b526B321E389");
8480
await contract.events.RemoveAllListeners();
85-
Debug.Log("Removed all event listeners!");
81+
Debugger.Instance.Log("Removed all event listeners!", "Events emitted will not trigger callbacks anymore.");
8682
}
8783
catch (System.Exception e)
8884
{
89-
Debug.Log($"Error: {e.Message}");
85+
Debugger.Instance.Log("[Remove All Event Listeners] Error", e.Message);
9086
}
9187
}
9288

9389
public void OnEventTriggered<T>(ContractEvent<T> contractEvent)
9490
{
95-
Debug.Log($"[EventListener] OnEventTriggered: An event was just emitted!\n{contractEvent.ToString()}");
91+
Debugger.Instance.Log("[EventListener] OnEventTriggered", $"An event was just emitted!\n{contractEvent.ToString()}");
9692
}
9793
}

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ public async void GetBalance()
99
try
1010
{
1111
CurrencyValue balance = await ThirdwebManager.Instance.SDK.wallet.GetBalance();
12-
Debug.Log($"[Get Balance] Native Balance:\n{balance.ToString()}");
12+
Debugger.Instance.Log("[Get Balance] Native Balance", balance.ToString());
1313
}
1414
catch (System.Exception e)
1515
{
16-
Debug.Log($"Error: {e.Message}");
16+
Debugger.Instance.Log("[Get Balance] Error", e.Message);
1717
}
1818
}
1919

@@ -27,7 +27,7 @@ public async void CustomCall()
2727
Debug.Log($"[Custom Call] Read Custom URI:\n{uri}");
2828

2929
TransactionResult transactionResult = await contract.Write("claimKitten");
30-
Debug.Log($"[Custom Call] Write Successful:\n{transactionResult}");
30+
Debugger.Instance.Log("[Custom Call] Write Successful", transactionResult.ToString());
3131

3232
// With Transaction Overrides:
3333
// await contract.Write("claim", new TransactionRequest
@@ -37,7 +37,7 @@ public async void CustomCall()
3737
}
3838
catch (System.Exception e)
3939
{
40-
Debug.Log($"Error: {e.Message}");
40+
Debugger.Instance.Log("[Custom Call] Error", e.Message);
4141
}
4242
}
4343

@@ -46,11 +46,11 @@ public async void Authenticate()
4646
try
4747
{
4848
LoginPayload data = await ThirdwebManager.Instance.SDK.wallet.Authenticate("example.com");
49-
Debug.Log($"[Authenticate] Successful:\n{data.ToString()}");
49+
Debugger.Instance.Log("[Authenticate] Successful", data.ToString());
5050
}
5151
catch (System.Exception e)
5252
{
53-
Debug.Log($"Error: {e.Message}");
53+
Debugger.Instance.Log("[Authenticate] Error", e.Message);
5454
}
5555
}
5656

@@ -65,11 +65,11 @@ public async void Deploy()
6565
primary_sale_recipient = await ThirdwebManager.Instance.SDK.wallet.GetAddress(),
6666
}
6767
);
68-
Debug.Log($"[Deploy] Successful: At {address}");
68+
Debugger.Instance.Log("[Deploy] Successful", $"Address: {address}");
6969
}
7070
catch (System.Exception e)
7171
{
72-
Debug.Log($"Error: {e.Message}");
72+
Debugger.Instance.Log("[Deploy] Error", e.Message);
7373
}
7474
}
7575

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

+12-24
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,13 @@ public async void FetchERC20()
1212
Contract contract = new Contract("goerli", "0xB4870B21f80223696b68798a755478C86ce349bE");
1313

1414
Currency currencyInfo = await contract.ERC20.Get();
15-
Debug.Log($"[Fetch ERC20] Currency:\n{currencyInfo.ToString()}");
15+
Debugger.Instance.Log("[Fetch ERC20] Get", currencyInfo.ToString());
1616

17-
CurrencyValue currencyValue = await contract.ERC20.TotalSupply();
18-
Debug.Log($"[Fetch ERC20] Total Supply:\n{currencyValue.ToString()}");
17+
// CurrencyValue currencyValue = await contract.ERC20.TotalSupply();
1918
}
2019
catch (System.Exception e)
2120
{
22-
Debug.Log($"Error: {e.Message}");
21+
Debugger.Instance.Log("[Fetch ERC20] Error", e.Message);
2322
}
2423
}
2524

@@ -30,20 +29,14 @@ public async void FetchERC721()
3029
Contract contract = new Contract("goerli", "0x2e01763fA0e15e07294D74B63cE4b526B321E389");
3130

3231
NFT getResult = await contract.ERC721.Get("1");
33-
Debug.Log($"[Fetch ERC721] Get:\n{getResult.ToString()}");
34-
35-
List<NFT> getAllResult = await contract.ERC721.GetAll(new Thirdweb.QueryAllParams() { start = 0, count = 10 });
36-
Debug.Log($"[Fetch ERC721] GetAll:\n{getAllResult.ToString()}");
37-
foreach (NFT nft in getAllResult)
38-
Debug.Log($"--[Fetch ERC721] NFT:\n{nft.ToString()}\n");
39-
40-
string tokenURI = await contract.Read<string>("tokenURI", "1");
41-
Debug.Log($"[Fetch ERC721] Custom Call - tokenURI(1): {tokenURI}");
32+
Debugger.Instance.Log("[Fetch ERC721] Get", getResult.ToString());
4233

34+
// List<NFT> getAllResult = await contract.ERC721.GetAll(new Thirdweb.QueryAllParams() { start = 0, count = 10 });
35+
// List<NFT> getOwnedResult = await contract.ERC721.GetOwned("someAddress");
4336
}
4437
catch (System.Exception e)
4538
{
46-
Debug.Log($"Error: {e.Message}");
39+
Debugger.Instance.Log("[Fetch ERC721] Error", e.Message);
4740
}
4841
}
4942

@@ -54,16 +47,13 @@ public async void FetchERC1155()
5447
Contract contract = new Contract("goerli", "0x86B7df0dc0A790789D8fDE4C604EF8187FF8AD2A");
5548

5649
NFT getResult = await contract.ERC1155.Get("1");
57-
Debug.Log($"[Fetch ERC1155] Get:\n{getResult.ToString()}");
50+
Debugger.Instance.Log("[Fetch ERC1155] Get", getResult.ToString());
5851

59-
List<NFT> getAllResult = await contract.ERC1155.GetAll(new Thirdweb.QueryAllParams() { start = 0, count = 10 });
60-
Debug.Log($"[Fetch ERC1155] GetAll:\n{getAllResult.ToString()}");
61-
foreach (NFT nft in getAllResult)
62-
Debug.Log($"--[Fetch ERC1155] NFT:\n{nft.ToString()}\n");
52+
// List<NFT> getAllResult = await contract.ERC1155.GetAll(new Thirdweb.QueryAllParams() { start = 0, count = 10 });
6353
}
6454
catch (System.Exception e)
6555
{
66-
Debug.Log($"Error: {e.Message}");
56+
Debugger.Instance.Log("[Fetch ERC1155] Error", e.Message);
6757
}
6858
}
6959

@@ -75,13 +65,11 @@ public async void FetchListings()
7565
Marketplace marketplace = contract.marketplace;
7666

7767
List<Listing> getAllListingsResult = await marketplace.GetAllListings();
78-
Debug.Log($"[Fetch Listings] GetAllListings:\n{getAllListingsResult.ToString()}");
79-
foreach (Listing listing in getAllListingsResult)
80-
Debug.Log($"--[Fetch Listings] Listing:\n{listing.ToString()}\n");
68+
Debugger.Instance.Log("[Fetch Listings] Listing #1", getAllListingsResult[0].ToString());
8169
}
8270
catch (System.Exception e)
8371
{
84-
Debug.Log($"Error: {e.Message}");
72+
Debugger.Instance.Log("[Fetch Listings] Error", e.Message);
8573
}
8674
}
8775
}

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

+9-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public async void MintERC20()
1212
Contract contract = new Contract("goerli", "0xB4870B21f80223696b68798a755478C86ce349bE");
1313

1414
TransactionResult transactionResult = await contract.ERC20.Mint("1.2");
15-
Debug.Log($"[Mint ERC20] Successful:\n{transactionResult.ToString()}");
15+
Debugger.Instance.Log("[Mint ERC20] Successful", transactionResult.ToString());
1616

1717
// Signature Minting
1818
// var payload = new ERC20MintPayload("0xE79ee09bD47F4F5381dbbACaCff2040f2FbC5803", "3.2");
@@ -21,7 +21,7 @@ public async void MintERC20()
2121
}
2222
catch (System.Exception e)
2323
{
24-
Debug.Log($"Error: {e.Message}");
24+
Debugger.Instance.Log("[Mint ERC20] Error", e.Message);
2525
}
2626
}
2727

@@ -43,15 +43,15 @@ public async void MintERC721()
4343
ERC721SignedPayload signedPayload = await contract.ERC721.signature.Generate(payload); // Typically generated on the backend
4444

4545
TransactionResult transactionResult = await contract.ERC721.signature.Mint(signedPayload);
46-
Debug.Log($"[Mint ERC721] Successful:\n{transactionResult.ToString()}");
46+
Debugger.Instance.Log("[Mint ERC721] Successful", transactionResult.ToString());
4747

4848
// NFT Drop Claiming
4949
// var result = await contract.ERC721.Claim(1);
5050
// Debug.Log("claimed tokenId: " + result[0].id);
5151
}
5252
catch (System.Exception e)
5353
{
54-
Debug.Log($"Error: {e.Message}");
54+
Debugger.Instance.Log("[Mint ERC721] Error", e.Message);
5555
}
5656
}
5757

@@ -65,15 +65,12 @@ public async void MintERC1155()
6565
bool canClaim = await contract.ERC1155.claimConditions.CanClaim("0", 1);
6666
if (!canClaim)
6767
{
68-
Debug.Log("[Mint ERC1155] Cannot claim!");
68+
Debugger.Instance.Log("[Mint ERC721] Cannot Claim", "Connected wallet not eligible to claim.");
6969
return;
7070
}
7171

7272
TransactionResult transactionResult = await contract.ERC1155.Claim("0", 1);
73-
Debug.Log($"[Mint ERC1155] Successful:\n{transactionResult.ToString()}");
74-
75-
int newSupply = await contract.ERC1155.TotalSupply("0");
76-
Debug.Log($"[Mint ERC1155] New Supply: {newSupply}");
73+
Debugger.Instance.Log("[Mint ERC1155] Successful", transactionResult.ToString());
7774

7875
// Edition Drop - Signature minting additional supply
7976
// var payload = new ERC1155MintAdditionalPayload("0xE79ee09bD47F4F5381dbbACaCff2040f2FbC5803", "1");
@@ -84,7 +81,7 @@ public async void MintERC1155()
8481
}
8582
catch (System.Exception e)
8683
{
87-
Debug.Log($"Error: {e.Message}");
84+
Debugger.Instance.Log("[Mint ERC1155] Error", e.Message);
8885
}
8986
}
9087

@@ -96,11 +93,11 @@ public async void BuyListing()
9693
Marketplace marketplace = contract.marketplace;
9794

9895
TransactionResult transactionResult = await marketplace.BuyListing("0", 1);
99-
Debug.Log($"[Buy Listing] Successful:\n{transactionResult.ToString()}");
96+
Debugger.Instance.Log("[Buy Listing] Successful", transactionResult.ToString());
10097
}
10198
catch (System.Exception e)
10299
{
103-
Debug.Log($"Error: {e.Message}");
100+
Debugger.Instance.Log("[Buy Listing] Error", e.Message);
104101
}
105102
}
106103
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private void Awake()
5454
if (Instance == null)
5555
Instance = this;
5656
else
57-
Destroy(gameObject);
57+
Destroy(this.gameObject);
5858

5959
#if !UNITY_EDITOR
6060
SDK = new ThirdwebSDK(chainIdentifiers[chain]);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using UnityEngine;
2+
using TMPro;
3+
4+
public class Debugger : MonoBehaviour
5+
{
6+
public GameObject debuggerPanel;
7+
public TMP_Text titleText;
8+
public TMP_Text descriptionText;
9+
10+
public static Debugger Instance;
11+
12+
private void Awake()
13+
{
14+
if (Instance == null)
15+
Instance = this;
16+
else
17+
Destroy(this.gameObject);
18+
}
19+
20+
private void Start()
21+
{
22+
debuggerPanel.SetActive(false);
23+
}
24+
25+
public void Log(string title, string description)
26+
{
27+
debuggerPanel.SetActive(true);
28+
titleText.text = title;
29+
descriptionText.text = description;
30+
}
31+
}

Assets/Thirdweb/Examples/Scripts/Utils/Debugger.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)