摄像机区域的优化
This commit is contained in:
43
Assets/_Game/Scripts/Camera/CameraAxisLockExtension.cs
Normal file
43
Assets/_Game/Scripts/Camera/CameraAxisLockExtension.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
using Unity.Cinemachine;
|
||||
|
||||
namespace BaseGames.Camera
|
||||
{
|
||||
/// <summary>
|
||||
/// Cinemachine 扩展:在 Body 阶段之后硬锁定相机某一轴向。
|
||||
///
|
||||
/// 用途:
|
||||
/// - <see cref="LockX"/> = true → 垂直竖井 / 电梯:相机仅上下移动,X 固定于限位区域中心。
|
||||
/// - <see cref="LockY"/> = true → 水平走廊:相机仅左右移动,Y 固定于限位区域中心。
|
||||
///
|
||||
/// 由 <see cref="CameraStateController"/> 在切换区域时自动写入 <see cref="LockedX"/> /
|
||||
/// <see cref="LockedY"/>(从 ConfinerCollider.bounds.center 取值)并切换锁定开关。
|
||||
/// </summary>
|
||||
[AddComponentMenu("Cinemachine/Extensions/Camera Axis Lock")]
|
||||
[DisallowMultipleComponent]
|
||||
public class CameraAxisLockExtension : CinemachineExtension
|
||||
{
|
||||
/// <summary>锁定 X 轴(垂直竖井)。</summary>
|
||||
[HideInInspector] public bool LockX = false;
|
||||
/// <summary>锁定 Y 轴(水平走廊)。</summary>
|
||||
[HideInInspector] public bool LockY = false;
|
||||
/// <summary>X 轴锁定到的世界坐标(由 CameraStateController 写入)。</summary>
|
||||
[HideInInspector] public float LockedX = 0f;
|
||||
/// <summary>Y 轴锁定到的世界坐标(由 CameraStateController 写入)。</summary>
|
||||
[HideInInspector] public float LockedY = 0f;
|
||||
|
||||
protected override void PostPipelineStageCallback(
|
||||
CinemachineVirtualCameraBase vcam,
|
||||
CinemachineCore.Stage stage,
|
||||
ref CameraState state,
|
||||
float deltaTime)
|
||||
{
|
||||
if (stage != CinemachineCore.Stage.Body) return;
|
||||
|
||||
var pos = state.RawPosition;
|
||||
if (LockX) pos.x = LockedX;
|
||||
if (LockY) pos.y = LockedY;
|
||||
state.RawPosition = pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user