2026-03-17 시네머신 카메라 묶음 수정. 여러 카메라릭에서 공유하도록 공통 시네머신카메라리스트 분리
This commit is contained in:
@@ -31,4 +31,13 @@ public static async Awaitable RunNextFrame(Action action, CancellationToken toke
|
||||
}
|
||||
catch (OperationCanceledException) { }
|
||||
}
|
||||
|
||||
public static float NormalizeAngle(float angle)
|
||||
{
|
||||
while (angle > 180)
|
||||
angle -= 360;
|
||||
while (angle < -180)
|
||||
angle += 360;
|
||||
return angle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using Unity.Cinemachine;
|
||||
using UnityEditor.Rendering;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
public class CameraManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private AimCameraRig _currentCameraRig; //현재 활성화된 플레이어의 카메라 묶음 조종객체
|
||||
private CameraRigBase _currentCameraRig; //현재 활성화된 플레이어의 카메라 묶음 조종객체
|
||||
|
||||
private float minFOV = 40f;
|
||||
private float maxFOV = 100f;
|
||||
@@ -12,6 +13,32 @@ public class CameraManager : MonoBehaviour
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_ = InitializeCameraRig();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private async Awaitable InitializeCameraRig()
|
||||
{
|
||||
CinemachineBrain brain = Camera.main.GetComponent<CinemachineBrain>();
|
||||
|
||||
while (brain.ActiveVirtualCamera == null)
|
||||
{
|
||||
await Awaitable.NextFrameAsync();
|
||||
}
|
||||
|
||||
if (brain.ActiveVirtualCamera is CinemachineCamera cam)
|
||||
{
|
||||
_currentCameraRig = cam.GetComponentInParent<CameraRigBase>();
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSceneLoaded(Scene scene, LoadSceneMode mode)
|
||||
@@ -26,13 +53,12 @@ public void SetCameraRig(AimCameraRig cameraRig)
|
||||
|
||||
public void ZoomCamera(float offset)
|
||||
{
|
||||
_currentCameraRig.CurrentFOV = Mathf.Clamp(_currentCameraRig.CurrentFOV - offset, minFOV,maxFOV);
|
||||
if (_currentCameraRig is AimCameraRig rig)
|
||||
{
|
||||
rig.CurrentFOV = Mathf.Clamp(rig.CurrentFOV - offset, minFOV, maxFOV);
|
||||
}
|
||||
}
|
||||
|
||||
public void RecenterPlayer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Vector3 GetViewportPointToRayEndPoint(Vector3 vpPoint,float rayLength)
|
||||
{
|
||||
|
||||
@@ -43,7 +43,7 @@ protected override void Start()
|
||||
|
||||
if (currentTargetCam != null && currentTargetCam.Follow != null)
|
||||
{
|
||||
_controller = currentTargetCam.Follow.GetComponentInChildren<PlayerCharacterController>();
|
||||
_controller = currentTargetCam.Follow.GetComponentInParent<PlayerCharacterController>();
|
||||
}
|
||||
|
||||
if (_controller == null)
|
||||
|
||||
21
Assets/02_Scripts/Player/Camera/GeneralCameraRig.cs
Normal file
21
Assets/02_Scripts/Player/Camera/GeneralCameraRig.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering;
|
||||
|
||||
public class GeneralCameraRig : CameraRigBase
|
||||
{
|
||||
//CameraRigBase에 전달용
|
||||
[SerializeField] private List<CinemachineVirtualCameraBase> _myCameras = new List<CinemachineVirtualCameraBase>();
|
||||
protected override IReadOnlyList<CinemachineVirtualCameraBase> CameraCandidates => _myCameras;
|
||||
|
||||
public override void GetInputAxes(List<IInputAxisOwner.AxisDescriptor> axes)
|
||||
{
|
||||
base.GetInputAxes(axes);
|
||||
}
|
||||
|
||||
protected override CinemachineVirtualCameraBase ChooseCurrentCamera(Vector3 worldUp, float deltaTime)
|
||||
{
|
||||
return (CinemachineVirtualCameraBase)LiveChild;
|
||||
}
|
||||
}
|
||||
2
Assets/02_Scripts/Player/Camera/GeneralCameraRig.cs.meta
Normal file
2
Assets/02_Scripts/Player/Camera/GeneralCameraRig.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c04f8894370aab408215d8c6d9bfa1a
|
||||
@@ -1,6 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using Unity.Cinemachine;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using static Unity.Cinemachine.CinemachineSplineDolly;
|
||||
|
||||
public class PlayerCharacterController : MonoBehaviour
|
||||
{
|
||||
@@ -45,7 +48,11 @@ public class PlayerCharacterController : MonoBehaviour
|
||||
private CameraMode _cameraMode = CameraMode.FreeLook; //카메라 모드
|
||||
private CancellationTokenSource _cameraDelayChangeCts; //지연전환 취소 토큰
|
||||
public enum PlayerRotationMode {CameraCoupled, CameraDecoupled}
|
||||
public PlayerRotationMode RotationMode;
|
||||
public PlayerRotationMode RotationMode = PlayerRotationMode.CameraCoupled;
|
||||
|
||||
//일단은 기본값
|
||||
public bool Strafe = false;
|
||||
public void SetStrafeMode(bool b) => Strafe = b;
|
||||
|
||||
|
||||
//캐릭터 관련
|
||||
@@ -255,8 +262,8 @@ private void Movement()
|
||||
|
||||
Debug.Log($"Forward : {camForward}");
|
||||
|
||||
//카메라가 보는 방향으로 회전
|
||||
RotationByVector(camForward);
|
||||
//모드별 회전
|
||||
RotationByMode();
|
||||
_anim.SetFloat("DirectX", moveDir.x * _currentSpd / _spdCoefficient);
|
||||
_anim.SetFloat("DirectY", moveDir.z * _currentSpd / _spdCoefficient);
|
||||
|
||||
@@ -269,10 +276,38 @@ private void RotationByMove()
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, lookTarget, Time.deltaTime * 10);
|
||||
}
|
||||
}
|
||||
private void RotationByVector(Vector3 dir)
|
||||
private void RotationByMode()
|
||||
{
|
||||
transform.forward = Vector3.Slerp(transform.forward, dir, Time.deltaTime * 10);
|
||||
switch (RotationMode)
|
||||
{
|
||||
case PlayerRotationMode.CameraCoupled:
|
||||
{
|
||||
SetStrafeMode(true);
|
||||
RecenterPlayer();
|
||||
break;
|
||||
}
|
||||
case PlayerRotationMode.CameraDecoupled:
|
||||
{
|
||||
SetStrafeMode(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void RecenterPlayer(float damping = 0)
|
||||
{
|
||||
if (transform == null)
|
||||
return;
|
||||
|
||||
Vector3 cameraForward = Camera.main.transform.forward;
|
||||
cameraForward.y = 0;
|
||||
cameraForward.Normalize();
|
||||
|
||||
Quaternion targetRotation = Quaternion.LookRotation(cameraForward);
|
||||
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation,targetRotation,damping > 0 ? Time.deltaTime / damping : 1f );
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 속도적용
|
||||
@@ -310,14 +345,6 @@ private void JumpAction()
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 카메라
|
||||
public void RecenterPlayer()
|
||||
{
|
||||
if(GameManager.Instance.Camera != null)
|
||||
GameManager.Instance.Camera.RecenterPlayer();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 타미어
|
||||
private void TickTimer()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user