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