You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
243 lines
8.0 KiB
C#
243 lines
8.0 KiB
C#
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 GameObject CameraMountingBracket;
|
|
public GameObject CameraExtendingArm;
|
|
|
|
public Transform ActiveMount;
|
|
|
|
public Transform MenuMount;
|
|
|
|
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;
|
|
|
|
public float CameraXOffset;
|
|
public float CameraYOffset;
|
|
|
|
public float CameraZoom = 1.0f;
|
|
|
|
public float speedX = 200.0f;
|
|
public float speedY = 100.0f;
|
|
|
|
public float maxX = 90.0f;
|
|
public float maxY = 90.0f;
|
|
|
|
public float firstPersonMinY = -80.0f;
|
|
public float firstPersonMaxY = 90.0f;
|
|
public float firstPersonMinX = 90.0f;
|
|
public float firstPersonMaxX = 90.0f;
|
|
|
|
public bool lerping;
|
|
public Vector3 lerpStartPosition;
|
|
public Vector3 lerpTargetPosition;
|
|
public float lerpStartTime;
|
|
public float lerpDistance;
|
|
public float lerpSpeed = 3.5f;
|
|
public float lerpStopDistanceThreshold = 0.01f;
|
|
|
|
public float focusRadius = 1.0f;
|
|
public float focusCentering = 0.5f;
|
|
public float focusMaximumDistance = 10.0f;
|
|
|
|
public float orbitX;
|
|
public float orbitY;
|
|
|
|
public float minZoom = 2.0f;
|
|
|
|
public bool shouldRealign;
|
|
|
|
private Vector3 xOrbitOffset;
|
|
private Vector3 yOrbitOffset;
|
|
|
|
private bool rotatingX;
|
|
private bool rotatingY;
|
|
|
|
//public CameraMode ActiveMode;
|
|
private int activeCameraIndex;
|
|
|
|
void Start()
|
|
{
|
|
CameraXOffset = 180;
|
|
xOrbitOffset = new Vector3(0, 1.5f, CameraZoom * 4);
|
|
yOrbitOffset = new Vector3(0, 1.5f, CameraZoom * 4);
|
|
}
|
|
|
|
void Update()
|
|
{
|
|
rotatingX = false;
|
|
rotatingY = false;
|
|
}
|
|
|
|
private void LateUpdate()
|
|
{
|
|
if (focusRadius > 0f)
|
|
{
|
|
var distance = Vector3.Distance(CameraMountingBracket.transform.position, ActiveMount.transform.position);
|
|
if (distance > focusRadius)
|
|
{
|
|
if (distance < focusMaximumDistance)
|
|
{
|
|
CameraMountingBracket.transform.position = Vector3.Lerp(
|
|
CameraMountingBracket.transform.position, ActiveMount.transform.position, focusRadius / distance
|
|
);
|
|
CameraExtendingArm.transform.position = CameraMountingBracket.transform.position;
|
|
ActiveCamera.transform.position = CameraExtendingArm.transform.position;
|
|
ActiveCamera.transform.rotation = Quaternion.Euler(ActiveMount.rotation.y + CameraY, ActiveMount.rotation.x + CameraX + CameraXOffset, ActiveMount.rotation.z);
|
|
}
|
|
else
|
|
{
|
|
CameraMountingBracket.transform.rotation = ActiveMount.transform.rotation;
|
|
CameraMountingBracket.transform.position = ActiveMount.transform.position;
|
|
CameraExtendingArm.transform.rotation = CameraMountingBracket.transform.rotation;
|
|
CameraExtendingArm.transform.position = CameraMountingBracket.transform.position;
|
|
ActiveCamera.transform.rotation = CameraExtendingArm.transform.rotation;
|
|
ActiveCamera.transform.position = CameraExtendingArm.transform.position;
|
|
}
|
|
}
|
|
}
|
|
|
|
xOrbitOffset = Quaternion.AngleAxis(orbitX * speedX, Vector3.up) * xOrbitOffset;
|
|
yOrbitOffset = Quaternion.AngleAxis(orbitY * speedY, Vector3.right) * yOrbitOffset;
|
|
|
|
ActiveCamera.transform.position = CameraTarget.transform.position + xOrbitOffset + yOrbitOffset;
|
|
ActiveCamera.transform.LookAt(CameraTarget.transform.position);
|
|
Debug.Log($"xOrbitOffset - {xOrbitOffset} / yOrbitOffset - {yOrbitOffset} - orbitX - {orbitX} / orbitY - {orbitY}");
|
|
|
|
}
|
|
|
|
public void SwitchActiveCamera(Camera targetCamera)
|
|
{
|
|
|
|
}
|
|
|
|
public void ZoomIn()
|
|
{
|
|
|
|
}
|
|
|
|
public void ZoomOut(bool request = true)
|
|
{
|
|
|
|
}
|
|
|
|
public void ResetCameraPosition()
|
|
{
|
|
|
|
}
|
|
|
|
public void RotateHorizontal(float amount)
|
|
{
|
|
rotatingX = true;
|
|
if (FirstPersonActive)
|
|
{
|
|
if ((CameraX > 0 && CameraX <= firstPersonMaxX) || (CameraX < 0 && CameraX >= -firstPersonMaxX) || CameraX == 0)
|
|
{
|
|
CameraX += amount * Time.deltaTime * speedX;
|
|
}
|
|
else
|
|
{
|
|
CameraX = (CameraX > 0 ? 1 : -1) * (firstPersonMaxX - 1);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
orbitX = amount * Time.unscaledDeltaTime * speedX;
|
|
}
|
|
}
|
|
|
|
public void RotateVertical(float amount)
|
|
{
|
|
rotatingY = true;
|
|
if (FirstPersonActive)
|
|
{
|
|
if ((CameraY > 0 && CameraY <= firstPersonMaxY) || (CameraY < 0 && CameraY >= -firstPersonMaxY) || CameraY == 0)
|
|
{
|
|
CameraY -= amount * Time.deltaTime * speedY;
|
|
}
|
|
else
|
|
{
|
|
CameraY = (CameraY > 0 ? 1 : -1) * (firstPersonMaxY - 1);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
orbitY = amount * Time.unscaledDeltaTime * speedY;
|
|
}
|
|
}
|
|
|
|
public void SwitchCamera()
|
|
{
|
|
if (activeCameraIndex - 3 == AutoMounts.Count + StationMounts.Count)
|
|
activeCameraIndex = 0;
|
|
else
|
|
activeCameraIndex++;
|
|
lerping = true;
|
|
lerpStartTime = Time.time;
|
|
lerpStartPosition = ActiveCamera.transform.position;
|
|
FirstPersonActive = false;
|
|
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);
|
|
ActiveCamera.transform.SetParent(ActiveMount);
|
|
}
|
|
}
|
|
}
|
|
|