| | 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 | | public static DebugConfigComponent i |
| | 13 | | { |
| | 14 | | get |
| | 15 | | { |
| 0 | 16 | | if (sharedInstance == null) |
| 0 | 17 | | sharedInstance = FindObjectOfType<DebugConfigComponent>(); |
| 0 | 18 | | return sharedInstance; |
| | 19 | | } |
| 0 | 20 | | private set => sharedInstance = value; |
| | 21 | | } |
| | 22 | |
|
| | 23 | | public DebugConfig debugConfig; |
| | 24 | |
|
| | 25 | | public enum DebugPanel |
| | 26 | | { |
| | 27 | | Off, |
| | 28 | | Scene, |
| | 29 | | Engine |
| | 30 | | } |
| | 31 | |
|
| | 32 | | public enum BaseUrl |
| | 33 | | { |
| | 34 | | LOCAL_HOST, |
| | 35 | | CUSTOM, |
| | 36 | | } |
| | 37 | |
|
| | 38 | | public enum Environment |
| | 39 | | { |
| | 40 | | USE_DEFAULT_FROM_URL, |
| | 41 | | LOCAL, |
| | 42 | | ZONE, |
| | 43 | | TODAY, |
| | 44 | | ORG |
| | 45 | | } |
| | 46 | |
|
| | 47 | | private const string ENGINE_DEBUG_PANEL = "ENGINE_DEBUG_PANEL"; |
| | 48 | | private const string SCENE_DEBUG_PANEL = "SCENE_DEBUG_PANEL"; |
| | 49 | |
|
| | 50 | | [Header("General Settings")] |
| | 51 | | public bool openBrowserWhenStart; |
| | 52 | | public bool webSocketSSL = false; |
| | 53 | |
|
| | 54 | | [Header("Kernel General Settings")] |
| | 55 | | public string kernelVersion; |
| | 56 | | public bool useCustomContentServer = false; |
| | 57 | |
|
| 0 | 58 | | public string customContentServerUrl = "http://localhost:1338/"; |
| | 59 | |
|
| | 60 | | [Space(10)] |
| | 61 | | public BaseUrl baseUrlMode; |
| | 62 | |
|
| | 63 | | public string baseUrlCustom; |
| | 64 | |
|
| | 65 | | [Space(10)] |
| | 66 | | public Environment environment; |
| | 67 | |
|
| | 68 | | [Tooltip("Set this field to force the realm (server). On the latin-american zone, recommended realms are fenrir- |
| | 69 | | public string realm; |
| | 70 | |
|
| 0 | 71 | | public Vector2 startInCoords = new Vector2(-99, 109); |
| | 72 | |
|
| | 73 | | [Header("Kernel Misc Settings")] |
| 0 | 74 | | public bool forceLocalComms = true; |
| | 75 | |
|
| | 76 | | public bool allWearables = false; |
| | 77 | | public bool testWearables = false; |
| | 78 | | public bool enableTutorial = false; |
| | 79 | | public bool builderInWorld = false; |
| 0 | 80 | | public bool soloScene = true; |
| | 81 | | public bool multithreaded = false; |
| | 82 | | public DebugPanel debugPanelMode = DebugPanel.Off; |
| | 83 | |
|
| | 84 | | private void Awake() |
| | 85 | | { |
| 0 | 86 | | if (sharedInstance == null) |
| 0 | 87 | | sharedInstance = this; |
| | 88 | |
|
| 0 | 89 | | DataStore.i.debugConfig.soloScene = debugConfig.soloScene; |
| 0 | 90 | | DataStore.i.debugConfig.soloSceneCoords = debugConfig.soloSceneCoords; |
| 0 | 91 | | DataStore.i.debugConfig.ignoreGlobalScenes = debugConfig.ignoreGlobalScenes; |
| 0 | 92 | | DataStore.i.debugConfig.msgStepByStep = debugConfig.msgStepByStep; |
| 0 | 93 | | DataStore.i.performance.multithreading.Set(multithreaded); |
| 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 (openBrowserWhenStart) |
| 0 | 129 | | OpenWebBrowser(); |
| 0 | 130 | | } |
| | 131 | |
|
| | 132 | | private void OpenWebBrowser() |
| | 133 | | { |
| | 134 | | #if (UNITY_EDITOR || UNITY_STANDALONE) |
| 0 | 135 | | string baseUrl = ""; |
| 0 | 136 | | string debugString = ""; |
| | 137 | |
|
| 0 | 138 | | if (baseUrlMode == BaseUrl.CUSTOM) |
| 0 | 139 | | baseUrl = baseUrlCustom; |
| | 140 | | else |
| 0 | 141 | | baseUrl = "http://localhost:3000/?"; |
| | 142 | |
|
| 0 | 143 | | switch (environment) |
| | 144 | | { |
| | 145 | | case Environment.USE_DEFAULT_FROM_URL: |
| | 146 | | break; |
| | 147 | | case Environment.LOCAL: |
| 0 | 148 | | debugString = "DEBUG_MODE&"; |
| 0 | 149 | | break; |
| | 150 | | case Environment.ZONE: |
| 0 | 151 | | debugString = "NETWORK=ropsten&"; |
| 0 | 152 | | break; |
| | 153 | | case Environment.TODAY: |
| 0 | 154 | | debugString = "NETWORK=mainnet&"; |
| 0 | 155 | | break; |
| | 156 | | case Environment.ORG: |
| 0 | 157 | | debugString = "NETWORK=mainnet&"; |
| | 158 | | break; |
| | 159 | | } |
| | 160 | |
|
| 0 | 161 | | if (!string.IsNullOrEmpty(kernelVersion)) |
| | 162 | | { |
| 0 | 163 | | debugString += $"kernel-version={kernelVersion}&"; |
| | 164 | | } |
| | 165 | |
|
| 0 | 166 | | if (forceLocalComms) |
| | 167 | | { |
| 0 | 168 | | debugString += "LOCAL_COMMS&"; |
| | 169 | | } |
| | 170 | |
|
| 0 | 171 | | if (allWearables) |
| | 172 | | { |
| 0 | 173 | | debugString += "ALL_WEARABLES&"; |
| | 174 | | } |
| | 175 | |
|
| 0 | 176 | | if (testWearables) |
| | 177 | | { |
| 0 | 178 | | debugString += "TEST_WEARABLES&"; |
| | 179 | | } |
| | 180 | |
|
| 0 | 181 | | if (enableTutorial) |
| | 182 | | { |
| 0 | 183 | | debugString += "RESET_TUTORIAL&"; |
| | 184 | | } |
| | 185 | |
|
| 0 | 186 | | if (soloScene) |
| | 187 | | { |
| 0 | 188 | | debugString += "LOS=0&"; |
| | 189 | | } |
| | 190 | |
|
| 0 | 191 | | if (builderInWorld) |
| | 192 | | { |
| 0 | 193 | | debugString += "ENABLE_BUILDER_IN_WORLD&"; |
| | 194 | | } |
| | 195 | |
|
| 0 | 196 | | if (!string.IsNullOrEmpty(realm)) |
| | 197 | | { |
| 0 | 198 | | debugString += $"realm={realm}&"; |
| | 199 | | } |
| | 200 | |
|
| 0 | 201 | | string debugPanelString = ""; |
| | 202 | |
|
| 0 | 203 | | if (debugPanelMode == DebugPanel.Engine) |
| | 204 | | { |
| 0 | 205 | | debugPanelString = ENGINE_DEBUG_PANEL + "&"; |
| 0 | 206 | | } |
| 0 | 207 | | else if (debugPanelMode == DebugPanel.Scene) |
| | 208 | | { |
| 0 | 209 | | debugPanelString = SCENE_DEBUG_PANEL + "&"; |
| | 210 | | } |
| | 211 | |
|
| 0 | 212 | | if (!webSocketSSL) |
| | 213 | | { |
| 0 | 214 | | if (baseUrl.Contains("play.decentraland.org")) |
| | 215 | | { |
| 0 | 216 | | Debug.LogError("play.decentraland.org only works with WebSocket SSL, please change the base URL to p |
| 0 | 217 | | QuitGame(); |
| 0 | 218 | | return; |
| | 219 | | } |
| | 220 | | } |
| | 221 | | else |
| | 222 | | { |
| 0 | 223 | | Debug.Log("[REMINDER] To be able to connect with SSL you should start Chrome with the --ignore-certifica |
| | 224 | | } |
| | 225 | |
|
| 0 | 226 | | Application.OpenURL( |
| | 227 | | $"{baseUrl}{debugString}{debugPanelString}position={startInCoords.x}%2C{startInCoords.y}&ws={DataStore.i |
| | 228 | | #endif |
| 0 | 229 | | } |
| | 230 | |
|
| 0 | 231 | | private void OnDestroy() { DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChange |
| | 232 | |
|
| | 233 | | private void QuitGame() |
| | 234 | | { |
| | 235 | | #if UNITY_EDITOR |
| | 236 | | // Application.Quit() does not work in the editor so |
| | 237 | | // UnityEditor.EditorApplication.isPlaying need to be set to false to end the game |
| 0 | 238 | | UnityEditor.EditorApplication.isPlaying = false; |
| | 239 | | #else |
| | 240 | | Application.Quit(); |
| | 241 | | #endif |
| 0 | 242 | | } |
| | 243 | | } |
| | 244 | | } |