77 lines
2.1 KiB
C#
77 lines
2.1 KiB
C#
using UnityEngine;
|
|
using DG.Tweening;
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
public class ScreenEffectManager : MonoBehaviour
|
|
{
|
|
public static ScreenEffectManager Instance { get; private set; }
|
|
|
|
public Volume saturation;
|
|
|
|
// private ColorAdjustments colorAdjustments;
|
|
|
|
private void Awake()
|
|
{
|
|
// 确保单例模式
|
|
if (Instance != null && Instance != this)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
else
|
|
{
|
|
Instance = this;
|
|
DontDestroyOnLoad(gameObject); // 可选:保持在场景加载之间
|
|
}
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
// 获取 ColorAdjustments 设置
|
|
// if (saturation.profile.TryGet(out colorAdjustments))
|
|
// {
|
|
// Debug.Log("ColorAdjustments is available.");
|
|
// }
|
|
// else
|
|
// {
|
|
// Debug.LogError("ColorAdjustments settings not found in PostProcessProfile.");
|
|
// }
|
|
}
|
|
|
|
// 动态调整饱和度
|
|
public Tween TweenSaturation(float targetSaturation, float duration)
|
|
{
|
|
if (saturation != null)
|
|
{
|
|
// 将targetSaturation (0~1) 转换为weight (1~0)
|
|
// targetSaturation = 0 时,weight = 1 (完全褪色)
|
|
// targetSaturation = 1 时,weight = 0 (正常颜色)
|
|
float targetWeight = 1f - targetSaturation;
|
|
|
|
// 使用 DOTween 创建一个weight过渡动画
|
|
Tween tween = DOTween.To(
|
|
() => saturation.weight, // 获取当前weight值
|
|
x => saturation.weight = x, // 设置新的weight值
|
|
targetWeight, // 目标weight值
|
|
duration // 过渡持续时间
|
|
);
|
|
|
|
return tween; // 返回 Tween 对象
|
|
}
|
|
else
|
|
{
|
|
Debug.LogError("Saturation Volume not found.");
|
|
return null; // 如果找不到设置,返回 null
|
|
}
|
|
}
|
|
|
|
// 重置饱和度效果
|
|
public void ResetSaturation()
|
|
{
|
|
if (saturation != null)
|
|
{
|
|
// 直接设置weight为0,恢复正常颜色
|
|
saturation.weight = 0f;
|
|
}
|
|
}
|
|
} |