Skip to content

Commit 0fcee5d

Browse files
committed
ThirdwebManagerEditor
1 parent 10247ab commit 0fcee5d

File tree

7 files changed

+418
-13
lines changed

7 files changed

+418
-13
lines changed

Assets/Thirdweb/Editor/Thirdweb.Editor.asmdef

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
{
22
"name": "Thirdweb.Editor",
33
"rootNamespace": "",
4-
"references": [],
4+
"references": [
5+
"GUID:dd19df8f7f16e704a863fe90dc73ab63"
6+
],
57
"includePlatforms": [
68
"Editor"
79
],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
using UnityEngine;
2+
using UnityEditor;
3+
using Thirdweb.Unity;
4+
using System.Reflection;
5+
6+
namespace Thirdweb.Editor
7+
{
8+
[CustomEditor(typeof(ThirdwebManager))]
9+
public class ThirdwebManagerEditor : UnityEditor.Editor
10+
{
11+
private SerializedProperty clientIdProp;
12+
private SerializedProperty bundleIdProp;
13+
private SerializedProperty initializeOnAwakeProp;
14+
private SerializedProperty showDebugLogsProp;
15+
private SerializedProperty optOutUsageAnalyticsProp;
16+
private SerializedProperty supportedChainsProp;
17+
private SerializedProperty redirectPageHtmlOverrideProp;
18+
19+
private int selectedTab = 0;
20+
private readonly string[] tabTitles = { "Client", "Preferences", "Misc", "Debug" };
21+
22+
private GUIStyle headerStyle;
23+
private GUIStyle buttonStyle;
24+
25+
private Texture2D bannerImage;
26+
27+
private void OnEnable()
28+
{
29+
clientIdProp = FindProperty("ClientId");
30+
bundleIdProp = FindProperty("BundleId");
31+
initializeOnAwakeProp = FindProperty("InitializeOnAwake");
32+
showDebugLogsProp = FindProperty("ShowDebugLogs");
33+
optOutUsageAnalyticsProp = FindProperty("OptOutUsageAnalytics");
34+
supportedChainsProp = FindProperty("SupportedChains");
35+
redirectPageHtmlOverrideProp = FindProperty("RedirectPageHtmlOverride");
36+
37+
bannerImage = Resources.Load<Texture2D>("EditorBanner");
38+
}
39+
40+
private void InitializeStyles()
41+
{
42+
buttonStyle = new GUIStyle(GUI.skin.button)
43+
{
44+
fontStyle = FontStyle.Bold,
45+
alignment = TextAnchor.MiddleLeft,
46+
padding = new RectOffset(10, 10, 10, 10)
47+
};
48+
}
49+
50+
private SerializedProperty FindProperty(string propertyName)
51+
{
52+
var targetType = target.GetType();
53+
var property = targetType.GetProperty(propertyName, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
54+
if (property == null)
55+
return null;
56+
57+
var backingFieldName = $"<{propertyName}>k__BackingField";
58+
return serializedObject.FindProperty(backingFieldName);
59+
}
60+
61+
public override void OnInspectorGUI()
62+
{
63+
serializedObject.Update();
64+
65+
if (headerStyle == null || buttonStyle == null)
66+
{
67+
InitializeStyles();
68+
}
69+
70+
// Draw Banner and Title
71+
DrawBannerAndTitle();
72+
73+
// Draw Tab Bar
74+
DrawTabs();
75+
76+
// Draw Selected Tab Content
77+
GUILayout.Space(10);
78+
DrawSelectedTabContent();
79+
80+
serializedObject.ApplyModifiedProperties();
81+
}
82+
83+
private void DrawBannerAndTitle()
84+
{
85+
GUILayout.BeginVertical();
86+
GUILayout.Space(10);
87+
88+
GUILayout.BeginHorizontal();
89+
90+
if (bannerImage != null)
91+
{
92+
GUILayout.Label(bannerImage, GUILayout.Width(64), GUILayout.Height(64));
93+
}
94+
95+
GUILayout.Space(10);
96+
97+
GUILayout.BeginVertical();
98+
GUILayout.Space(10);
99+
GUILayout.Label("Thirdweb Configuration", EditorStyles.boldLabel);
100+
GUILayout.Label("Configure your settings and preferences.\nYou can access ThirdwebManager.Instance from anywhere.", EditorStyles.miniLabel);
101+
GUILayout.EndVertical();
102+
103+
GUILayout.EndHorizontal();
104+
105+
GUILayout.Space(10);
106+
107+
GUILayout.EndVertical();
108+
}
109+
110+
private void DrawTabs()
111+
{
112+
selectedTab = GUILayout.Toolbar(selectedTab, tabTitles, GUILayout.Height(25));
113+
}
114+
115+
private void DrawSelectedTabContent()
116+
{
117+
switch (selectedTab)
118+
{
119+
case 0:
120+
DrawClientTab();
121+
break;
122+
case 1:
123+
DrawPreferencesTab();
124+
break;
125+
case 2:
126+
DrawMiscTab();
127+
break;
128+
case 3:
129+
DrawDebugTab();
130+
break;
131+
default:
132+
GUILayout.Label("Unknown Tab", EditorStyles.boldLabel);
133+
break;
134+
}
135+
}
136+
137+
private void DrawClientTab()
138+
{
139+
EditorGUILayout.HelpBox("Configure your client settings here.", MessageType.Info);
140+
DrawProperty(clientIdProp, "Client ID");
141+
DrawProperty(bundleIdProp, "Bundle ID");
142+
DrawButton(
143+
"Create API Key",
144+
() =>
145+
{
146+
Application.OpenURL("https://thirdweb.com/create-api-key");
147+
}
148+
);
149+
}
150+
151+
private void DrawPreferencesTab()
152+
{
153+
EditorGUILayout.HelpBox("Set your preferences and initialization options here.", MessageType.Info);
154+
DrawProperty(initializeOnAwakeProp, "Initialize On Awake");
155+
DrawProperty(showDebugLogsProp, "Show Debug Logs");
156+
DrawProperty(optOutUsageAnalyticsProp, "Opt-Out of Usage Analytics");
157+
}
158+
159+
private void DrawMiscTab()
160+
{
161+
EditorGUILayout.HelpBox("Configure other settings here.", MessageType.Info);
162+
163+
// Wallet Connect Settings
164+
GUILayout.Label("Wallet Connect Settings", EditorStyles.boldLabel);
165+
DrawProperty(supportedChainsProp, "Supported Chains");
166+
167+
GUILayout.Space(10);
168+
169+
// Desktop OAuth Settings
170+
GUILayout.Label("Desktop OAuth Settings", EditorStyles.boldLabel);
171+
EditorGUILayout.LabelField("Redirect Page HTML Override", EditorStyles.boldLabel);
172+
redirectPageHtmlOverrideProp.stringValue = EditorGUILayout.TextArea(redirectPageHtmlOverrideProp.stringValue, GUILayout.MinHeight(75));
173+
}
174+
175+
private void DrawDebugTab()
176+
{
177+
EditorGUILayout.HelpBox("Debug your settings here.", MessageType.Info);
178+
179+
DrawButton(
180+
"Log Active Wallet Info",
181+
() =>
182+
{
183+
if (Application.isPlaying)
184+
{
185+
var wallet = ((ThirdwebManager)target).GetActiveWallet();
186+
if (wallet != null)
187+
{
188+
Debug.Log($"Active Wallet ({wallet.GetType().Name}) Address: {wallet.GetAddress().Result}");
189+
}
190+
else
191+
{
192+
Debug.LogWarning("No active wallet found.");
193+
}
194+
}
195+
else
196+
{
197+
Debug.LogWarning("Debugging can only be done in Play Mode.");
198+
}
199+
}
200+
);
201+
202+
DrawButton(
203+
"Open Documentation",
204+
() =>
205+
{
206+
Application.OpenURL("http://portal.thirdweb.com/unity/v5/thirdwebmanager");
207+
}
208+
);
209+
}
210+
211+
private void DrawProperty(SerializedProperty property, string label)
212+
{
213+
if (property != null)
214+
{
215+
EditorGUILayout.PropertyField(property, new GUIContent(label));
216+
}
217+
else
218+
{
219+
EditorGUILayout.HelpBox($"Property '{label}' not found.", MessageType.Error);
220+
}
221+
}
222+
223+
private void DrawButton(string label, System.Action action)
224+
{
225+
GUILayout.FlexibleSpace();
226+
// center label
227+
if (GUILayout.Button(label, buttonStyle, GUILayout.Height(35), GUILayout.ExpandWidth(true)))
228+
{
229+
action.Invoke();
230+
}
231+
GUILayout.FlexibleSpace();
232+
}
233+
}
234+
}

Assets/Thirdweb/Editor/ThirdwebManagerEditor.cs.meta

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

Assets/Thirdweb/Resources.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
107 KB
Loading

0 commit comments

Comments
 (0)