using System.Collections; using System.Collections.Generic; using UnityEngine; using SiegeSong; namespace SiegeSong { public class PlayerCameraManager : MonoBehaviour { public PlayerReferencePopulator ReferencePopulator; public ActorMotor ActorMotor; public GameObject ActiveCamera; private int activeCameraIndex; public bool FirstPersonActive; public Transform CameraTarget; public GameObject LeftCamera; public GameObject CenterCamera; public GameObject RightCamera; public GameObject FirstPersonCamera; public float CameraSpeedX = 200.0f; public float CameraSpeedY = 100.0f; public float CameraMinX = -90.0f; public float CameraMaxX = 90.0f; public float CameraMinY = -70.0f; public float CameraMaxY = 90.0f; public float FirstPersonMinY = -170.0f; public float FirstPersonMaxY = 130.0f; public float CameraZoomSpeed = 0.1f; public float CameraZoom = 2.0f; public float CameraRequestedZoom = 2.0f; public float CameraMinZoom = -0.2f; public float CameraMaxZoom = 0.5f; public bool CanZoomToRequested = true; public bool CameraZooming; public bool CameraZoomCollision; public float cameraX; public float cameraY; public float RotationSpeedBrakeSpeed = 2.0f; public float RotationSpeedStopThreshold = 0.1f; float cameraZoomStep = 0.1f; //public CameraMode ActiveMode; void Start() { } void Update() { if (ActorMotor.UsingStation) { cameraX = ActorMotor.TargetStation.CameraX; cameraY = ActorMotor.TargetStation.CameraY; } if (!CameraZoomCollision) { for (var i = 0; i < ActiveCamera.transform.childCount; i++) { var child = ActiveCamera.transform.GetChild(i); if (child.gameObject.CompareTag("MainCamera") && !FirstPersonActive) { child.position = new Vector3(child.position.x, child.position.y, child.position.z + CameraZoom); CameraZoom = 0; } } } } public void SwitchActiveCamera(Camera targetCamera) { } public void ZoomIn() { if (!FirstPersonActive) { if (CameraZoom - cameraZoomStep > CameraMinZoom) { CameraZoom -= cameraZoomStep; } else { CameraZoom = CameraMinZoom; } } } public void ZoomOut(bool request = true) { if (!FirstPersonActive) { CameraZoom += cameraZoomStep; } if (!FirstPersonActive) { if (CameraZoom + cameraZoomStep < CameraMaxZoom) { CameraZoom += cameraZoomStep; } else { CameraZoom = CameraMaxZoom; } } } public void RealignCamera(bool rotateBody = false) { if (!rotateBody) { if (cameraX < RotationSpeedStopThreshold && cameraX > -RotationSpeedStopThreshold) cameraX = 0; else cameraX = cameraX / RotationSpeedBrakeSpeed; } else { ActorMotor.RotateToDirection(ActiveCamera.transform.eulerAngles); ActiveCamera.transform.RotateAround(CameraTarget.position, Vector3.up, -cameraX); cameraX = 0; } } public void RotateHorizontal(float amount) { var degreesToRotate = amount * CameraSpeedX * Time.deltaTime; cameraX += degreesToRotate; ActiveCamera.transform.RotateAround(CameraTarget.position, Vector3.up, amount * CameraSpeedX * Time.deltaTime); } public void RotateVertical(float amount) { var degreesToRotate = amount * CameraSpeedY * Time.deltaTime; if (degreesToRotate > 0 && !(cameraY + degreesToRotate > (FirstPersonActive ? FirstPersonMaxY : CameraMaxY)) || (degreesToRotate < 0 && !(cameraY + degreesToRotate < (FirstPersonActive ? FirstPersonMinY : CameraMinY)))) { cameraY += degreesToRotate; ActiveCamera.transform.RotateAround(CameraTarget.position, ActiveCamera.transform.TransformDirection(-Vector3.right), amount * CameraSpeedY * Time.deltaTime); } } public void SwitchCamera() { ActiveCamera.transform.RotateAround(CameraTarget.position, ActiveCamera.transform.TransformDirection(-Vector3.right), -cameraY); cameraY = 0; switch (activeCameraIndex) { case 0: FirstPersonActive = false; FirstPersonCamera.active = false; CenterCamera.active = true; ActiveCamera = CenterCamera; activeCameraIndex++; break; case 1: LeftCamera.active = false; RightCamera.active = true; ActiveCamera = RightCamera; activeCameraIndex++; break; case 2: RightCamera.active = false; LeftCamera.active = true; ActiveCamera = LeftCamera; activeCameraIndex++; break; case 3: default: LeftCamera.active = false; FirstPersonActive = true; FirstPersonCamera.active = true; ActiveCamera = FirstPersonCamera; activeCameraIndex = 0; break; } ReferencePopulator.PopulateReferences(); } } }