42 lines
1.5 KiB
C#
42 lines
1.5 KiB
C#
|
|
using UnityEngine.Rendering;
|
|
using UnityEngine.Rendering.Universal;
|
|
|
|
namespace zzwater
|
|
{
|
|
public class URPHelper
|
|
{
|
|
public static ScriptableRendererFeature FindAndCacheRendererFeature(string name)
|
|
{
|
|
// 获取当前 URP 资产
|
|
var urpAsset = (UniversalRenderPipelineAsset)GraphicsSettings.currentRenderPipeline;
|
|
|
|
// 使用反射获取 rendererData (因为它通常是私有的)
|
|
System.Reflection.FieldInfo propertyInfo = urpAsset.GetType().GetField("m_RendererDataList", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
|
|
if (propertyInfo != null)
|
|
{
|
|
ScriptableRendererData[] rendererDataList = (ScriptableRendererData[])propertyInfo.GetValue(urpAsset);
|
|
if (rendererDataList.Length > 0)
|
|
{
|
|
var rendererData = rendererDataList[0]; // 获取第一个渲染器数据,你可能需要调整此逻辑
|
|
|
|
// 查找指定名称的 FullScreenPassRendererFeature
|
|
foreach (var feature in rendererData.rendererFeatures)
|
|
{
|
|
if (feature.name == name)
|
|
{
|
|
return feature;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public static void RendererFeatureSetActive(bool active, string name)
|
|
{
|
|
FindAndCacheRendererFeature(name)?.SetActive(active);
|
|
}
|
|
}
|
|
}
|