问:如何通过代码来控制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));
    }
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-14
  • 2021-07-09
  • 2022-01-17
  • 2021-08-07
  • 2021-04-15
  • 2022-02-19
  • 2022-01-01
相关资源
相似解决方案