61 lines
1.8 KiB
C#
61 lines
1.8 KiB
C#
using Ichni.RhythmGame.Beatmap;
|
||
using UnityEngine;
|
||
|
||
namespace Ichni.RhythmGame
|
||
{
|
||
public class CameraZoomEffect : EffectBase
|
||
{
|
||
#region [效果参数] Effect Parameters
|
||
public float duration;
|
||
public float relativeZoom;
|
||
public AnimationCurve zoomCurve;
|
||
|
||
private Camera _mainCamera;
|
||
private float _startFOV = 60f; // 请填入你项目的默认摄像机广角值
|
||
#endregion
|
||
|
||
#region [初始化] Initialization
|
||
public CameraZoomEffect(float duration, float relativeZoom, AnimationCurve zoomCurve)
|
||
: base(duration)
|
||
{
|
||
this.duration = duration;
|
||
this.relativeZoom = relativeZoom;
|
||
this.zoomCurve = zoomCurve;
|
||
}
|
||
#endregion
|
||
|
||
#region [效果逻辑覆盖] Effect Pattern Overrides
|
||
public override void PreExecute()
|
||
{
|
||
if (_mainCamera == null)
|
||
{
|
||
_mainCamera = GameManager.Instance.cameraManager.gameCamera.cam;
|
||
}
|
||
|
||
_startFOV = _mainCamera.fieldOfView; // 记录初始 FOV,结束时恢复
|
||
}
|
||
|
||
public override void Execute()
|
||
{
|
||
if (_mainCamera != null)
|
||
{
|
||
// relativeZoom > 0 代表拉近视野,FOV 更小
|
||
float offset = zoomCurve.Evaluate(effectProgressPercent) * relativeZoom;
|
||
_mainCamera.fieldOfView = _startFOV - offset;
|
||
}
|
||
}
|
||
|
||
public override void Adjust() { ResetEffect(); }
|
||
public override void Recover() { ResetEffect(); }
|
||
public override void Disrupt() { ResetEffect(); }
|
||
|
||
private void ResetEffect()
|
||
{
|
||
if (_mainCamera != null) _mainCamera.fieldOfView = _startFOV;
|
||
}
|
||
#endregion
|
||
|
||
}
|
||
|
||
}
|