通过脚本更改相机镜头的物理偏移轴。

huangapple go评论92阅读模式
英文:

Change physical camera lens shift axis through script

问题

I have an HDRP camera that contains physical properties such as Lens, Aperture, etc. There is a property for Shift (X, Y) under Lens. How do I change the value of X for this property through script?

using UnityEngine.Rendering.HighDefinition;

void Update () {
    HDAdditionalCameraData cameraData = GetComponent<HDAdditionalCameraData>();
}

通过脚本更改相机镜头的物理偏移轴。

英文:

I have an HDRP camera that contain physical properties such as Lens, Aperture etc. There is a property for Shift (X, Y) under Lens. How do I change the value of X for this property through script?

using UnityEngine.Rendering.HighDefinition;

    void Update () {

        HDAdditionalCameraData cameraData = GetComponent&lt;HDAdditionalCameraData&gt;();
    }

通过脚本更改相机镜头的物理偏移轴。

答案1

得分: 1

你需要访问实际的 Camera 组件,而不是 HDAdditionalCameraData,以下是一个示例的 MonoBehaviour,可以实现你想要的功能,使用公共方法 SetLensShift(Vector2)。由你决定何时调用它。

using UnityEngine;

namespace Core
{
    public class LensShiftSetter : MonoBehaviour
    {
        private Camera _camera;
        
        private void Start()
        {
            _camera = GetComponent<Camera>();
        }

        public void SetLensShift(Vector2 value)
        {
            _camera.lensShift = value;
        }
    }
}
英文:

You need to access the actual Camera component, not the HDAdditionalCameraData, this is a sample MonoBehaviour that does what you're looking for, use the public method SetLensShift(Vector2). It's up to you to decide when to call that.

using UnityEngine;

namespace Core
{
    public class LensShiftSetter : MonoBehaviour
    {
        private Camera _camera;
        
        private void Start()
        {
            _camera = GetComponent&lt;Camera&gt;();
        }

        public void SetLensShift(Vector2 value)
        {
            _camera.lensShift = value;
        }
    }
}

huangapple
  • 本文由 发表于 2023年7月4日 21:50:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76613330.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定