| | 1 | | using Cinemachine; |
| | 2 | | using System.Collections; |
| | 3 | | using System.Collections.Generic; |
| | 4 | | using UnityEngine; |
| | 5 | |
|
| | 6 | | namespace DCL.Camera |
| | 7 | | { |
| | 8 | | public class CameraStateFreeBuildingMovement : CameraStateBase |
| | 9 | | { |
| 0 | 10 | | protected Vector3Variable cameraForward => CommonScriptableObjects.cameraForward; |
| 0 | 11 | | protected Vector3NullableVariable characterForward => CommonScriptableObjects.characterForward; |
| | 12 | |
|
| | 13 | | float localCameraDistForward; |
| | 14 | | float localCameraDistY; |
| | 15 | | bool hasLocalCameraUnselectValues = false; |
| | 16 | |
|
| | 17 | | public override void OnUpdate() |
| | 18 | | { |
| 0 | 19 | | var xzPlaneForward = Vector3.Scale(cameraTransform.forward, new Vector3(1, 0, 1)); |
| 0 | 20 | | characterForward.Set(xzPlaneForward); |
| 0 | 21 | | } |
| | 22 | |
|
| | 23 | | public override Vector3 OnGetRotation() |
| | 24 | | { |
| 0 | 25 | | if (defaultVirtualCamera is CinemachineVirtualCamera vcamera) |
| | 26 | | { |
| 0 | 27 | | var pov = vcamera.GetCinemachineComponent<CinemachinePOV>(); |
| 0 | 28 | | return new Vector3(pov.m_VerticalAxis.Value, pov.m_HorizontalAxis.Value, 0); |
| | 29 | | } |
| | 30 | |
|
| 0 | 31 | | return Vector3.zero; |
| | 32 | | } |
| | 33 | |
|
| | 34 | | public override void OnSetRotation(CameraController.SetRotationPayload payload) |
| | 35 | | { |
| 0 | 36 | | var eulerDir = Vector3.zero; |
| | 37 | |
|
| 0 | 38 | | if (payload.cameraTarget.HasValue) |
| | 39 | | { |
| 0 | 40 | | var newPos = new Vector3(payload.x, payload.y, payload.z); |
| 0 | 41 | | var cameraTarget = payload.cameraTarget.GetValueOrDefault(); |
| 0 | 42 | | var dirToLook = (cameraTarget - newPos); |
| 0 | 43 | | eulerDir = Quaternion.LookRotation(dirToLook).eulerAngles; |
| | 44 | | } |
| | 45 | |
|
| 0 | 46 | | if (defaultVirtualCamera is CinemachineVirtualCamera vcamera) |
| | 47 | | { |
| 0 | 48 | | var pov = vcamera.GetCinemachineComponent<CinemachinePOV>(); |
| 0 | 49 | | pov.m_HorizontalAxis.Value = eulerDir.y; |
| 0 | 50 | | pov.m_VerticalAxis.Value = eulerDir.x; |
| | 51 | | } |
| 0 | 52 | | } |
| | 53 | | } |
| | 54 | | } |