| | 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 | | public DebugConfig debugConfig; |
| | 21 | |
|
| | 22 | | private PerformanceMetricsController performanceMetricsController; |
| | 23 | | private EntryPoint_World worldEntryPoint; |
| | 24 | |
|
| | 25 | | void Awake() |
| | 26 | | { |
| 105 | 27 | | if (i != null) |
| | 28 | | { |
| 0 | 29 | | Utils.SafeDestroy(this); |
| 0 | 30 | | return; |
| | 31 | | } |
| | 32 | |
|
| 105 | 33 | | i = this; |
| | 34 | |
|
| 105 | 35 | | DataStore.i.debugConfig.soloScene = debugConfig.soloScene; |
| 105 | 36 | | DataStore.i.debugConfig.soloSceneCoords = debugConfig.soloSceneCoords; |
| 105 | 37 | | DataStore.i.debugConfig.ignoreGlobalScenes = debugConfig.ignoreGlobalScenes; |
| 105 | 38 | | DataStore.i.debugConfig.msgStepByStep = debugConfig.msgStepByStep; |
| | 39 | |
|
| 105 | 40 | | if (!Configuration.EnvironmentSettings.RUNNING_TESTS) |
| | 41 | | { |
| 0 | 42 | | performanceMetricsController = new PerformanceMetricsController(); |
| 0 | 43 | | RenderProfileManifest.i.Initialize(); |
| 0 | 44 | | SetupEnvironment(); |
| | 45 | | } |
| | 46 | |
|
| 105 | 47 | | DCL.Interface.WebInterface.SendSystemInfoReport(); |
| | 48 | |
|
| | 49 | | #if !UNITY_EDITOR |
| | 50 | | Debug.Log("DCL Unity Build Version: " + DCL.Configuration.ApplicationSettings.version); |
| | 51 | | Debug.unityLogger.logEnabled = false; |
| | 52 | |
|
| | 53 | | worldEntryPoint = new EntryPoint_World(Environment.i.world.sceneController); |
| | 54 | | #endif |
| | 55 | |
|
| | 56 | | // TODO(Brian): This is a temporary fix to address elevators issue in the xmas event. |
| | 57 | | // We should re-enable this later as produces a performance regression. |
| 105 | 58 | | if (!Configuration.EnvironmentSettings.RUNNING_TESTS) |
| 0 | 59 | | Environment.i.platform.cullingController.SetAnimationCulling(false); |
| 105 | 60 | | } |
| | 61 | |
|
| | 62 | | protected virtual void SetupEnvironment() |
| | 63 | | { |
| 0 | 64 | | Environment.SetupWithBuilders( |
| | 65 | | messagingBuilder: MessagingContextBuilder, |
| | 66 | | platformBuilder: PlatformContextBuilder, |
| | 67 | | worldRuntimeBuilder: WorldRuntimeContextBuilder, |
| | 68 | | hudBuilder: HUDContextBuilder); |
| 0 | 69 | | } |
| | 70 | | protected virtual MessagingContext MessagingContextBuilder() |
| | 71 | | { |
| 0 | 72 | | return MessagingContextFactory.CreateDefault(); |
| | 73 | | } |
| | 74 | | protected virtual PlatformContext PlatformContextBuilder() |
| | 75 | | { |
| 0 | 76 | | return PlatformContextFactory.CreateDefault(); |
| | 77 | | } |
| | 78 | | protected virtual WorldRuntimeContext WorldRuntimeContextBuilder() |
| | 79 | | { |
| 0 | 80 | | return WorldRuntimeContextFactory.CreateDefault(componentFactory); |
| | 81 | | } |
| | 82 | | protected virtual HUDContext HUDContextBuilder() |
| | 83 | | { |
| 0 | 84 | | return HUDContextFactory.CreateDefault(); |
| | 85 | | } |
| 210 | 86 | | private void Start() { Environment.i.world.sceneController.Start(); } |
| | 87 | |
|
| | 88 | | private void Update() |
| | 89 | | { |
| 13948 | 90 | | Environment.i.platform.idleChecker.Update(); |
| 13948 | 91 | | Environment.i.world.sceneController.Update(); |
| 13948 | 92 | | performanceMetricsController?.Update(); |
| 0 | 93 | | } |
| | 94 | |
|
| 27894 | 95 | | private void LateUpdate() { Environment.i.world.sceneController.LateUpdate(); } |
| | 96 | |
|
| | 97 | | private void OnDestroy() |
| | 98 | | { |
| 104 | 99 | | if (!Configuration.EnvironmentSettings.RUNNING_TESTS) |
| 0 | 100 | | Environment.Dispose(); |
| 104 | 101 | | } |
| | 102 | |
|
| | 103 | | #region RuntimeMessagingBridge |
| | 104 | |
|
| 0 | 105 | | public void LoadParcelScenes(string payload) { Environment.i.world.sceneController.LoadParcelScenes(payload); } |
| | 106 | |
|
| 0 | 107 | | public void SendSceneMessage(string payload) { Environment.i.world.sceneController.SendSceneMessage(payload); } |
| | 108 | |
|
| 0 | 109 | | public void UnloadScene(string sceneId) { Environment.i.world.sceneController.UnloadScene(sceneId); } |
| | 110 | |
|
| 0 | 111 | | public void CreateGlobalScene(string payload) { Environment.i.world.sceneController.CreateGlobalScene(payload); |
| | 112 | |
|
| 0 | 113 | | public void UpdateParcelScenes(string payload) { Environment.i.world.sceneController.UpdateParcelScenes(payload) |
| | 114 | |
|
| | 115 | | #endregion |
| | 116 | |
|
| 0 | 117 | | public void BuilderReady() { UnityEngine.SceneManagement.SceneManager.LoadScene("BuilderScene", UnityEngine.Scen |
| | 118 | | } |
| | 119 | | } |