PreviewCameraSetup
public static class PreviewCameraSetupCentralized camera creation and positioning for all preview types. Consolidates camera logic from PreviewManager, CustomPreviewStage, and PreviewSceneSetup.
Fields
Section titled “Fields”
DefaultPreviewFOV
Section titled “DefaultPreviewFOV”public const float DefaultPreviewFOV = 30Returns
System.Single
DefaultNearClip
Section titled “DefaultNearClip”public const float DefaultNearClip = 0.01Returns
System.Single
Methods
Section titled “Methods”
CreatePreviewCamera(Scene, bool)
Section titled “CreatePreviewCamera(Scene, bool)”public static Camera CreatePreviewCamera(Scene scene, bool addToScene = true)Create and configure a preview camera in the specified scene
Parameters
| Name | Type |
|---|---|
scene | UnityEngine.SceneManagement.Scene |
addToScene | System.Boolean |
Returns
UnityEngine.Camera
SetupCameraBackground(Camera)
Section titled “SetupCameraBackground(Camera)”public static void SetupCameraBackground(Camera camera)Setup camera background based on configuration
Parameters
| Name | Type |
|---|---|
camera | UnityEngine.Camera |
GetBackgroundColor()
Section titled “GetBackgroundColor()”public static Color GetBackgroundColor()Get background color based on render pipeline
Returns
UnityEngine.Color
PositionCameraForScene(Camera, Bounds)
Section titled “PositionCameraForScene(Camera, Bounds)”public static void PositionCameraForScene(Camera camera, Bounds bounds)Position camera for scene rendering based on scene bounds
Parameters
| Name | Type |
|---|---|
camera | UnityEngine.Camera |
bounds | UnityEngine.Bounds |
CalculateCameraDistance(Bounds, Camera, float, float, float, float)
Section titled “CalculateCameraDistance(Bounds, Camera, float, float, float, float)”public static float CalculateCameraDistance(Bounds bounds, Camera camera, float paddingPercent, float angleX, float angleY, float fillFraction = 1)Calculate the optimal camera distance for framing an object with configurable padding. Uses a hybrid approach: projected bounds calculation verified by corner projection to ensure all 8 bounding box corners fit within the view frustum.
Parameters
| Name | Type | Description |
|---|---|---|
bounds | UnityEngine.Bounds | The bounding box of the object to frame |
camera | UnityEngine.Camera | The camera (for FOV) |
paddingPercent | System.Single | Padding as a percentage (e.g., 2 for 2%) |
angleX | System.Single | Vertical camera angle in degrees (0 = eye level, 90 = top-down) |
angleY | System.Single | Horizontal camera angle in degrees (rotation around Y axis) |
fillFraction | System.Single | Target viewport fill (1 = fit exactly). Lower values bring the camera closer. |
Returns
System.Single: The optimal distance from the camera to the bounds center
FitCameraToPoints(Camera, IReadOnlyList, float)
Section titled “FitCameraToPoints(Camera, IReadOnlyList, float)”public static bool FitCameraToPoints(Camera camera, IReadOnlyList<Vector3> points, float paddingPercent = 0)Moves a perspective camera so that all points are centered and just fit into the square view, keeping its rotation. A point restricts the camera position linearly per view axis, which allows solving for it directly: in view space |x - camX| must not exceed (z - camZ) * tan(fov / 2) for every point, and likewise for y.
Parameters
| Name | Type | Description |
|---|---|---|
camera | UnityEngine.Camera | The camera to move. |
points | System.Collections.Generic.IReadOnlyList{UnityEngine.Vector3} | World space points that have to be visible. |
paddingPercent | System.Single | Additional padding as a percentage (e.g., 2 for 2%). |
Returns
System.Boolean: False if the camera could not be positioned, it stays untouched then.
FitCameraForOrbit(Camera, Vector3, IReadOnlyList, float)
Section titled “FitCameraForOrbit(Camera, Vector3, IReadOnlyList, float)”public static void FitCameraForOrbit(Camera camera, Vector3 center, IReadOnlyList<Vector3> points, float paddingPercent = 0)Moves a perspective camera to look at the center from a distance at which the points stay visible from all sides.
Parameters
| Name | Type | Description |
|---|---|---|
camera | UnityEngine.Camera | The camera to move, keeping its direction. |
center | UnityEngine.Vector3 | The point the camera will orbit around. |
points | System.Collections.Generic.IReadOnlyList{UnityEngine.Vector3} | World space points that have to be visible. |
paddingPercent | System.Single | Additional padding as a percentage (e.g., 2 for 2%). |
CalculateCameraDistance(Bounds, Camera)
Section titled “CalculateCameraDistance(Bounds, Camera)”public static float CalculateCameraDistance(Bounds bounds, Camera camera)Simplified overload using current config settings for angles and padding
Parameters
| Name | Type |
|---|---|
bounds | UnityEngine.Bounds |
camera | UnityEngine.Camera |
Returns
System.Single
PositionCameraFor3D(Camera, Bounds)
Section titled “PositionCameraFor3D(Camera, Bounds)”public static void PositionCameraFor3D(Camera camera, Bounds bounds)Position perspective camera for 3D object rendering
Parameters
| Name | Type |
|---|---|
camera | UnityEngine.Camera |
bounds | UnityEngine.Bounds |