| | 1 | | using System.Collections; |
| | 2 | | using System.Collections.Generic; |
| | 3 | | using DCL.Builder; |
| | 4 | | using DCL.Camera; |
| | 5 | | using DCL.CameraTool; |
| | 6 | | using DCL.Configuration; |
| | 7 | | using DCL.Controllers; |
| | 8 | | using DCL.Helpers; |
| | 9 | | using UnityEngine; |
| | 10 | |
|
| | 11 | | namespace DCL.Builder |
| | 12 | | { |
| | 13 | | public class CameraController : ICameraController |
| | 14 | | { |
| 5 | 15 | | private float initialEagleCameraHeight = 10f; |
| 5 | 16 | | private float initialEagleCameraDistance = 10f; |
| | 17 | |
|
| | 18 | | private CameraMode.ModeId avatarCameraModeBeforeEditing; |
| | 19 | | private Camera.CameraController cameraController; |
| | 20 | | internal IFreeCameraMovement freeCameraController; |
| | 21 | | internal IScreenshotCameraController screenshotCameraController; |
| | 22 | | internal IContext context; |
| | 23 | | internal Texture2D lastScreenshot; |
| | 24 | |
|
| | 25 | | internal Vector3 initialCameraPosition; |
| | 26 | | internal Vector3 initialPointToLookAt; |
| | 27 | |
|
| | 28 | | public void Initialize(IContext context) |
| | 29 | | { |
| 5 | 30 | | this.context = context; |
| 5 | 31 | | if (context.sceneReferences.cameraController != null) |
| | 32 | | { |
| 0 | 33 | | if (context.sceneReferences.cameraController.GetComponent<Camera.CameraController>().TryGetCameraStateBy |
| 0 | 34 | | freeCameraController = (FreeCameraMovement) cameraState; |
| | 35 | |
|
| 0 | 36 | | cameraController = context.sceneReferences.cameraController.GetComponent<Camera.CameraController>(); |
| | 37 | | } |
| | 38 | |
|
| 5 | 39 | | initialEagleCameraHeight = context.editorContext.godModeDynamicVariablesAsset.initialEagleCameraHeight; |
| 5 | 40 | | initialEagleCameraDistance = context.editorContext.godModeDynamicVariablesAsset.initialEagleCameraDistance; |
| | 41 | |
|
| 5 | 42 | | screenshotCameraController = new ScreenshotCameraController(); |
| 5 | 43 | | screenshotCameraController.Init(context); |
| 5 | 44 | | } |
| | 45 | |
|
| | 46 | | public void Dispose() |
| | 47 | | { |
| 5 | 48 | | DeactivateCamera(); |
| 5 | 49 | | screenshotCameraController.Dispose(); |
| 5 | 50 | | } |
| | 51 | |
|
| | 52 | | public void TakeSceneScreenshot(IScreenshotCameraController.OnSnapshotsReady onSuccess) |
| | 53 | | { |
| 1 | 54 | | screenshotCameraController.TakeSceneScreenshot(onSuccess); |
| 1 | 55 | | } |
| | 56 | |
|
| | 57 | | public void TakeSceneScreenshot(Vector3 camPosition, Vector3 pointToLookAt, int width, int height, IScreenshotCa |
| | 58 | | { |
| 1 | 59 | | screenshotCameraController.TakeSceneScreenshot(camPosition,pointToLookAt,width,height,onSuccess); |
| 1 | 60 | | } |
| | 61 | |
|
| | 62 | | public void TakeSceneAerialScreenshot(IParcelScene parcelScene, IScreenshotCameraController.OnSnapshotsReady onS |
| | 63 | | { |
| 1 | 64 | | screenshotCameraController.TakeSceneAerialScreenshot(parcelScene,onSuccess); |
| 1 | 65 | | } |
| | 66 | |
|
| | 67 | | public void TakeSceneScreenshotFromResetPosition(IScreenshotCameraController.OnSnapshotsReady onSuccess) |
| | 68 | | { |
| 1 | 69 | | screenshotCameraController.TakeSceneScreenshot(initialCameraPosition,initialPointToLookAt,onSuccess); |
| 1 | 70 | | } |
| | 71 | |
|
| | 72 | | public void ActivateCamera(IParcelScene parcelScene) |
| | 73 | | { |
| 1 | 74 | | freeCameraController.gameObject.SetActive(true); |
| 1 | 75 | | Vector3 pointToLookAt = BIWUtils.CalculateUnityMiddlePoint(parcelScene); |
| 1 | 76 | | Vector3 cameraPosition = GetInitialCameraPosition(parcelScene); |
| | 77 | |
|
| 1 | 78 | | initialPointToLookAt = pointToLookAt; |
| 1 | 79 | | initialCameraPosition = cameraPosition; |
| | 80 | |
|
| 1 | 81 | | freeCameraController.SetPosition(cameraPosition); |
| 1 | 82 | | freeCameraController.LookAt(pointToLookAt); |
| 1 | 83 | | freeCameraController.SetResetConfiguration(cameraPosition, pointToLookAt); |
| | 84 | |
|
| 1 | 85 | | if (cameraController != null && cameraController.currentCameraState.cameraModeId != CameraMode.ModeId.Buildi |
| 0 | 86 | | avatarCameraModeBeforeEditing = cameraController.currentCameraState.cameraModeId; |
| | 87 | |
|
| 1 | 88 | | cameraController?.SetCameraMode(CameraMode.ModeId.BuildingToolGodMode); |
| 0 | 89 | | } |
| | 90 | |
|
| | 91 | | public void DeactivateCamera() |
| | 92 | | { |
| 5 | 93 | | if (!DataStore.i.common.isApplicationQuitting.Get()) |
| 5 | 94 | | cameraController?.SetCameraMode(avatarCameraModeBeforeEditing); |
| 0 | 95 | | } |
| | 96 | |
|
| 0 | 97 | | public Texture2D GetLastScreenshot() { return lastScreenshot; } |
| | 98 | |
|
| | 99 | | internal Vector3 GetInitialCameraPosition(IParcelScene parcelScene) |
| | 100 | | { |
| 1 | 101 | | Vector3 middlePoint = BIWUtils.CalculateUnityMiddlePoint(parcelScene); |
| 1 | 102 | | Vector3 direction = (parcelScene.GetSceneTransform().position - middlePoint).normalized; |
| | 103 | |
|
| 1 | 104 | | return parcelScene.GetSceneTransform().position |
| | 105 | | + direction * initialEagleCameraDistance |
| | 106 | | + Vector3.up * initialEagleCameraHeight; |
| | 107 | | } |
| | 108 | | } |
| | 109 | | } |