66 lines
1.7 KiB
C#
66 lines
1.7 KiB
C#
using System;
|
|
using UFS2.Gameplay;
|
|
using UnityEngine;
|
|
using UnityEngine.Rendering.PostProcessing;
|
|
|
|
public class PostProcessingController : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private PostProcessVolume _PP_Land;
|
|
|
|
[SerializeField]
|
|
private PostProcessVolume _PP_Underwater;
|
|
|
|
[SerializeField]
|
|
private AnimationCurve _LensCenterXCurve;
|
|
|
|
[SerializeField]
|
|
private AnimationCurve _LensCenterYCurve;
|
|
|
|
private bool isUnderwater;
|
|
|
|
public static event Action OnPPChange;
|
|
|
|
private void OnEnable()
|
|
{
|
|
GameCameraController.OnEnterInToWater += ChangeToUnderWaterPP;
|
|
GameCameraController.OnExitFromWater += ChangeToNormalPP;
|
|
SmoothFollowUnderwater.OnCameraTransformUpdate += UpdateUnderwaterPP;
|
|
FreeCamera.OnEnterUnderwater += ChangeToUnderWaterPP;
|
|
FreeCamera.OnExitUnderwater += ChangeToNormalPP;
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
GameCameraController.OnEnterInToWater -= ChangeToUnderWaterPP;
|
|
GameCameraController.OnExitFromWater -= ChangeToNormalPP;
|
|
SmoothFollowUnderwater.OnCameraTransformUpdate -= UpdateUnderwaterPP;
|
|
FreeCamera.OnEnterUnderwater -= ChangeToUnderWaterPP;
|
|
FreeCamera.OnExitUnderwater -= ChangeToNormalPP;
|
|
}
|
|
|
|
private void ChangeToUnderWaterPP()
|
|
{
|
|
ChangePP(isUnderwater: true);
|
|
}
|
|
|
|
private void ChangeToNormalPP()
|
|
{
|
|
ChangePP(isUnderwater: false);
|
|
}
|
|
|
|
private void ChangePP(bool isUnderwater)
|
|
{
|
|
PostProcessingController.OnPPChange?.Invoke();
|
|
_PP_Underwater.gameObject.SetActive(isUnderwater);
|
|
_PP_Land.gameObject.SetActive(!isUnderwater);
|
|
}
|
|
|
|
private void UpdateUnderwaterPP(Transform target)
|
|
{
|
|
_PP_Underwater.sharedProfile.TryGetSettings<DepthOfField>(out var outSetting);
|
|
float value = Vector3.Distance(Vector3.zero, target.localPosition);
|
|
outSetting.focusDistance.value = value;
|
|
}
|
|
}
|