| | 1 | | using System; |
| | 2 | | using DCL.Components; |
| | 3 | | using DCL.Controllers; |
| | 4 | | using DCL.Helpers; |
| | 5 | | using UnityEngine; |
| | 6 | | using UnityEngine.Serialization; |
| | 7 | |
|
| | 8 | | namespace DCL |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// This is the InitialScene entry point. |
| | 12 | | /// Most of the application subsystems should be initialized from this class Awake() event. |
| | 13 | | /// </summary> |
| | 14 | | public class Main : MonoBehaviour |
| | 15 | | { |
| 0 | 16 | | public static Main i { get; private set; } |
| | 17 | |
|
| | 18 | | public PoolableComponentFactory componentFactory; |
| | 19 | |
|
| | 20 | | private PerformanceMetricsController performanceMetricsController; |
| | 21 | | private IKernelCommunication kernelCommunication; |
| | 22 | |
|
| | 23 | | private PluginSystem pluginSystem; |
| | 24 | |
|
| | 25 | | protected virtual void Awake() |
| | 26 | | { |
| 123 | 27 | | if (i != null) |
| | 28 | | { |
| 0 | 29 | | Utils.SafeDestroy(this); |
| 0 | 30 | | return; |
| | 31 | | } |
| | 32 | |
|
| 123 | 33 | | i = this; |
| | 34 | |
|
| 123 | 35 | | if (!Configuration.EnvironmentSettings.RUNNING_TESTS) |
| | 36 | | { |
| 0 | 37 | | performanceMetricsController = new PerformanceMetricsController(); |
| 0 | 38 | | RenderProfileManifest.i.Initialize(); |
| 0 | 39 | | SetupEnvironment(); |
| | 40 | | } |
| | 41 | |
|
| 123 | 42 | | pluginSystem = new PluginSystem(); |
| | 43 | |
|
| | 44 | | #if UNITY_WEBGL && !UNITY_EDITOR |
| | 45 | | Debug.Log("DCL Unity Build Version: " + DCL.Configuration.ApplicationSettings.version); |
| | 46 | | Debug.unityLogger.logEnabled = false; |
| | 47 | |
|
| | 48 | | kernelCommunication = new NativeBridgeCommunication(Environment.i.world.sceneController); |
| | 49 | | #else |
| | 50 | | // TODO(Brian): Remove this branching once we finish migrating all tests out of the |
| | 51 | | // IntegrationTestSuite_Legacy base class. |
| 123 | 52 | | if (!Configuration.EnvironmentSettings.RUNNING_TESTS) |
| | 53 | | { |
| 0 | 54 | | kernelCommunication = new WebSocketCommunication(); |
| | 55 | | } |
| | 56 | | #endif |
| | 57 | |
|
| | 58 | | // TODO(Brian): This is a temporary fix to address elevators issue in the xmas event. |
| | 59 | | // We should re-enable this later as produces a performance regression. |
| 123 | 60 | | if (!Configuration.EnvironmentSettings.RUNNING_TESTS) |
| 0 | 61 | | Environment.i.platform.cullingController.SetAnimationCulling(false); |
| | 62 | |
|
| | 63 | | // this event should be the last one to be executed after initialization |
| | 64 | | // it is used by the kernel to signal "EngineReady" or something like that |
| | 65 | | // to prevent race conditions like "SceneController is not an object", |
| | 66 | | // aka sending events before unity is ready |
| 123 | 67 | | DCL.Interface.WebInterface.SendSystemInfoReport(); |
| | 68 | |
|
| | 69 | | // We trigger the Decentraland logic once everything is initialized. |
| 123 | 70 | | DCL.Interface.WebInterface.StartDecentraland(); |
| 123 | 71 | | } |
| | 72 | |
|
| | 73 | | protected virtual void SetupEnvironment() |
| | 74 | | { |
| 0 | 75 | | Environment.SetupWithBuilders( |
| | 76 | | messagingBuilder: MessagingContextBuilder, |
| | 77 | | platformBuilder: PlatformContextBuilder, |
| | 78 | | worldRuntimeBuilder: WorldRuntimeContextBuilder, |
| | 79 | | hudBuilder: HUDContextBuilder); |
| 0 | 80 | | } |
| | 81 | |
|
| 0 | 82 | | protected virtual MessagingContext MessagingContextBuilder() { return MessagingContextFactory.CreateDefault(); } |
| | 83 | |
|
| 0 | 84 | | protected virtual PlatformContext PlatformContextBuilder() { return PlatformContextFactory.CreateDefault(); } |
| | 85 | |
|
| 0 | 86 | | protected virtual WorldRuntimeContext WorldRuntimeContextBuilder() { return WorldRuntimeContextFactory.CreateDef |
| | 87 | |
|
| 0 | 88 | | protected virtual HUDContext HUDContextBuilder() { return HUDContextFactory.CreateDefault(); } |
| | 89 | |
|
| 246 | 90 | | private void Start() { Environment.i.world.sceneController.Start(); } |
| | 91 | |
|
| | 92 | | private void Update() |
| | 93 | | { |
| 21253 | 94 | | Environment.i.platform.Update(); |
| 21253 | 95 | | Environment.i.world.sceneController.Update(); |
| 21253 | 96 | | performanceMetricsController?.Update(); |
| 21253 | 97 | | pluginSystem?.Update(); |
| 21253 | 98 | | } |
| | 99 | |
|
| | 100 | | private void LateUpdate() |
| | 101 | | { |
| 21252 | 102 | | Environment.i.world.sceneController.LateUpdate(); |
| 21252 | 103 | | pluginSystem?.LateUpdate(); |
| 21252 | 104 | | } |
| | 105 | |
|
| | 106 | | protected virtual void OnDestroy() |
| | 107 | | { |
| 122 | 108 | | if (!Configuration.EnvironmentSettings.RUNNING_TESTS) |
| 0 | 109 | | Environment.Dispose(); |
| 122 | 110 | | pluginSystem?.OnDestroy(); |
| 122 | 111 | | kernelCommunication?.Dispose(); |
| 0 | 112 | | } |
| | 113 | |
|
| 6756 | 114 | | private void OnGUI() { pluginSystem?.OnGUI(); } |
| | 115 | | } |
| | 116 | | } |