using System.Collections; using System.Collections.Generic; using UnityEngine; using SiegeSong; namespace SiegeSong { public class PlayerCameraManager : MonoBehaviour { public RuntimeManager RuntimeManager; 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 CameraX; public float CameraY; private float cameraSpeedX = 200.0f; private float cameraSpeedY = 100.0f; private float cameraMinX = -90.0f; private float cameraMaxX = 90.0f; private float cameraMinY = -70.0f; private float cameraMaxY = 90.0f; private float firstPersonMinY = -170.0f; private float firstPersonMaxY = 130.0f; private float cameraZoomSpeed = 0.1f; private float cameraZoom = 2.0f; private float cameraRequestedZoom = 2.0f; private float cameraMinZoom = -0.2f; private float cameraMaxZoom = 0.5f; private bool canZoomToRequested = true; private bool cameraZooming; private bool cameraZoomCollision; private float rotationSpeedBrakeSpeed = 2.0f; private float rotationSpeedStopThreshold = 0.1f; private 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; } RuntimeManager.PopulateReferences(); } } }