Files
Cielonos/Assets/Scripts/MainGame/Effects/PostProcessing/PostProcessingManager.cs
SoulliesOfficial 649b7a5ddc 更新
2026-05-23 08:27:50 -04:00

78 lines
2.5 KiB
C#
Raw Permalink 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.
using System;
using System.Collections.Generic;
using Cielonos.MainGame;
using Cielonos.MainGame.Effects;
using NBShader;
using Sirenix.OdinInspector;
using SLSUtilities.Feedback;
using SLSUtilities.General;
using UnityEngine;
using UnityEngine.Rendering;
namespace Cielonos
{
public partial class PostProcessingManager : Singleton<PostProcessingManager>
{
public SpeedLinesSubmodule speedLinesSm;
[Tooltip("主要的后处理 Volume")]
[SerializeField]
private Volume volume;
private VolumeProfile profile;
private Dictionary<Type, VolumeComponent> componentCache;
protected override void Awake()
{
base.Awake();
speedLinesSm = new SpeedLinesSubmodule(this);
if (volume != null)
{
profile = volume.profile;
componentCache = new Dictionary<Type, VolumeComponent>();
}
else
{
Debug.LogError("PostProcessingManager: 未分配 Volume 组件。请在 Inspector 中设置。");
}
}
private void Update()
{
speedLinesSm.Update(MainGameManager.Player.selfTimeSm.TimeScale);
}
/// <summary>
/// 从 Volume Profile 中安全地获取一个后处理组件(如 SpeedLines, RadialBlur
/// </summary>
/// <typeparam name="T">要获取的组件类型 (必须继承自 VolumeComponent)</typeparam>
/// <param name="component">获取到的组件实例</param>
/// <returns>如果成功找到,返回 true</returns>
public bool GetVolumeComponent<T>(out T component) where T : VolumeComponent
{
component = null;
if (componentCache == null) return false;
Type type = typeof(T);
// 1. 尝试从缓存中获取
if (componentCache.TryGetValue(type, out var cachedComponent))
{
component = (T)cachedComponent;
}
// 2. 如果缓存中没有,从 Profile 中获取
if (profile.TryGet(out T foundComponent))
{
componentCache[type] = foundComponent; // 存入缓存
component = foundComponent;
return true;
}
// 3. 未找到
Debug.LogWarning($"PostProcessManager: 在 Volume Profile 中未找到类型为 {type.Name} 的组件。");
return false;
}
}
}