更新
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
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<PostProcessingManager>
|
||||
{
|
||||
public PostProcessingController postProcessingController;
|
||||
|
||||
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
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user