|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using SiegeSong;
|
|
|
|
|
|
|
|
|
|
namespace SiegeSong
|
|
|
|
|
{
|
|
|
|
|
public class CameraManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public RuntimeManager RuntimeManager;
|
|
|
|
|
|
|
|
|
|
public Motor Motor;
|
|
|
|
|
|
|
|
|
|
public GameObject ActiveCamera;
|
|
|
|
|
|
|
|
|
|
public bool FirstPersonActive;
|
|
|
|
|
|
|
|
|
|
public Transform CameraTarget;
|
|
|
|
|
|
|
|
|
|
public Transform MenuMount;
|
|
|
|
|
|
|
|
|
|
public Transform ActiveMount;
|
|
|
|
|
|
|
|
|
|
public Transform FirstPersonMount;
|
|
|
|
|
public Transform LeftMount;
|
|
|
|
|
public Transform RightMount;
|
|
|
|
|
public Transform CenterMount;
|
|
|
|
|
public List<Transform> AutoMounts;
|
|
|
|
|
public List<Transform> StationMounts;
|
|
|
|
|
|
|
|
|
|
public GameObject[] NonPlayerCameras;
|
|
|
|
|
|
|
|
|
|
public float CameraX;
|
|
|
|
|
public float CameraY;
|
|
|
|
|
|
|
|
|
|
private int activeCameraIndex;
|
|
|
|
|
|
|
|
|
|
private float speedX = 200.0f;
|
|
|
|
|
private float speedY = 100.0f;
|
|
|
|
|
|
|
|
|
|
private float minX = -90.0f;
|
|
|
|
|
private float maxX = 90.0f;
|
|
|
|
|
|
|
|
|
|
private float minY = -70.0f;
|
|
|
|
|
private float maxY = 90.0f;
|
|
|
|
|
private float zoomStep = 0.1f;
|
|
|
|
|
|
|
|
|
|
private float firstPersonMinY = -170.0f;
|
|
|
|
|
private float firstPersonMaxY = 130.0f;
|
|
|
|
|
|
|
|
|
|
private float zoomSpeed = 0.1f;
|
|
|
|
|
private float zoom = 2.0f;
|
|
|
|
|
private float requestedZoom = 2.0f;
|
|
|
|
|
private float minZoom = -0.2f;
|
|
|
|
|
private float maxZoom = 0.5f;
|
|
|
|
|
private bool canZoomToRequested = true;
|
|
|
|
|
private bool zooming;
|
|
|
|
|
private bool zoomCollision;
|
|
|
|
|
|
|
|
|
|
private bool lerping;
|
|
|
|
|
private Vector3 lerpStartPosition;
|
|
|
|
|
private Vector3 lerpTargetPosition;
|
|
|
|
|
private float lerpStartTime;
|
|
|
|
|
private float lerpDistance;
|
|
|
|
|
private float lerpSpeed = 3.5f;
|
|
|
|
|
private float lerpStopDistanceThreshold = 0.02f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private float rotationSpeedBrakeSpeed = 2.0f;
|
|
|
|
|
private float rotationSpeedStopThreshold = 0.1f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//public CameraMode ActiveMode;
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
|
|
|
|
ActiveMount = MenuMount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
|
|
|
|
ActiveCamera.transform.position = ActiveMount.position;
|
|
|
|
|
|
|
|
|
|
if (Motor.UsingStation)
|
|
|
|
|
{
|
|
|
|
|
CameraX = Motor.TargetStation.CameraX;
|
|
|
|
|
CameraY = Motor.TargetStation.CameraY;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (lerping)
|
|
|
|
|
{
|
|
|
|
|
ActiveCamera.transform.position = Vector3.Lerp(lerpStartPosition, lerpTargetPosition, ((Time.time - lerpStartTime) * lerpSpeed) / lerpDistance);
|
|
|
|
|
if (Vector3.Distance(ActiveCamera.transform.position, lerpTargetPosition) < lerpStopDistanceThreshold)
|
|
|
|
|
lerping = false;
|
|
|
|
|
}
|
|
|
|
|
//else if (lerpTargetPosition != null)
|
|
|
|
|
//{
|
|
|
|
|
// ActiveCamera.transform.position = lerpTargetPosition;
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
if (!zoomCollision)
|
|
|
|
|
{
|
|
|
|
|
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 + zoom);
|
|
|
|
|
zoom = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SwitchActiveCamera(Camera targetCamera)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ZoomIn()
|
|
|
|
|
{
|
|
|
|
|
if (!FirstPersonActive)
|
|
|
|
|
{
|
|
|
|
|
if (zoom - zoomStep > minZoom)
|
|
|
|
|
{
|
|
|
|
|
zoom -= zoomStep;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
zoom = minZoom;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ZoomOut(bool request = true)
|
|
|
|
|
{
|
|
|
|
|
if (!FirstPersonActive)
|
|
|
|
|
{
|
|
|
|
|
zoom += zoomStep;
|
|
|
|
|
}
|
|
|
|
|
if (!FirstPersonActive)
|
|
|
|
|
{
|
|
|
|
|
if (zoom + zoomStep < maxZoom)
|
|
|
|
|
{
|
|
|
|
|
zoom += zoomStep;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
zoom = maxZoom;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResetCameraPosition()
|
|
|
|
|
{
|
|
|
|
|
ActiveCamera.transform.position = ActiveMount.transform.position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RealignCamera(bool rotateBody = false)
|
|
|
|
|
{
|
|
|
|
|
if (!rotateBody)
|
|
|
|
|
{
|
|
|
|
|
if (CameraX < rotationSpeedStopThreshold && CameraX > -rotationSpeedStopThreshold)
|
|
|
|
|
CameraX = 0;
|
|
|
|
|
else
|
|
|
|
|
CameraX = CameraX / rotationSpeedBrakeSpeed;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Motor.RotateToDirection(ActiveMount.eulerAngles);
|
|
|
|
|
//Motor.RotateToDirection(ActiveCamera.transform.eulerAngles);
|
|
|
|
|
|
|
|
|
|
ActiveMount.RotateAround(CameraTarget.position, Vector3.up, -CameraX);
|
|
|
|
|
ActiveCamera.transform.rotation.SetLookRotation(CameraTarget.position);
|
|
|
|
|
ActiveCamera.transform.rotation = Quaternion.Euler(-ActiveCamera.transform.rotation.x, ActiveCamera.transform.rotation.y, ActiveCamera.transform.rotation.z);
|
|
|
|
|
//ActiveCamera.transform.RotateAround(CameraTarget.position, Vector3.up, -CameraX);
|
|
|
|
|
|
|
|
|
|
CameraX = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RotateMotor(Vector3 eulerAngles)
|
|
|
|
|
{
|
|
|
|
|
Motor.RotateToDirection(eulerAngles);
|
|
|
|
|
ActiveMount.RotateAround(CameraTarget.position, Vector3.up, -eulerAngles.x);
|
|
|
|
|
//ActiveCamera.transform.RotateAround(CameraTarget.position, Vector3.up, -eulerAngles.x);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RotateHorizontal(float amount)
|
|
|
|
|
{
|
|
|
|
|
var degreesToRotate = amount * speedX * Time.deltaTime;
|
|
|
|
|
|
|
|
|
|
CameraX += degreesToRotate;
|
|
|
|
|
ActiveMount.RotateAround(CameraTarget.position, Vector3.up, amount * speedX * Time.deltaTime);
|
|
|
|
|
//ActiveCamera.transform.RotateAround(CameraTarget.position, Vector3.up, amount * speedX * Time.deltaTime);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RotateVertical(float amount)
|
|
|
|
|
{
|
|
|
|
|
var degreesToRotate = amount * speedY * Time.deltaTime;
|
|
|
|
|
if (degreesToRotate > 0 && !(CameraY + degreesToRotate > (FirstPersonActive ? firstPersonMaxY : maxY))
|
|
|
|
|
|| (degreesToRotate < 0 && !(CameraY + degreesToRotate < (FirstPersonActive ? firstPersonMinY : minY))))
|
|
|
|
|
{
|
|
|
|
|
CameraY += degreesToRotate;
|
|
|
|
|
ActiveCamera.transform.RotateAround(CameraTarget.position, ActiveCamera.transform.TransformDirection(-Vector3.right), amount * speedY * Time.deltaTime);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SwitchCamera()
|
|
|
|
|
{
|
|
|
|
|
ActiveCamera.transform.RotateAround(CameraTarget.position, ActiveCamera.transform.TransformDirection(-Vector3.right), -CameraY);
|
|
|
|
|
CameraY = 0;
|
|
|
|
|
if (FirstPersonActive)
|
|
|
|
|
FirstPersonActive = false;
|
|
|
|
|
if (activeCameraIndex - 3 == AutoMounts.Count + StationMounts.Count)
|
|
|
|
|
activeCameraIndex = 0;
|
|
|
|
|
else
|
|
|
|
|
activeCameraIndex++;
|
|
|
|
|
lerping = true;
|
|
|
|
|
lerpStartTime = Time.time;
|
|
|
|
|
lerpStartPosition = ActiveCamera.transform.position;
|
|
|
|
|
switch (activeCameraIndex)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
FirstPersonActive = true;
|
|
|
|
|
lerpTargetPosition = FirstPersonMount.position;
|
|
|
|
|
ActiveMount = FirstPersonMount;
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
lerpTargetPosition = RightMount.position;
|
|
|
|
|
ActiveMount = RightMount;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
lerpTargetPosition = CenterMount.position;
|
|
|
|
|
ActiveMount = CenterMount;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
lerpTargetPosition = LeftMount.position;
|
|
|
|
|
ActiveMount = LeftMount;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
case 4:
|
|
|
|
|
if (activeCameraIndex - 3 > AutoMounts.Count)
|
|
|
|
|
{
|
|
|
|
|
lerpTargetPosition = StationMounts[activeCameraIndex - 3 - AutoMounts.Count].position;
|
|
|
|
|
ActiveMount = StationMounts[activeCameraIndex - 3 - AutoMounts.Count];
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
lerpTargetPosition = StationMounts[activeCameraIndex - 3].position;
|
|
|
|
|
ActiveMount = StationMounts[activeCameraIndex - 3];
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
lerpDistance = Vector3.Distance(ActiveCamera.transform.position, lerpTargetPosition);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|