2026-03-17 시네머신 카메라 묶음 수정. 여러 카메라릭에서 공유하도록 공통 시네머신카메라리스트 분리
This commit is contained in:
BIN
Assets/01_Scenes/GameScene.unity
LFS
BIN
Assets/01_Scenes/GameScene.unity
LFS
Binary file not shown.
@@ -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()
|
||||
{
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -96,6 +96,15 @@
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": true
|
||||
},
|
||||
{
|
||||
"name": "AimToggle",
|
||||
"type": "Button",
|
||||
"id": "cb23cd8a-2f01-4c64-95ee-ce66cdeb9b6e",
|
||||
"expectedControlType": "",
|
||||
"processors": "",
|
||||
"interactions": "",
|
||||
"initialStateCheck": false
|
||||
}
|
||||
],
|
||||
"bindings": [
|
||||
@@ -198,50 +207,6 @@
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "Two Modifiers",
|
||||
"id": "6b03a59d-285a-4eba-9d22-b1f00df7a719",
|
||||
"path": "TwoModifiers",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": "",
|
||||
"action": "Look",
|
||||
"isComposite": true,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "modifier1",
|
||||
"id": "78ed7bf1-7fd2-4d10-9b4a-f3c30ce2c34f",
|
||||
"path": "<Keyboard>/leftCtrl",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "Look",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "modifier2",
|
||||
"id": "673df13b-f2e9-4005-848d-7082d785bbb2",
|
||||
"path": "<Mouse>/leftButton",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "Look",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "binding",
|
||||
"id": "5e0ef3f8-c168-4415-9688-2209b60a8f33",
|
||||
"path": "<Mouse>/delta",
|
||||
"interactions": "",
|
||||
"processors": "ScaleVector2(x=10,y=10)",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "Look",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": true
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "05f6913d-c316-48b2-a6bb-e225f14c7960",
|
||||
@@ -296,6 +261,28 @@
|
||||
"action": "Scroll",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "b70b818d-291e-4f86-8260-5daed1b62e64",
|
||||
"path": "<Keyboard>/leftAlt",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "AimToggle",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
},
|
||||
{
|
||||
"name": "",
|
||||
"id": "786045ad-3e31-4336-a241-5a0f1c57caa8",
|
||||
"path": "<Mouse>/delta",
|
||||
"interactions": "",
|
||||
"processors": "",
|
||||
"groups": ";Keyboard&Mouse",
|
||||
"action": "Look",
|
||||
"isComposite": false,
|
||||
"isPartOfComposite": false
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
Binary file not shown.
Reference in New Issue
Block a user