Files
zeling_v2/Assets/Scripts/World/Liquid/UnderwaterPostProcessingController.cs
Joywayer 1135139bc6 v11 全量评审:修复 TD-13 至 TD-17
- TD-13: IQuestManager.CompleteQuest 改用 IRewardTarget,移除 using BaseGames.Player
- TD-14: HurtFlashController 缓存 WaitForSeconds(_waitForFlash 字段)
- TD-16: LiquidType 枚举迁移至 BaseGames.Core.Events;LiquidEvent.LiquidType 改为枚举直接比较
- TD-17: DeathScreenController 移除失效的 _onPlayerDied 订阅,改为 OnEnable 直接启动延迟显示

影响文件: IQuestManager.cs / HurtFlashController.cs / LiquidType.cs(迁移) /
  LiquidEvent.cs / LiquidZone.cs / WaterDangerState.cs /
  UnderwaterPostProcessingController.cs / UnderwaterAudioController.cs /
  DeathScreenController.cs

评审文档: Docs/Review/FrameworkReview_2026_May_v11.md(综合评分 9.30/10)
2026-05-12 16:34:03 +08:00

57 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Assets/Scripts/World/Liquid/UnderwaterPostProcessingController.cs
using System.Collections;
using BaseGames.Core.Events;
using UnityEngine;
using UnityEngine.Rendering;
namespace BaseGames.World.Liquid
{
public class UnderwaterPostProcessingController : MonoBehaviour
{
[SerializeField] private Volume _underwaterVolume; // 水下专属 VolumeWeightMode
[SerializeField] private float _blendInDuration = 0.3f;
[SerializeField] private float _blendOutDuration = 0.3f;
[SerializeField] private LiquidEventChannelSO _onLiquidEntered; // EVT_LiquidEntered
[SerializeField] private LiquidEventChannelSO _onLiquidExited; // EVT_LiquidExited
private Coroutine _blendCoroutine;
private readonly CompositeDisposable _subs = new();
private void OnEnable()
{
_onLiquidEntered?.Subscribe(OnLiquidEntered).AddTo(_subs);
_onLiquidExited?.Subscribe(OnLiquidExited).AddTo(_subs);
}
private void OnDisable() => _subs.Clear();
private void OnLiquidEntered(LiquidEvent evt)
{
if (evt.LiquidType != LiquidType.Water) return;
BlendVolume(1f, _blendInDuration);
}
private void OnLiquidExited(LiquidEvent evt) => BlendVolume(0f, _blendOutDuration);
private void BlendVolume(float target, float duration)
{
if (_blendCoroutine != null) StopCoroutine(_blendCoroutine);
_blendCoroutine = StartCoroutine(BlendRoutine(target, duration));
}
private IEnumerator BlendRoutine(float target, float duration)
{
if (_underwaterVolume == null) yield break;
float start = _underwaterVolume.weight;
float elapsed = 0f;
while (elapsed < duration)
{
elapsed += Time.deltaTime;
_underwaterVolume.weight = Mathf.Lerp(start, target, elapsed / duration);
yield return null;
}
_underwaterVolume.weight = target;
}
}
}