|
| 1 | +using UnityEngine; |
| 2 | +using UnityEditor; |
| 3 | + |
| 4 | +public class ThirdwebSDKInstallerPopup : EditorWindow |
| 5 | +{ |
| 6 | + #region Private Fields |
| 7 | + |
| 8 | + private Texture2D bannerImage; |
| 9 | + private GUIStyle headerStyle; |
| 10 | + private GUIStyle descriptionStyle; |
| 11 | + private GUIStyle codeStyle; |
| 12 | + |
| 13 | + #endregion |
| 14 | + |
| 15 | + #region Editor Window Setup |
| 16 | + |
| 17 | + [MenuItem("Thirdweb/Thirdweb Unity SDK Setup")] |
| 18 | + public static void ShowWindow() |
| 19 | + { |
| 20 | + EditorWindow.GetWindow<ThirdwebSDKInstallerPopup>("Thirdweb Unity SDK Setup").minSize = new Vector2(450, 600); |
| 21 | + } |
| 22 | + |
| 23 | + #endregion |
| 24 | + |
| 25 | + #region GUI Styles & Resources |
| 26 | + |
| 27 | + void LoadResourcesAndStyles() |
| 28 | + { |
| 29 | + if (bannerImage == null) |
| 30 | + { |
| 31 | + bannerImage = Resources.Load<Texture2D>("EditorBanner"); |
| 32 | + } |
| 33 | + |
| 34 | + if (headerStyle == null) |
| 35 | + { |
| 36 | + headerStyle = new GUIStyle(EditorStyles.boldLabel) |
| 37 | + { |
| 38 | + fontSize = 16, |
| 39 | + alignment = TextAnchor.MiddleLeft, |
| 40 | + margin = new RectOffset(0, 0, 20, 10) |
| 41 | + }; |
| 42 | + } |
| 43 | + |
| 44 | + if (descriptionStyle == null) |
| 45 | + { |
| 46 | + descriptionStyle = new GUIStyle(EditorStyles.wordWrappedLabel) { margin = new RectOffset(5, 5, 10, 5), alignment = TextAnchor.MiddleLeft }; |
| 47 | + } |
| 48 | + |
| 49 | + if (codeStyle == null) |
| 50 | + { |
| 51 | + codeStyle = new GUIStyle(EditorStyles.label) |
| 52 | + { |
| 53 | + fontStyle = FontStyle.Bold, |
| 54 | + border = new RectOffset(2, 2, 2, 2), |
| 55 | + padding = new RectOffset(5, 5, 2, 2), |
| 56 | + normal = { textColor = Color.cyan } |
| 57 | + }; |
| 58 | + } |
| 59 | + } |
| 60 | + |
| 61 | + #endregion |
| 62 | + |
| 63 | + #region OnGUI Implementation |
| 64 | + |
| 65 | + void OnGUI() |
| 66 | + { |
| 67 | + LoadResourcesAndStyles(); |
| 68 | + |
| 69 | + GUILayout.BeginVertical(); |
| 70 | + GUILayout.FlexibleSpace(); |
| 71 | + |
| 72 | + DrawBanner(); |
| 73 | + |
| 74 | + GUILayout.Space(20); |
| 75 | + |
| 76 | + DrawDocumentationSection(); |
| 77 | + |
| 78 | + GUILayout.Space(20); |
| 79 | + |
| 80 | + DrawClientIDSection(); |
| 81 | + |
| 82 | + GUILayout.Space(20); |
| 83 | + |
| 84 | + DrawPrefabSection(); |
| 85 | + |
| 86 | + GUILayout.Space(30); |
| 87 | + |
| 88 | + DrawFinishSetupButton(); |
| 89 | + |
| 90 | + GUILayout.FlexibleSpace(); |
| 91 | + GUILayout.EndVertical(); |
| 92 | + } |
| 93 | + |
| 94 | + private void DrawBanner() |
| 95 | + { |
| 96 | + GUILayout.BeginHorizontal(); |
| 97 | + GUILayout.FlexibleSpace(); |
| 98 | + GUILayout.Label(bannerImage, GUILayout.Width(80), GUILayout.Height(80)); |
| 99 | + GUILayout.Space(10); |
| 100 | + GUILayout.BeginVertical(); |
| 101 | + GUILayout.Label("Thirdweb Unity SDK", headerStyle); |
| 102 | + GUILayout.Label("Quick Setup", EditorStyles.miniBoldLabel); |
| 103 | + GUILayout.EndVertical(); |
| 104 | + GUILayout.FlexibleSpace(); |
| 105 | + GUILayout.EndHorizontal(); |
| 106 | + } |
| 107 | + |
| 108 | + private void DrawDocumentationSection() |
| 109 | + { |
| 110 | + GUILayout.BeginHorizontal(); |
| 111 | + GUILayout.FlexibleSpace(); |
| 112 | + GUILayout.BeginVertical(GUILayout.Width(380)); |
| 113 | + EditorGUILayout.LabelField("Read the official documentation to get started and understand more about the SDK's capabilities.", descriptionStyle, GUILayout.Width(380)); |
| 114 | + if (GUILayout.Button("View Documentation", GUILayout.Height(40))) |
| 115 | + { |
| 116 | + Application.OpenURL("https://portal.thirdweb.com/unity"); |
| 117 | + } |
| 118 | + GUILayout.EndVertical(); |
| 119 | + GUILayout.FlexibleSpace(); |
| 120 | + GUILayout.EndHorizontal(); |
| 121 | + } |
| 122 | + |
| 123 | + private void DrawClientIDSection() |
| 124 | + { |
| 125 | + GUILayout.BeginHorizontal(); |
| 126 | + GUILayout.FlexibleSpace(); |
| 127 | + GUILayout.BeginVertical(GUILayout.Width(380)); |
| 128 | + EditorGUILayout.LabelField( |
| 129 | + "To access thirdweb services such as Storage, RPC, and Account Abstraction, you need a Client ID. For WebGL builds, whitelist your domain. For Native builds, include your Bundle ID.", |
| 130 | + descriptionStyle, |
| 131 | + GUILayout.Width(380) |
| 132 | + ); |
| 133 | + if (GUILayout.Button("Get Client ID", GUILayout.Height(40))) |
| 134 | + { |
| 135 | + Application.OpenURL("https://thirdweb.com/create-api-key"); |
| 136 | + } |
| 137 | + GUILayout.EndVertical(); |
| 138 | + GUILayout.FlexibleSpace(); |
| 139 | + GUILayout.EndHorizontal(); |
| 140 | + } |
| 141 | + |
| 142 | + private void DrawPrefabSection() |
| 143 | + { |
| 144 | + GUILayout.BeginHorizontal(); |
| 145 | + GUILayout.FlexibleSpace(); |
| 146 | + GUILayout.BeginVertical(GUILayout.Width(380)); |
| 147 | + EditorGUILayout.LabelField( |
| 148 | + "The ThirdwebManager is a MonoBehaviour that offers a streamlined way to instantiate and control the ThirdwebSDK. Access the SDK universally using: ", |
| 149 | + descriptionStyle, |
| 150 | + GUILayout.Width(380) |
| 151 | + ); |
| 152 | + |
| 153 | + EditorGUILayout.LabelField("ThirdwebManager.Instance.SDK", codeStyle, GUILayout.Width(380)); |
| 154 | + |
| 155 | + if (GUILayout.Button("Add ThirdwebManager to Scene", GUILayout.Height(40))) |
| 156 | + { |
| 157 | + GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Thirdweb/Core/Prefabs/ThirdwebManager.prefab"); |
| 158 | + if (prefab) |
| 159 | + { |
| 160 | + Instantiate(prefab); |
| 161 | + } |
| 162 | + else |
| 163 | + { |
| 164 | + Debug.LogError("Failed to find ThirdwebManager prefab. Please ensure it's in the correct path."); |
| 165 | + } |
| 166 | + } |
| 167 | + GUILayout.EndVertical(); |
| 168 | + GUILayout.FlexibleSpace(); |
| 169 | + GUILayout.EndHorizontal(); |
| 170 | + } |
| 171 | + |
| 172 | + private void DrawFinishSetupButton() |
| 173 | + { |
| 174 | + GUILayout.BeginHorizontal(); |
| 175 | + GUILayout.FlexibleSpace(); |
| 176 | + if (GUILayout.Button("Finish Setup", GUILayout.Height(50), GUILayout.Width(250))) |
| 177 | + { |
| 178 | + EditorPrefs.SetBool("ThirdwebSDK_SetupCompleted", true); |
| 179 | + Close(); |
| 180 | + } |
| 181 | + GUILayout.FlexibleSpace(); |
| 182 | + GUILayout.EndHorizontal(); |
| 183 | + } |
| 184 | + |
| 185 | + #endregion |
| 186 | +} |
| 187 | + |
| 188 | +[InitializeOnLoad] |
| 189 | +public class ThirdwebSDKInitializer |
| 190 | +{ |
| 191 | + static ThirdwebSDKInitializer() |
| 192 | + { |
| 193 | + EditorApplication.update += RunOnce; |
| 194 | + } |
| 195 | + |
| 196 | + static void RunOnce() |
| 197 | + { |
| 198 | + EditorApplication.delayCall += () => |
| 199 | + { |
| 200 | + if (!EditorPrefs.HasKey("ThirdwebSDK_ShownPopup")) |
| 201 | + { |
| 202 | + ThirdwebSDKInstallerPopup.ShowWindow(); |
| 203 | + EditorPrefs.SetBool("ThirdwebSDK_ShownPopup", true); |
| 204 | + } |
| 205 | + EditorApplication.update -= RunOnce; |
| 206 | + }; |
| 207 | + } |
| 208 | +} |
0 commit comments