英文:
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<HDAdditionalCameraData>();
}
答案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<Camera>();
}
public void SetLensShift(Vector2 value)
{
_camera.lensShift = value;
}
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论