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