定义一个可以从相机叠加层中选择的视点。
将此基类与 ICameraLensData 一起使用来定义一个视点,并在相机叠加层中公开一个组件。如果您在相机叠加层中公开了一个组件,则可以使用相机叠加层在场景视图中查看该组件。
要使用此类,您必须在 MonoBehaviour 中拥有相机镜头的自定义表示。
检测到时,相机叠加层会为场景中类型为 T0 的每个组件创建 Viewpoint 类的实例。
相机叠加层使用附加到组件的 UI 中的图标。
using UnityEngine;
public class MyVirtualCamera : MonoBehaviour { public float fov; public float nearPlane; public float farPlane;
public bool physicalProps; public float focalLength; public Vector2 sensor; public Vector2 lensShift; public Camera.GateFitMode gateFit; }
using UnityEngine; using UnityEditor;
class VirtualCameraViewpoint : Viewpoint<MyVirtualCamera>, ICameraLensData { public VirtualCameraViewpoint(MyVirtualCamera target) : base(target) { }
public float NearClipPlane => Target.nearPlane;
public float FarClipPlane => Target.farPlane;
// If you are not using physical properties, FieldOfView can change from the SceneView with the scrollwheel action while looking through a camera. public float FieldOfView { get => Target.fov; set => Target.fov = value; }
public bool UsePhysicalProperties => Target.physicalProps;
// If you are using physical properties, FocalLength can change from the SceneView with the scrollwheel action while looking through a camera. public float FocalLength { get => Target.focalLength; set => Target.focalLength = value; }
public Vector2 SensorSize => Target.sensor;
public Vector2 LensShift => Target.lensShift;
public Camera.GateFitMode GateFit => Target.gateFit;
// The SceneView sets orthographic to true when: // - the 2DMode button is toggled on. // - orthographic view is set from the Orientation gizmo. // // In this example, our representation doesn't consider orthographic view. public bool Orthographic { get => false; set { } } public float OrthographicSize { get => 0; set { } } }
Viewpoint_1 | 构造函数。 |
CreateVisualElement | 在相机叠加层中选择视点时,会调用 CreateVisualElement。 |