unity如何动态控制后处理程序的参数
程序员文章站
2022-06-10 23:47:22
...
public PostProcessVolume volume;
public DepthOfField dof;
// Use this for initialization
void Start()
{
PostProcessLayer ppsLayer = GetComponent<PostProcessLayer>();
if (ppsLayer != null)
{
LayerMask layerMask = ppsLayer.volumeLayer;
PostProcessVolume[] ppsVolumes = FindObjectsOfType<PostProcessVolume>();
if (ppsVolumes != null && ppsVolumes.Length > 0)
{
for (int k = 0; k < ppsVolumes.Length; k++)
{
PostProcessVolume ppsVolume = ppsVolumes[k];
int layer = 1 << ppsVolume.gameObject.layer;
bool inLayer = (layerMask.value & layer) == layer;
if (ppsVolume != null && inLayer && ppsVolume.profile != null && ppsVolume.profile.TryGetSettings<DepthOfField>(out dof))
{
volume = ppsVolume;
break;
}
}
}
}
if (dof == null)
{
Debug.LogError("找不到景深");
}
}
using UnityEngine.Rendering.PostProcessing;
引入后处理的命名空间,先获取PostProcessVolume对象,从PostProcessVolume中尝试获取对应的后处理脚本对象,并修改参数