| | 1 | | using System; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL.Components; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL |
| | 7 | | { |
| | 8 | | public class DebugConfigComponent : MonoBehaviour |
| | 9 | | { |
| | 10 | | private static DebugConfigComponent sharedInstance; |
| | 11 | |
|
| | 12 | | public static DebugConfigComponent i |
| | 13 | | { |
| | 14 | | get |
| | 15 | | { |
| 0 | 16 | | if (sharedInstance == null) |
| 0 | 17 | | sharedInstance = FindObjectOfType<DebugConfigComponent>(); |
| | 18 | |
|
| 0 | 19 | | return sharedInstance; |
| | 20 | | } |
| 0 | 21 | | private set => sharedInstance = value; |
| | 22 | | } |
| | 23 | |
|
| | 24 | | public DebugConfig debugConfig; |
| | 25 | |
|
| | 26 | | public enum DebugPanel |
| | 27 | | { |
| | 28 | | Off, |
| | 29 | | Scene, |
| | 30 | | Engine |
| | 31 | | } |
| | 32 | |
|
| | 33 | | public enum BaseUrl |
| | 34 | | { |
| | 35 | | ZONE, |
| | 36 | | ORG, |
| | 37 | | LOCAL_HOST, |
| | 38 | | CUSTOM, |
| | 39 | | } |
| | 40 | |
|
| | 41 | | public enum Network |
| | 42 | | { |
| | 43 | | MAINNET, |
| | 44 | | GOERLI, |
| | 45 | | } |
| | 46 | |
|
| | 47 | | [Header("General Settings")] public bool OpenBrowserOnStart; |
| | 48 | | public bool webSocketSSL = false; |
| | 49 | |
|
| | 50 | | [Header("Kernel General Settings")] public string kernelVersion; |
| | 51 | | public bool useCustomContentServer = false; |
| | 52 | |
|
| 0 | 53 | | public string customContentServerUrl = "http://localhost:1338/"; |
| | 54 | |
|
| | 55 | | [Space(10)] public BaseUrl baseUrlMode = BaseUrl.ZONE; |
| | 56 | | [DrawIf("baseUrlMode", BaseUrl.CUSTOM)] |
| 0 | 57 | | public string customURL = "https://play.decentraland.zone/?"; |
| | 58 | |
|
| | 59 | | [Space(10)] public Network network; |
| | 60 | |
|
| | 61 | | [Tooltip( |
| | 62 | | "Set this field to force the realm (server). On the latin-american zone, recommended realms are fenrir-amber |
| | 63 | | public string realm; |
| | 64 | |
|
| 0 | 65 | | public Vector2 startInCoords = new Vector2(-99, 109); |
| | 66 | |
|
| 0 | 67 | | [Header("Kernel Misc Settings")] public bool forceLocalComms = true; |
| | 68 | |
|
| | 69 | | public bool enableTutorial = false; |
| | 70 | | public bool builderInWorld = false; |
| 0 | 71 | | public bool soloScene = true; |
| | 72 | | public bool disableAssetBundles = false; |
| | 73 | | public bool enableDebugMode = false; |
| | 74 | | public DebugPanel debugPanelMode = DebugPanel.Off; |
| | 75 | |
|
| | 76 | |
|
| | 77 | | [Header("Performance")] |
| | 78 | | public bool disableGLTFDownloadThrottle = false; |
| | 79 | | public bool multithreaded = false; |
| | 80 | | public bool runPerformanceMeterToolDuringLoading = false; |
| | 81 | | private PerformanceMeterController performanceMeterController; |
| | 82 | |
|
| | 83 | | private void Awake() |
| | 84 | | { |
| 0 | 85 | | if (sharedInstance == null) |
| 0 | 86 | | sharedInstance = this; |
| | 87 | |
|
| 0 | 88 | | DataStore.i.debugConfig.soloScene = debugConfig.soloScene; |
| 0 | 89 | | DataStore.i.debugConfig.soloSceneCoords = debugConfig.soloSceneCoords; |
| 0 | 90 | | DataStore.i.debugConfig.ignoreGlobalScenes = debugConfig.ignoreGlobalScenes; |
| 0 | 91 | | DataStore.i.debugConfig.msgStepByStep = debugConfig.msgStepByStep; |
| 0 | 92 | | DataStore.i.performance.multithreading.Set(multithreaded); |
| 0 | 93 | | if (disableGLTFDownloadThrottle) DataStore.i.performance.maxDownloads.Set(999); |
| 0 | 94 | | Texture.allowThreadedTextureCreation = multithreaded; |
| 0 | 95 | | } |
| | 96 | |
|
| | 97 | | private void Start() |
| | 98 | | { |
| 0 | 99 | | lock (DataStore.i.wsCommunication.communicationReady) |
| | 100 | | { |
| 0 | 101 | | if (DataStore.i.wsCommunication.communicationReady.Get()) |
| | 102 | | { |
| 0 | 103 | | InitConfig(); |
| 0 | 104 | | } |
| | 105 | | else |
| | 106 | | { |
| 0 | 107 | | DataStore.i.wsCommunication.communicationReady.OnChange += OnCommunicationReadyChangedValue; |
| | 108 | | } |
| 0 | 109 | | } |
| 0 | 110 | | } |
| | 111 | |
|
| | 112 | | private void OnCommunicationReadyChangedValue(bool newState, bool prevState) |
| | 113 | | { |
| 0 | 114 | | if (newState && !prevState) |
| 0 | 115 | | InitConfig(); |
| | 116 | |
|
| 0 | 117 | | DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChangedValue; |
| 0 | 118 | | } |
| | 119 | |
|
| | 120 | | private void InitConfig() |
| | 121 | | { |
| 0 | 122 | | if (useCustomContentServer) |
| | 123 | | { |
| 0 | 124 | | RendereableAssetLoadHelper.useCustomContentServerUrl = true; |
| 0 | 125 | | RendereableAssetLoadHelper.customContentServerUrl = customContentServerUrl; |
| | 126 | | } |
| | 127 | |
|
| 0 | 128 | | if (OpenBrowserOnStart) |
| 0 | 129 | | OpenWebBrowser(); |
| | 130 | |
|
| 0 | 131 | | if (runPerformanceMeterToolDuringLoading) |
| | 132 | | { |
| 0 | 133 | | CommonScriptableObjects.forcePerformanceMeter.Set(true); |
| 0 | 134 | | performanceMeterController = new PerformanceMeterController(); |
| 0 | 135 | | performanceMeterController.StartSampling(999); |
| 0 | 136 | | CommonScriptableObjects.rendererState.OnChange += OnRendererStateChanged; |
| | 137 | | } |
| 0 | 138 | | } |
| | 139 | | private void OnRendererStateChanged(bool current, bool previous) |
| | 140 | | { |
| 0 | 141 | | CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged; |
| 0 | 142 | | performanceMeterController.StopSampling(); |
| 0 | 143 | | } |
| | 144 | |
|
| | 145 | | private void OpenWebBrowser() |
| | 146 | | { |
| | 147 | | #if (UNITY_EDITOR || UNITY_STANDALONE) |
| 0 | 148 | | string baseUrl = ""; |
| 0 | 149 | | string debugString = ""; |
| | 150 | |
|
| 0 | 151 | | if (baseUrlMode.Equals(BaseUrl.CUSTOM)) |
| | 152 | | { |
| 0 | 153 | | baseUrl = this.customURL; |
| 0 | 154 | | if (string.IsNullOrEmpty(this.customURL)) |
| | 155 | | { |
| 0 | 156 | | Debug.LogError("Custom url cannot be empty"); |
| 0 | 157 | | QuitGame(); |
| 0 | 158 | | return; |
| | 159 | | } |
| | 160 | | } |
| 0 | 161 | | else if (baseUrlMode.Equals(BaseUrl.LOCAL_HOST)) |
| | 162 | | { |
| 0 | 163 | | baseUrl = "http://localhost:3000/?"; |
| 0 | 164 | | } |
| 0 | 165 | | else if (baseUrlMode.Equals(BaseUrl.ORG)) |
| | 166 | | { |
| 0 | 167 | | baseUrl = "http://play.decentraland.org/?"; |
| 0 | 168 | | if (!webSocketSSL) |
| | 169 | | { |
| 0 | 170 | | Debug.LogError( |
| | 171 | | "play.decentraland.org only works with WebSocket SSL, please change the base URL to play.decentr |
| 0 | 172 | | QuitGame(); |
| 0 | 173 | | return; |
| | 174 | | } |
| | 175 | | } |
| | 176 | | else |
| | 177 | | { |
| 0 | 178 | | baseUrl = "http://play.decentraland.zone/?"; |
| | 179 | | } |
| | 180 | |
|
| 0 | 181 | | switch (network) |
| | 182 | | { |
| | 183 | | case Network.GOERLI: |
| 0 | 184 | | debugString = "NETWORK=goerli&"; |
| 0 | 185 | | break; |
| | 186 | | case Network.MAINNET: |
| 0 | 187 | | debugString = "NETWORK=mainnet&"; |
| | 188 | | break; |
| | 189 | | } |
| | 190 | |
|
| 0 | 191 | | if (!string.IsNullOrEmpty(kernelVersion)) |
| | 192 | | { |
| 0 | 193 | | debugString += $"kernel-version={kernelVersion}&"; |
| | 194 | | } |
| | 195 | |
|
| 0 | 196 | | if (forceLocalComms) |
| | 197 | | { |
| 0 | 198 | | debugString += "LOCAL_COMMS&"; |
| | 199 | | } |
| | 200 | |
|
| 0 | 201 | | if (enableTutorial) |
| | 202 | | { |
| 0 | 203 | | debugString += "RESET_TUTORIAL&"; |
| | 204 | | } |
| | 205 | |
|
| 0 | 206 | | if (soloScene) |
| | 207 | | { |
| 0 | 208 | | debugString += "LOS=0&"; |
| | 209 | | } |
| | 210 | |
|
| 0 | 211 | | if (builderInWorld) |
| | 212 | | { |
| 0 | 213 | | debugString += "ENABLE_BUILDER_IN_WORLD&"; |
| | 214 | | } |
| | 215 | |
|
| 0 | 216 | | if (disableAssetBundles) |
| | 217 | | { |
| 0 | 218 | | debugString += "DISABLE_ASSET_BUNDLES&DISABLE_WEARABLE_ASSET_BUNDLES&"; |
| | 219 | | } |
| | 220 | |
|
| 0 | 221 | | if (enableDebugMode) |
| | 222 | | { |
| 0 | 223 | | debugString += "DEBUG_MODE&"; |
| | 224 | | } |
| | 225 | |
|
| 0 | 226 | | if (!string.IsNullOrEmpty(realm)) |
| | 227 | | { |
| 0 | 228 | | debugString += $"realm={realm}&"; |
| | 229 | | } |
| | 230 | |
|
| 0 | 231 | | string debugPanelString = ""; |
| | 232 | |
|
| 0 | 233 | | if (debugPanelMode == DebugPanel.Engine) |
| | 234 | | { |
| 0 | 235 | | debugPanelString = "ENGINE_DEBUG_PANEL&"; |
| 0 | 236 | | } |
| 0 | 237 | | else if (debugPanelMode == DebugPanel.Scene) |
| | 238 | | { |
| 0 | 239 | | debugPanelString = "SCENE_DEBUG_PANEL&"; |
| | 240 | | } |
| | 241 | |
|
| 0 | 242 | | if (webSocketSSL) |
| | 243 | | { |
| 0 | 244 | | Debug.Log( |
| | 245 | | "[REMINDER] To be able to connect with SSL you should start Chrome with the --ignore-certificate-err |
| | 246 | | } |
| | 247 | |
|
| 0 | 248 | | Application.OpenURL( |
| | 249 | | $"{baseUrl}{debugString}{debugPanelString}position={startInCoords.x}%2C{startInCoords.y}&ws={DataStore.i |
| | 250 | | #endif |
| 0 | 251 | | } |
| | 252 | |
|
| 0 | 253 | | private void OnDestroy() { DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChange |
| | 254 | |
|
| | 255 | | private void QuitGame() |
| | 256 | | { |
| | 257 | | #if UNITY_EDITOR |
| | 258 | | // Application.Quit() does not work in the editor so |
| | 259 | | // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game |
| 0 | 260 | | UnityEditor.EditorApplication.isPlaying = false; |
| | 261 | | #else |
| | 262 | | Application.Quit(); |
| | 263 | | #endif |
| 0 | 264 | | } |
| | 265 | | } |
| | 266 | | } |