Unity使用脚本获取Post Process Volume的参数
问:如何通过代码来控制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));
}
}