| | 1 | | using System.Collections.Generic; |
| | 2 | | using DCL.Builder; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.SocialPlatforms.Impl; |
| | 5 | |
|
| | 6 | | namespace DCL |
| | 7 | | { |
| | 8 | | public static class MainSceneFactory |
| | 9 | | { |
| | 10 | | public static List<GameObject> CreatePlayerSystems() |
| | 11 | | { |
| 592 | 12 | | List<GameObject> result = new List<GameObject>(); |
| 592 | 13 | | GameObject playerGo = LoadAndInstantiate("Player"); |
| 592 | 14 | | var playerReferences = playerGo.GetComponent<PlayerReferences>(); |
| 592 | 15 | | SceneReferences.i.playerAvatarController = playerReferences.avatarController; |
| 592 | 16 | | SceneReferences.i.biwCameraParent = playerReferences.biwCameraRoot; |
| 592 | 17 | | SceneReferences.i.inputController = playerReferences.inputController; |
| 592 | 18 | | SceneReferences.i.cursorCanvas = playerReferences.cursorCanvas; |
| 592 | 19 | | SceneReferences.i.cameraController = playerReferences.cameraController; |
| 592 | 20 | | SceneReferences.i.mainCamera = playerReferences.mainCamera; |
| 592 | 21 | | SceneReferences.i.thirdPersonCamera = playerReferences.thirdPersonCamera; |
| 592 | 22 | | SceneReferences.i.firstPersonCamera = playerReferences.firstPersonCamera; |
| | 23 | |
|
| | 24 | | // Why we don't just add the playerGo? |
| | 25 | | // This happens because the characterController reparents itself. |
| | 26 | | // (and any of our systems may do this as well). |
| 592 | 27 | | result.Add( playerReferences.cursorCanvas.gameObject ); |
| 592 | 28 | | result.Add( playerReferences.cameraController.gameObject ); |
| 592 | 29 | | result.Add( playerReferences.inputController.gameObject ); |
| 592 | 30 | | result.Add( playerReferences.avatarController.gameObject ); |
| 592 | 31 | | result.Add( playerGo ); |
| | 32 | |
|
| 592 | 33 | | return result; |
| | 34 | | } |
| | 35 | |
|
| | 36 | | public static GameObject CreateMouseCatcher() |
| | 37 | | { |
| 58 | 38 | | GameObject result = LoadAndInstantiate("MouseCatcher"); |
| 58 | 39 | | MouseCatcher mouseCatcher = result.GetComponent<MouseCatcher>(); |
| 58 | 40 | | SceneReferences.i.mouseCatcher = mouseCatcher; |
| 58 | 41 | | return result; |
| | 42 | | } |
| | 43 | |
|
| 52 | 44 | | public static GameObject CreateHudController() => LoadAndInstantiate("HUDController"); |
| | 45 | |
|
| 52 | 46 | | public static GameObject CreateAudioHandler() => LoadAndInstantiate("HUDAudioHandler"); |
| | 47 | |
|
| 54 | 48 | | public static GameObject CreateNavMap() => LoadAndInstantiate("NavMap"); |
| | 49 | |
|
| | 50 | | public static GameObject CreateEnvironment(string prefabPath = "Environment") |
| | 51 | | { |
| 143 | 52 | | GameObject result = LoadAndInstantiate(prefabPath); |
| 143 | 53 | | var env = result.GetComponent<EnvironmentReferences>(); |
| 143 | 54 | | SceneReferences.i.environmentLight = env.environmentLight; |
| 143 | 55 | | SceneReferences.i.postProcessVolume = env.postProcessVolume; |
| 143 | 56 | | SceneReferences.i.groundVisual = env.ground; |
| 143 | 57 | | return result; |
| | 58 | | } |
| | 59 | |
|
| | 60 | | public static GameObject CreateBridges() |
| | 61 | | { |
| 55 | 62 | | if (SceneReferences.i.bridgeGameObject == null) |
| | 63 | | { |
| 53 | 64 | | var bridges = LoadAndInstantiate("Bridges"); |
| 53 | 65 | | SceneReferences.i.bridgeGameObject = bridges; |
| 53 | 66 | | return bridges; |
| | 67 | | } |
| | 68 | |
|
| 2 | 69 | | return SceneReferences.i.bridgeGameObject; |
| | 70 | | } |
| | 71 | |
|
| 126 | 72 | | public static GameObject CreateEventSystem() => LoadAndInstantiate("EventSystem"); |
| | 73 | |
|
| | 74 | |
|
| | 75 | | public static BuilderInWorldBridge CreateBuilderInWorldBridge(GameObject gameObject = null) |
| | 76 | | { |
| 38 | 77 | | if (gameObject == null) |
| 38 | 78 | | gameObject = new GameObject("BuilderInWorldBridge"); |
| | 79 | |
|
| 38 | 80 | | var instance = gameObject.AddComponent<BuilderInWorldBridge>(); |
| 38 | 81 | | SceneReferences.i.biwBridgeGameObject = instance.gameObject; |
| 38 | 82 | | return instance; |
| | 83 | | } |
| | 84 | |
|
| | 85 | | private static GameObject LoadAndInstantiate(string name) |
| | 86 | | { |
| 1130 | 87 | | GameObject instance = UnityEngine.Object.Instantiate(Resources.Load(name)) as GameObject; |
| 1130 | 88 | | instance.name = name; |
| 1130 | 89 | | return instance; |
| | 90 | | } |
| | 91 | | } |
| | 92 | | } |