Unity使用指令碼獲取Post Process Volume的引數
阿新 • • 發佈:2021-10-25
問:如何通過程式碼來控制PostProcessVolume裡的引數
Modifying the new Post-Processing Stack through code? - Unity Answers
這個問答裡2020年4月8日warpfx的那個回答,正解!
專案URP,PostProcessing version 2.3.0
using UnityEngine; using UnityEngine.Rendering; using UnityEngine.Rendering.Universal;//不再用using UnityEngine.Rendering.PostProcessing; public class PostProcess_anime : MonoBehaviour { Volume myVolume;//不再是PostProcessVolume myVolume; LensDistortion lens; void Start() { myVolume = this.GetComponent<Volume>(); myVolume.profile.TryGet<LensDistortion>(out lens); //不是myVolume.profile.TryGetSettings<LensDistortion>(out lens); } void Update() { //不是lens.centerX.value = Mathf.Sin(0.1f * Time.time) * 0.25f + 0.5f; //上面這個方法已經不能賦值了,要下面這樣的,用SetValue才能賦值 float x = Mathf.Sin(0.1f * Time.time) * 0.25f + 0.5f; float y = Mathf.Sin(0.1f * Time.time) * 0.25f + 0.5f; Vector2 center = new Vector2( x, y ); lens.center.SetValue(new Vector2Parameter(center,true)); } }