1. 程式人生 > >unity如何動態控制後處理程式的引數

unity如何動態控制後處理程式的引數

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中嘗試獲取對應的後處理指令碼物件,並修改引數