+玩家行为事件
+视角摇晃 +相机后处理
This commit is contained in:
35
Assets/Scripts/Camera/CameraPostProcessing.cs
Normal file
35
Assets/Scripts/Camera/CameraPostProcessing.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using Event;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Rendering.PostProcessing;
|
||||
|
||||
namespace Camera
|
||||
{
|
||||
public class CameraPostProcessing : MonoBehaviour
|
||||
{
|
||||
private UnityEngine.Camera _camera;
|
||||
private PostProcessVolume _processVolume;
|
||||
private void Awake()
|
||||
{
|
||||
_camera = GetComponent<UnityEngine.Camera>();
|
||||
_processVolume = GetComponent<PostProcessVolume>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
EventManager.Instance.PlayerRunning += PostProcess;
|
||||
EventManager.Instance.PlayerRunStop += ProcessingStop;
|
||||
}
|
||||
|
||||
private void PostProcess()
|
||||
{
|
||||
_camera.fieldOfView = Mathf.Lerp(_camera.fieldOfView, 90f, Time.deltaTime * 10f);
|
||||
_processVolume.profile.GetSetting<ChromaticAberration>().intensity.value = Mathf.Lerp(_processVolume.profile.GetSetting<ChromaticAberration>().intensity.value, 1f, Time.deltaTime * 10f);
|
||||
}
|
||||
|
||||
private void ProcessingStop()
|
||||
{
|
||||
_processVolume.profile.GetSetting<ChromaticAberration>().intensity.value = Mathf.Lerp(_processVolume.profile.GetSetting<ChromaticAberration>().intensity.value, 0f, Time.deltaTime * 10f);
|
||||
_camera.fieldOfView = Mathf.Lerp(_camera.fieldOfView, 60f, Time.deltaTime * 10f);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Camera/CameraPostProcessing.cs.meta
Normal file
3
Assets/Scripts/Camera/CameraPostProcessing.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd8e51b43a0c4d4ca7e732246b8ad2e6
|
||||
timeCreated: 1726297370
|
||||
68
Assets/Scripts/Camera/CameraShake.cs
Normal file
68
Assets/Scripts/Camera/CameraShake.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using Event;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Camera
|
||||
{
|
||||
public class CameraShake : MonoBehaviour
|
||||
{
|
||||
public Transform cameraTransform;
|
||||
public float amplitude = 0.05f;
|
||||
public float frequency = 10.0f;
|
||||
|
||||
private Vector3 _originalPos;
|
||||
private bool _isRunning;
|
||||
private bool _isWalking;
|
||||
private void Start()
|
||||
{
|
||||
_originalPos = cameraTransform.localPosition;
|
||||
EventManager.Instance.PlayerRunning += OnPlayerRunning;
|
||||
EventManager.Instance.PlayerRunStop += StopRunning;
|
||||
EventManager.Instance.PlayerWalking += OnPlayerWalking;
|
||||
EventManager.Instance.PlayerWalkStop += StopWalking;
|
||||
}
|
||||
|
||||
|
||||
private void OnPlayerRunning()
|
||||
{
|
||||
_isRunning = true;
|
||||
}
|
||||
|
||||
private void OnPlayerWalking()
|
||||
{
|
||||
_isWalking = true;
|
||||
}
|
||||
|
||||
private void StopRunning()
|
||||
{
|
||||
_isRunning = false;
|
||||
}
|
||||
|
||||
private void StopWalking()
|
||||
{
|
||||
_isWalking = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (_isRunning)
|
||||
{
|
||||
var xShake = Mathf.Sin(Time.time * frequency) * amplitude;
|
||||
var yShake = Mathf.Cos(Time.time * frequency * 2) * amplitude * 0.5f;
|
||||
|
||||
cameraTransform.localPosition = _originalPos + new Vector3(xShake, yShake, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_isWalking)
|
||||
{
|
||||
var xShake = Mathf.Sin(Time.time * frequency / 2) * amplitude;
|
||||
var yShake = Mathf.Cos(Time.time * frequency / 2 * 2) * amplitude * 0.5f;
|
||||
|
||||
cameraTransform.localPosition = _originalPos + new Vector3(xShake, yShake, 0);
|
||||
}else
|
||||
cameraTransform.localPosition = _originalPos;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Camera/CameraShake.cs.meta
Normal file
3
Assets/Scripts/Camera/CameraShake.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d64f284209414d79a3996a0a6d1748b4
|
||||
timeCreated: 1726297975
|
||||
Reference in New Issue
Block a user