< Summary

Class:DCL.DebugConfigComponent
Assembly:DebugParameters
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/Debugging/DebugParameters/DebugConfigComponent.cs
Covered lines:0
Uncovered lines:91
Coverable lines:91
Total lines:275
Line coverage:0% (0 of 91)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DebugConfigComponent()0%2100%
Awake()0%12300%
Start()0%12300%
OnCommunicationReadyChangedValue(...)0%12300%
InitConfig()0%20400%
OnRendererStateChanged(...)0%2100%
OpenWebBrowser()0%4202000%
OnDestroy()0%2100%
QuitGame()0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Scripts/MainScripts/DCL/WorldRuntime/Debugging/DebugParameters/DebugConfigComponent.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using DCL.Components;
 4using UnityEditor;
 5using UnityEngine;
 6
 7namespace DCL
 8{
 9    public class DebugConfigComponent : MonoBehaviour
 10    {
 11        private static DebugConfigComponent sharedInstance;
 12
 13        public static DebugConfigComponent i
 14        {
 15            get
 16            {
 017                if (sharedInstance == null)
 018                    sharedInstance = FindObjectOfType<DebugConfigComponent>();
 19
 020                return sharedInstance;
 21            }
 022            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
 058        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
 070        public Vector2 startInCoords = new Vector2(-99, 109);
 71
 072        [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;
 078        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        {
 090            if (sharedInstance == null)
 091                sharedInstance = this;
 92
 093            DataStore.i.debugConfig.soloScene = debugConfig.soloScene;
 094            DataStore.i.debugConfig.soloSceneCoords = debugConfig.soloSceneCoords;
 095            DataStore.i.debugConfig.ignoreGlobalScenes = debugConfig.ignoreGlobalScenes;
 096            DataStore.i.debugConfig.msgStepByStep = debugConfig.msgStepByStep;
 097            DataStore.i.performance.multithreading.Set(multithreaded);
 098            if (disableGLTFDownloadThrottle) DataStore.i.performance.maxDownloads.Set(999);
 099            Texture.allowThreadedTextureCreation = multithreaded;
 0100        }
 101
 102        private void Start()
 103        {
 0104            lock (DataStore.i.wsCommunication.communicationReady)
 105            {
 0106                if (DataStore.i.wsCommunication.communicationReady.Get())
 107                {
 0108                    InitConfig();
 0109                }
 110                else
 111                {
 0112                    DataStore.i.wsCommunication.communicationReady.OnChange += OnCommunicationReadyChangedValue;
 113                }
 0114            }
 0115        }
 116
 117        private void OnCommunicationReadyChangedValue(bool newState, bool prevState)
 118        {
 0119            if (newState && !prevState)
 0120                InitConfig();
 121
 0122            DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChangedValue;
 0123        }
 124
 125        private void InitConfig()
 126        {
 0127            if (useCustomContentServer)
 128            {
 0129                RendereableAssetLoadHelper.useCustomContentServerUrl = true;
 0130                RendereableAssetLoadHelper.customContentServerUrl = customContentServerUrl;
 131            }
 132
 0133            if (openBrowserWhenStart)
 0134                OpenWebBrowser();
 135
 0136            if (runPerformanceMeterToolDuringLoading)
 137            {
 0138                CommonScriptableObjects.forcePerformanceMeter.Set(true);
 0139                performanceMeterController = new PerformanceMeterController();
 0140                performanceMeterController.StartSampling(999);
 0141                CommonScriptableObjects.rendererState.OnChange += OnRendererStateChanged;
 142            }
 0143        }
 144        private void OnRendererStateChanged(bool current, bool previous)
 145        {
 0146            CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged;
 0147            performanceMeterController.StopSampling();
 0148        }
 149
 150        private void OpenWebBrowser()
 151        {
 152#if (UNITY_EDITOR || UNITY_STANDALONE)
 0153            string baseUrl = "";
 0154            string debugString = "";
 155
 0156            if (baseUrlMode == BaseUrl.CUSTOM)
 0157                baseUrl = baseUrlCustom;
 158            else
 0159                baseUrl = "http://localhost:3000/?";
 160
 0161            switch (environment)
 162            {
 163                case Environment.USE_DEFAULT_FROM_URL:
 164                    break;
 165                case Environment.LOCAL:
 0166                    debugString = "DEBUG_MODE&";
 167
 0168                    break;
 169                case Environment.ZONE:
 0170                    debugString = "NETWORK=ropsten&";
 171
 0172                    break;
 173                case Environment.TODAY:
 0174                    debugString = "NETWORK=mainnet&";
 175
 0176                    break;
 177                case Environment.ORG:
 0178                    debugString = "NETWORK=mainnet&";
 179
 180                    break;
 181            }
 182
 0183            if (!string.IsNullOrEmpty(kernelVersion))
 184            {
 0185                debugString += $"kernel-version={kernelVersion}&";
 186            }
 187
 0188            if (forceLocalComms)
 189            {
 0190                debugString += "LOCAL_COMMS&";
 191            }
 192
 0193            if (allWearables)
 194            {
 0195                debugString += "ALL_WEARABLES&";
 196            }
 197
 0198            if (testWearables)
 199            {
 0200                debugString += "TEST_WEARABLES&";
 201            }
 202
 0203            if (enableTutorial)
 204            {
 0205                debugString += "RESET_TUTORIAL&";
 206            }
 207
 0208            if (soloScene)
 209            {
 0210                debugString += "LOS=0&";
 211            }
 212
 0213            if (builderInWorld)
 214            {
 0215                debugString += "ENABLE_BUILDER_IN_WORLD&";
 216            }
 217
 0218            if (disableAssetBundles)
 219            {
 0220                debugString += "DISABLE_ASSET_BUNDLES&DISABLE_WEARABLE_ASSET_BUNDLES&";
 221            }
 222
 0223            if (!string.IsNullOrEmpty(realm))
 224            {
 0225                debugString += $"realm={realm}&";
 226            }
 227
 0228            string debugPanelString = "";
 229
 0230            if (debugPanelMode == DebugPanel.Engine)
 231            {
 0232                debugPanelString = ENGINE_DEBUG_PANEL + "&";
 0233            }
 0234            else if (debugPanelMode == DebugPanel.Scene)
 235            {
 0236                debugPanelString = SCENE_DEBUG_PANEL + "&";
 237            }
 238
 0239            if (!webSocketSSL)
 240            {
 0241                if (baseUrl.Contains("play.decentraland.org"))
 242                {
 0243                    Debug.LogError(
 244                        "play.decentraland.org only works with WebSocket SSL, please change the base URL to play.decentr
 245
 0246                    QuitGame();
 247
 0248                    return;
 249                }
 250            }
 251            else
 252            {
 0253                Debug.Log(
 254                    "[REMINDER] To be able to connect with SSL you should start Chrome with the --ignore-certificate-err
 255            }
 256
 0257            Application.OpenURL(
 258                $"{baseUrl}{debugString}{debugPanelString}position={startInCoords.x}%2C{startInCoords.y}&ws={DataStore.i
 259#endif
 0260        }
 261
 0262        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
 0269            UnityEditor.EditorApplication.isPlaying = false;
 270#else
 271            Application.Quit();
 272#endif
 0273        }
 274    }
 275}