< 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:95
Coverable lines:95
Total lines:266
Line coverage:0% (0 of 95)
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%3801900%
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 UnityEngine;
 5
 6namespace DCL
 7{
 8    public class DebugConfigComponent : MonoBehaviour
 9    {
 10        private static DebugConfigComponent sharedInstance;
 11
 12        public static DebugConfigComponent i
 13        {
 14            get
 15            {
 016                if (sharedInstance == null)
 017                    sharedInstance = FindObjectOfType<DebugConfigComponent>();
 18
 019                return sharedInstance;
 20            }
 021            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
 053        public string customContentServerUrl = "http://localhost:1338/";
 54
 55        [Space(10)] public BaseUrl baseUrlMode = BaseUrl.ZONE;
 56        [DrawIf("baseUrlMode", BaseUrl.CUSTOM)]
 057        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
 065        public Vector2 startInCoords = new Vector2(-99, 109);
 66
 067        [Header("Kernel Misc Settings")] public bool forceLocalComms = true;
 68
 69        public bool enableTutorial = false;
 70        public bool builderInWorld = false;
 071        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        {
 085            if (sharedInstance == null)
 086                sharedInstance = this;
 87
 088            DataStore.i.debugConfig.soloScene = debugConfig.soloScene;
 089            DataStore.i.debugConfig.soloSceneCoords = debugConfig.soloSceneCoords;
 090            DataStore.i.debugConfig.ignoreGlobalScenes = debugConfig.ignoreGlobalScenes;
 091            DataStore.i.debugConfig.msgStepByStep = debugConfig.msgStepByStep;
 092            DataStore.i.performance.multithreading.Set(multithreaded);
 093            if (disableGLTFDownloadThrottle) DataStore.i.performance.maxDownloads.Set(999);
 094            Texture.allowThreadedTextureCreation = multithreaded;
 095        }
 96
 97        private void Start()
 98        {
 099            lock (DataStore.i.wsCommunication.communicationReady)
 100            {
 0101                if (DataStore.i.wsCommunication.communicationReady.Get())
 102                {
 0103                    InitConfig();
 0104                }
 105                else
 106                {
 0107                    DataStore.i.wsCommunication.communicationReady.OnChange += OnCommunicationReadyChangedValue;
 108                }
 0109            }
 0110        }
 111
 112        private void OnCommunicationReadyChangedValue(bool newState, bool prevState)
 113        {
 0114            if (newState && !prevState)
 0115                InitConfig();
 116
 0117            DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChangedValue;
 0118        }
 119
 120        private void InitConfig()
 121        {
 0122            if (useCustomContentServer)
 123            {
 0124                RendereableAssetLoadHelper.useCustomContentServerUrl = true;
 0125                RendereableAssetLoadHelper.customContentServerUrl = customContentServerUrl;
 126            }
 127
 0128            if (OpenBrowserOnStart)
 0129                OpenWebBrowser();
 130
 0131            if (runPerformanceMeterToolDuringLoading)
 132            {
 0133                CommonScriptableObjects.forcePerformanceMeter.Set(true);
 0134                performanceMeterController = new PerformanceMeterController();
 0135                performanceMeterController.StartSampling(999);
 0136                CommonScriptableObjects.rendererState.OnChange += OnRendererStateChanged;
 137            }
 0138        }
 139        private void OnRendererStateChanged(bool current, bool previous)
 140        {
 0141            CommonScriptableObjects.rendererState.OnChange -= OnRendererStateChanged;
 0142            performanceMeterController.StopSampling();
 0143        }
 144
 145        private void OpenWebBrowser()
 146        {
 147#if (UNITY_EDITOR || UNITY_STANDALONE)
 0148            string baseUrl = "";
 0149            string debugString = "";
 150
 0151            if (baseUrlMode.Equals(BaseUrl.CUSTOM))
 152            {
 0153                baseUrl = this.customURL;
 0154                if (string.IsNullOrEmpty(this.customURL))
 155                {
 0156                    Debug.LogError("Custom url cannot be empty");
 0157                    QuitGame();
 0158                    return;
 159                }
 160            }
 0161            else if (baseUrlMode.Equals(BaseUrl.LOCAL_HOST))
 162            {
 0163                baseUrl = "http://localhost:3000/?";
 0164            }
 0165            else if (baseUrlMode.Equals(BaseUrl.ORG))
 166            {
 0167                baseUrl = "http://play.decentraland.org/?";
 0168                if (!webSocketSSL)
 169                {
 0170                    Debug.LogError(
 171                        "play.decentraland.org only works with WebSocket SSL, please change the base URL to play.decentr
 0172                    QuitGame();
 0173                    return;
 174                }
 175            }
 176            else
 177            {
 0178                baseUrl = "http://play.decentraland.zone/?";
 179            }
 180
 0181            switch (network)
 182            {
 183                case Network.GOERLI:
 0184                    debugString = "NETWORK=goerli&";
 0185                    break;
 186                case Network.MAINNET:
 0187                    debugString = "NETWORK=mainnet&";
 188                    break;
 189            }
 190
 0191            if (!string.IsNullOrEmpty(kernelVersion))
 192            {
 0193                debugString += $"kernel-version={kernelVersion}&";
 194            }
 195
 0196            if (forceLocalComms)
 197            {
 0198                debugString += "LOCAL_COMMS&";
 199            }
 200
 0201            if (enableTutorial)
 202            {
 0203                debugString += "RESET_TUTORIAL&";
 204            }
 205
 0206            if (soloScene)
 207            {
 0208                debugString += "LOS=0&";
 209            }
 210
 0211            if (builderInWorld)
 212            {
 0213                debugString += "ENABLE_BUILDER_IN_WORLD&";
 214            }
 215
 0216            if (disableAssetBundles)
 217            {
 0218                debugString += "DISABLE_ASSET_BUNDLES&DISABLE_WEARABLE_ASSET_BUNDLES&";
 219            }
 220
 0221            if (enableDebugMode)
 222            {
 0223                debugString += "DEBUG_MODE&";
 224            }
 225
 0226            if (!string.IsNullOrEmpty(realm))
 227            {
 0228                debugString += $"realm={realm}&";
 229            }
 230
 0231            string debugPanelString = "";
 232
 0233            if (debugPanelMode == DebugPanel.Engine)
 234            {
 0235                debugPanelString = "ENGINE_DEBUG_PANEL&";
 0236            }
 0237            else if (debugPanelMode == DebugPanel.Scene)
 238            {
 0239                debugPanelString = "SCENE_DEBUG_PANEL&";
 240            }
 241
 0242            if (webSocketSSL)
 243            {
 0244                Debug.Log(
 245                    "[REMINDER] To be able to connect with SSL you should start Chrome with the --ignore-certificate-err
 246            }
 247
 0248            Application.OpenURL(
 249                $"{baseUrl}{debugString}{debugPanelString}position={startInCoords.x}%2C{startInCoords.y}&ws={DataStore.i
 250#endif
 0251        }
 252
 0253        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
 0260            UnityEditor.EditorApplication.isPlaying = false;
 261#else
 262            Application.Quit();
 263#endif
 0264        }
 265    }
 266}