| | 1 | | using Cysharp.Threading.Tasks; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Configuration; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using DCL.Interface; |
| | 6 | | using DCL.Map; |
| | 7 | | using DCL.Providers; |
| | 8 | | using DCL.SettingsCommon; |
| | 9 | | using DCl.Social.Friends; |
| | 10 | | using DCL.Social.Friends; |
| | 11 | | using MainScripts.DCL.Controllers.HotScenes; |
| | 12 | | using DCLServices.WearablesCatalogService; |
| | 13 | | using MainScripts.DCL.Controllers.FriendsController; |
| | 14 | | using UnityEngine; |
| | 15 | | #if UNITY_EDITOR |
| | 16 | | using DG.Tweening; |
| | 17 | | #endif |
| | 18 | |
|
| | 19 | | namespace DCL |
| | 20 | | { |
| | 21 | | /// <summary> |
| | 22 | | /// This is the InitialScene entry point. |
| | 23 | | /// Most of the application subsystems should be initialized from this class Awake() event. |
| | 24 | | /// </summary> |
| | 25 | | public class Main : MonoBehaviour |
| | 26 | | { |
| | 27 | | [SerializeField] private bool disableSceneDependencies; |
| | 28 | |
|
| | 29 | | private HotScenesController hotScenesController; |
| | 30 | |
|
| | 31 | | private readonly DataStoreRef<DataStore_LoadingScreen> dataStoreLoadingScreen; |
| | 32 | | protected IKernelCommunication kernelCommunication; |
| | 33 | |
|
| | 34 | | private PerformanceMetricsController performanceMetricsController; |
| | 35 | |
|
| | 36 | | protected PluginSystem pluginSystem; |
| 0 | 37 | | public static Main i { get; private set; } |
| | 38 | |
|
| | 39 | | protected virtual void Awake() |
| | 40 | | { |
| 0 | 41 | | if (i != null) |
| | 42 | | { |
| 0 | 43 | | Utils.SafeDestroy(this); |
| 0 | 44 | | return; |
| | 45 | | } |
| | 46 | |
|
| 0 | 47 | | i = this; |
| | 48 | |
|
| 0 | 49 | | if (!disableSceneDependencies) |
| 0 | 50 | | InitializeSceneDependencies(); |
| | 51 | |
|
| | 52 | | #if UNITY_EDITOR |
| | 53 | |
|
| | 54 | | // Prevent warning when starting on unity editor mode |
| | 55 | | // TODO: Are we instantiating 500 different kinds of animations? |
| 0 | 56 | | DOTween.SetTweensCapacity(500, 50); |
| | 57 | | #endif |
| | 58 | |
|
| 0 | 59 | | Settings.CreateSharedInstance(new DefaultSettingsFactory()); |
| | 60 | |
|
| 0 | 61 | | if (!EnvironmentSettings.RUNNING_TESTS) |
| | 62 | | { |
| 0 | 63 | | SetupServices(); |
| 0 | 64 | | performanceMetricsController = new PerformanceMetricsController(); |
| | 65 | | } |
| | 66 | |
|
| | 67 | | #if UNITY_STANDALONE || UNITY_EDITOR |
| 0 | 68 | | Application.quitting += () => DataStore.i.common.isApplicationQuitting.Set(true); |
| | 69 | | #endif |
| | 70 | |
|
| 0 | 71 | | InitializeDataStore(); |
| 0 | 72 | | SetupPlugins(); |
| 0 | 73 | | InitializeCommunication(); |
| 0 | 74 | | } |
| | 75 | |
|
| | 76 | | protected virtual void Start() |
| | 77 | | { |
| | 78 | | // this event should be the last one to be executed after initialization |
| | 79 | | // it is used by the kernel to signal "EngineReady" or something like that |
| | 80 | | // to prevent race conditions like "SceneController is not an object", |
| | 81 | | // aka sending events before unity is ready |
| 0 | 82 | | WebInterface.SendSystemInfoReport(); |
| | 83 | |
|
| | 84 | | // We trigger the Decentraland logic once everything is initialized. |
| 0 | 85 | | WebInterface.StartDecentraland(); |
| 0 | 86 | | } |
| | 87 | |
|
| | 88 | | protected virtual void Update() |
| | 89 | | { |
| 0 | 90 | | performanceMetricsController?.Update(); |
| 0 | 91 | | } |
| | 92 | |
|
| | 93 | | protected virtual void InitializeDataStore() |
| | 94 | | { |
| 0 | 95 | | DataStore.i.textureConfig.gltfMaxSize.Set(TextureCompressionSettings.GLTF_TEX_MAX_SIZE_WEB); |
| 0 | 96 | | DataStore.i.textureConfig.generalMaxSize.Set(TextureCompressionSettings.GENERAL_TEX_MAX_SIZE_WEB); |
| 0 | 97 | | DataStore.i.avatarConfig.useHologramAvatar.Set(true); |
| 0 | 98 | | } |
| | 99 | |
|
| | 100 | | protected virtual void InitializeCommunication() |
| | 101 | | { |
| | 102 | | #if UNITY_WEBGL && !UNITY_EDITOR |
| | 103 | | Debug.Log("DCL Unity Build Version: " + DCL.Configuration.ApplicationSettings.version); |
| | 104 | |
|
| | 105 | | kernelCommunication = new NativeBridgeCommunication(Environment.i.world.sceneController); |
| | 106 | | #else |
| | 107 | |
|
| | 108 | | // TODO(Brian): Remove this branching once we finish migrating all tests out of the |
| | 109 | | // IntegrationTestSuite_Legacy base class. |
| 0 | 110 | | if (!EnvironmentSettings.RUNNING_TESTS) { kernelCommunication = new WebSocketCommunication(DebugConfigCompon |
| | 111 | | #endif |
| 0 | 112 | | } |
| | 113 | |
|
| | 114 | | protected virtual void SetupPlugins() |
| | 115 | | { |
| 0 | 116 | | pluginSystem = PluginSystemFactory.Create(); |
| 0 | 117 | | pluginSystem.Initialize(); |
| 0 | 118 | | } |
| | 119 | |
|
| | 120 | | protected virtual void SetupServices() |
| | 121 | | { |
| 0 | 122 | | var serviceLocator = ServiceLocatorFactory.CreateDefault(); |
| 0 | 123 | | serviceLocator.Register<IHotScenesController>(() => hotScenesController); |
| 0 | 124 | | Environment.Setup(serviceLocator); |
| 0 | 125 | | } |
| | 126 | |
|
| | 127 | | [RuntimeInitializeOnLoadMethod] |
| | 128 | | private static void RunOnStart() |
| | 129 | | { |
| 0 | 130 | | Application.wantsToQuit += ApplicationWantsToQuit; |
| 0 | 131 | | } |
| | 132 | |
|
| | 133 | | private static bool ApplicationWantsToQuit() |
| | 134 | | { |
| 0 | 135 | | if (i != null) |
| 0 | 136 | | i.Dispose(); |
| | 137 | |
|
| 0 | 138 | | return true; |
| | 139 | | } |
| | 140 | |
|
| | 141 | | protected virtual void Dispose() |
| | 142 | | { |
| 0 | 143 | | DataStore.i.common.isApplicationQuitting.Set(true); |
| 0 | 144 | | Settings.i.SaveSettings(); |
| | 145 | |
|
| 0 | 146 | | pluginSystem?.Dispose(); |
| | 147 | |
|
| 0 | 148 | | if (!EnvironmentSettings.RUNNING_TESTS) |
| 0 | 149 | | Environment.Dispose(); |
| | 150 | |
|
| 0 | 151 | | kernelCommunication?.Dispose(); |
| 0 | 152 | | } |
| | 153 | |
|
| | 154 | | protected virtual void InitializeSceneDependencies() |
| | 155 | | { |
| 0 | 156 | | gameObject.AddComponent<UserProfileController>(); |
| 0 | 157 | | gameObject.AddComponent<RenderingController>(); |
| 0 | 158 | | gameObject.AddComponent<WebInterfaceWearablesCatalogService>(); |
| 0 | 159 | | gameObject.AddComponent<WebInterfaceMinimapApiBridge>(); |
| 0 | 160 | | gameObject.AddComponent<MinimapMetadataController>(); |
| 0 | 161 | | gameObject.AddComponent<WebInterfaceFriendsApiBridge>(); |
| 0 | 162 | | hotScenesController = gameObject.AddComponent<HotScenesController>(); |
| 0 | 163 | | gameObject.AddComponent<MatrixInitializationBridge>(); |
| 0 | 164 | | gameObject.AddComponent<GIFProcessingBridge>(); |
| 0 | 165 | | gameObject.AddComponent<RenderProfileBridge>(); |
| 0 | 166 | | gameObject.AddComponent<AssetCatalogBridge>(); |
| 0 | 167 | | gameObject.AddComponent<ScreenSizeWatcher>(); |
| 0 | 168 | | gameObject.AddComponent<SceneControllerBridge>(); |
| | 169 | |
|
| 0 | 170 | | MainSceneFactory.CreateBridges(); |
| 0 | 171 | | MainSceneFactory.CreateMouseCatcher(); |
| 0 | 172 | | MainSceneFactory.CreatePlayerSystems(); |
| 0 | 173 | | CreateEnvironment(); |
| 0 | 174 | | MainSceneFactory.CreateAudioHandler(); |
| 0 | 175 | | MainSceneFactory.CreateHudController(); |
| 0 | 176 | | MainSceneFactory.CreateNavMap(); |
| 0 | 177 | | MainSceneFactory.CreateEventSystem(); |
| 0 | 178 | | } |
| | 179 | |
|
| | 180 | | protected virtual void CreateEnvironment() => |
| 0 | 181 | | MainSceneFactory.CreateEnvironment(); |
| | 182 | | } |
| | 183 | | } |