115 lines
2.4 KiB
C#
115 lines
2.4 KiB
C#
using Cinemachine;
|
|
using UFS2.Gameplay;
|
|
using UnityEngine;
|
|
|
|
public class PhotomodeCamera : MonoBehaviour
|
|
{
|
|
public float MainSpeed = 10f;
|
|
|
|
public float ShiftSpeed = 30f;
|
|
|
|
public float RotationSpeed = 5f;
|
|
|
|
private Vector3 _InputVector;
|
|
|
|
private Vector3 _RotationEuler;
|
|
|
|
private bool _IsEnabled;
|
|
|
|
private CinemachineVirtualCamera _VirtualCamera;
|
|
|
|
[SerializeField]
|
|
private Canvas _Canvas;
|
|
|
|
private void Start()
|
|
{
|
|
_InputVector = Vector3.zero;
|
|
_RotationEuler = base.transform.rotation.eulerAngles;
|
|
_VirtualCamera = GetComponent<CinemachineVirtualCamera>();
|
|
_Canvas.gameObject.SetActive(value: false);
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
GameCameraController.OnPhotoModeEnable += GameCameraController_OnPhotoModeEnable;
|
|
GameCameraController.OnPhotoModeDisable += GameCameraController_OnPhotoModeDisable;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
GameCameraController.OnPhotoModeEnable -= GameCameraController_OnPhotoModeEnable;
|
|
GameCameraController.OnPhotoModeDisable -= GameCameraController_OnPhotoModeDisable;
|
|
}
|
|
|
|
private void GameCameraController_OnPhotoModeDisable()
|
|
{
|
|
_IsEnabled = false;
|
|
_Canvas.gameObject.SetActive(value: false);
|
|
_VirtualCamera.Priority = 0;
|
|
}
|
|
|
|
private void GameCameraController_OnPhotoModeEnable()
|
|
{
|
|
_IsEnabled = true;
|
|
_Canvas.gameObject.SetActive(value: true);
|
|
SetCameraPosition();
|
|
_VirtualCamera.Priority = 20;
|
|
}
|
|
|
|
private void SetCameraPosition()
|
|
{
|
|
base.transform.position = Camera.main.transform.position;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (_IsEnabled)
|
|
{
|
|
_RotationEuler.x -= Input.GetAxis("Mouse Y") * RotationSpeed;
|
|
_RotationEuler.y += Input.GetAxis("Mouse X") * RotationSpeed;
|
|
base.transform.eulerAngles = _RotationEuler;
|
|
CalculateInputVector();
|
|
base.transform.Translate(_InputVector);
|
|
}
|
|
}
|
|
|
|
private void CalculateInputVector()
|
|
{
|
|
_InputVector.x = 0f;
|
|
_InputVector.y = 0f;
|
|
_InputVector.z = 0f;
|
|
if (Input.GetKey(KeyCode.W))
|
|
{
|
|
_InputVector.z += 1f;
|
|
}
|
|
if (Input.GetKey(KeyCode.S))
|
|
{
|
|
_InputVector.z -= 1f;
|
|
}
|
|
if (Input.GetKey(KeyCode.A))
|
|
{
|
|
_InputVector.x -= 1f;
|
|
}
|
|
if (Input.GetKey(KeyCode.D))
|
|
{
|
|
_InputVector.x += 1f;
|
|
}
|
|
if (Input.GetKey(KeyCode.Q))
|
|
{
|
|
_InputVector.y -= 1f;
|
|
}
|
|
if (Input.GetKey(KeyCode.E))
|
|
{
|
|
_InputVector.y += 1f;
|
|
}
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|
{
|
|
_InputVector *= Time.deltaTime * ShiftSpeed;
|
|
}
|
|
else
|
|
{
|
|
_InputVector *= Time.deltaTime * MainSpeed;
|
|
}
|
|
}
|
|
}
|