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