| | 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 | | public DebugConfig debugConfig; |
| | 12 | | public enum DebugPanel |
| | 13 | | { |
| | 14 | | Off, |
| | 15 | | Scene, |
| | 16 | | Engine |
| | 17 | | } |
| | 18 | |
|
| | 19 | | public enum BaseUrl |
| | 20 | | { |
| | 21 | | LOCAL_HOST, |
| | 22 | | CUSTOM, |
| | 23 | | } |
| | 24 | |
|
| | 25 | | public enum Environment |
| | 26 | | { |
| | 27 | | USE_DEFAULT_FROM_URL, |
| | 28 | | LOCAL, |
| | 29 | | ZONE, |
| | 30 | | TODAY, |
| | 31 | | ORG |
| | 32 | | } |
| | 33 | |
|
| | 34 | | private const string ENGINE_DEBUG_PANEL = "ENGINE_DEBUG_PANEL"; |
| | 35 | | private const string SCENE_DEBUG_PANEL = "SCENE_DEBUG_PANEL"; |
| | 36 | |
|
| | 37 | | public bool openBrowserWhenStart; |
| | 38 | |
|
| | 39 | | [Header("Kernel General Settings")] |
| | 40 | | public bool useCustomContentServer = false; |
| | 41 | |
|
| 0 | 42 | | public string customContentServerUrl = "http://localhost:1338/"; |
| | 43 | |
|
| | 44 | | [Space(10)] |
| | 45 | | public BaseUrl baseUrlMode; |
| | 46 | |
|
| | 47 | | public string baseUrlCustom; |
| | 48 | |
|
| | 49 | |
|
| | 50 | | [Space(10)] |
| | 51 | | public Environment environment; |
| | 52 | |
|
| | 53 | | [Tooltip("Set this field to force the realm (server). On the latin-american zone, recommended realms are fenrir- |
| | 54 | | public string realm; |
| | 55 | |
|
| 0 | 56 | | public Vector2 startInCoords = new Vector2(-99, 109); |
| | 57 | |
|
| | 58 | | [Header("Kernel Misc Settings")] |
| 0 | 59 | | public bool forceLocalComms = true; |
| | 60 | |
|
| | 61 | | public bool allWearables = false; |
| | 62 | | public bool testWearables = false; |
| | 63 | | public bool enableTutorial = false; |
| | 64 | | public bool builderInWorld = false; |
| 0 | 65 | | public bool soloScene = true; |
| | 66 | | public DebugPanel debugPanelMode = DebugPanel.Off; |
| | 67 | |
|
| | 68 | | private void Awake() |
| | 69 | | { |
| 0 | 70 | | DataStore.i.debugConfig.soloScene = debugConfig.soloScene; |
| 0 | 71 | | DataStore.i.debugConfig.soloSceneCoords = debugConfig.soloSceneCoords; |
| 0 | 72 | | DataStore.i.debugConfig.ignoreGlobalScenes = debugConfig.ignoreGlobalScenes; |
| 0 | 73 | | DataStore.i.debugConfig.msgStepByStep = debugConfig.msgStepByStep; |
| 0 | 74 | | } |
| | 75 | |
|
| | 76 | | private void Start() |
| | 77 | | { |
| 0 | 78 | | lock (DataStore.i.wsCommunication.communicationReady) |
| | 79 | | { |
| 0 | 80 | | if (DataStore.i.wsCommunication.communicationReady.Get()) |
| | 81 | | { |
| 0 | 82 | | InitConfig(); |
| 0 | 83 | | } |
| | 84 | | else |
| | 85 | | { |
| 0 | 86 | | DataStore.i.wsCommunication.communicationReady.OnChange += OnCommunicationReadyChangedValue; |
| | 87 | | } |
| 0 | 88 | | } |
| 0 | 89 | | } |
| | 90 | |
|
| | 91 | | private void OnCommunicationReadyChangedValue(bool newState, bool prevState) |
| | 92 | | { |
| 0 | 93 | | if (newState && !prevState) |
| 0 | 94 | | InitConfig(); |
| | 95 | |
|
| 0 | 96 | | DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChangedValue; |
| 0 | 97 | | } |
| | 98 | |
|
| | 99 | | private void InitConfig() |
| | 100 | | { |
| 0 | 101 | | if (useCustomContentServer) |
| | 102 | | { |
| 0 | 103 | | RendereableAssetLoadHelper.useCustomContentServerUrl = true; |
| 0 | 104 | | RendereableAssetLoadHelper.customContentServerUrl = customContentServerUrl; |
| | 105 | | } |
| | 106 | |
|
| 0 | 107 | | if (openBrowserWhenStart) |
| 0 | 108 | | OpenWebBrowser(); |
| 0 | 109 | | } |
| | 110 | |
|
| | 111 | | private void OpenWebBrowser() |
| | 112 | | { |
| | 113 | | #if (UNITY_EDITOR || UNITY_STANDALONE) |
| 0 | 114 | | string baseUrl = ""; |
| 0 | 115 | | string debugString = ""; |
| | 116 | |
|
| 0 | 117 | | if (baseUrlMode == BaseUrl.CUSTOM) |
| 0 | 118 | | baseUrl = baseUrlCustom; |
| | 119 | | else |
| 0 | 120 | | baseUrl = "http://localhost:3000/?"; |
| | 121 | |
|
| 0 | 122 | | switch (environment) |
| | 123 | | { |
| | 124 | | case Environment.USE_DEFAULT_FROM_URL: |
| | 125 | | break; |
| | 126 | | case Environment.LOCAL: |
| 0 | 127 | | debugString = "DEBUG_MODE&"; |
| 0 | 128 | | break; |
| | 129 | | case Environment.ZONE: |
| 0 | 130 | | debugString = "NETWORK=ropsten&"; |
| 0 | 131 | | break; |
| | 132 | | case Environment.TODAY: |
| 0 | 133 | | debugString = "NETWORK=mainnet&"; |
| 0 | 134 | | break; |
| | 135 | | case Environment.ORG: |
| 0 | 136 | | debugString = "NETWORK=mainnet&"; |
| | 137 | | break; |
| | 138 | | } |
| | 139 | |
|
| 0 | 140 | | if (forceLocalComms) |
| | 141 | | { |
| 0 | 142 | | debugString += "LOCAL_COMMS&"; |
| | 143 | | } |
| | 144 | |
|
| 0 | 145 | | if (allWearables) |
| | 146 | | { |
| 0 | 147 | | debugString += "ALL_WEARABLES&"; |
| | 148 | | } |
| | 149 | |
|
| 0 | 150 | | if (testWearables) |
| | 151 | | { |
| 0 | 152 | | debugString += "TEST_WEARABLES&"; |
| | 153 | | } |
| | 154 | |
|
| 0 | 155 | | if (enableTutorial) |
| | 156 | | { |
| 0 | 157 | | debugString += "RESET_TUTORIAL&"; |
| | 158 | | } |
| | 159 | |
|
| 0 | 160 | | if (soloScene) |
| | 161 | | { |
| 0 | 162 | | debugString += "LOS=0&"; |
| | 163 | | } |
| | 164 | |
|
| 0 | 165 | | if (builderInWorld) |
| | 166 | | { |
| 0 | 167 | | debugString += "ENABLE_BUILDER_IN_WORLD&"; |
| | 168 | | } |
| | 169 | |
|
| 0 | 170 | | if ( !string.IsNullOrEmpty(realm)) |
| | 171 | | { |
| 0 | 172 | | debugString += $"realm={realm}&"; |
| | 173 | | } |
| | 174 | |
|
| 0 | 175 | | string debugPanelString = ""; |
| | 176 | |
|
| 0 | 177 | | if (debugPanelMode == DebugPanel.Engine) |
| | 178 | | { |
| 0 | 179 | | debugPanelString = ENGINE_DEBUG_PANEL + "&"; |
| 0 | 180 | | } |
| 0 | 181 | | else if (debugPanelMode == DebugPanel.Scene) |
| | 182 | | { |
| 0 | 183 | | debugPanelString = SCENE_DEBUG_PANEL + "&"; |
| | 184 | | } |
| | 185 | |
|
| 0 | 186 | | Application.OpenURL( |
| | 187 | | $"{baseUrl}{debugString}{debugPanelString}position={startInCoords.x}%2C{startInCoords.y}&ws={DataStore.i |
| | 188 | | #endif |
| 0 | 189 | | } |
| | 190 | |
|
| | 191 | | private void OnDestroy() |
| | 192 | | { |
| 0 | 193 | | DataStore.i.wsCommunication.communicationReady.OnChange -= OnCommunicationReadyChangedValue; |
| 0 | 194 | | } |
| | 195 | | } |
| | 196 | | } |