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