Skip to content

PreviewCameraSetup

ClassAssetInventoryAssetInventory.Editor
public static class PreviewCameraSetup

Centralized camera creation and positioning for all preview types. Consolidates camera logic from PreviewManager, CustomPreviewStage, and PreviewSceneSetup.

public const float DefaultPreviewFOV = 30

Returns

System.Single

public const float DefaultNearClip = 0.01

Returns

System.Single

public static Camera CreatePreviewCamera(Scene scene, bool addToScene = true)

Create and configure a preview camera in the specified scene

Parameters

NameType
sceneUnityEngine.SceneManagement.Scene
addToSceneSystem.Boolean

Returns

UnityEngine.Camera

public static void SetupCameraBackground(Camera camera)

Setup camera background based on configuration

Parameters

NameType
cameraUnityEngine.Camera
public static Color GetBackgroundColor()

Get background color based on render pipeline

Returns

UnityEngine.Color

public static void PositionCameraForScene(Camera camera, Bounds bounds)

Position camera for scene rendering based on scene bounds

Parameters

NameType
cameraUnityEngine.Camera
boundsUnityEngine.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

NameTypeDescription
boundsUnityEngine.BoundsThe bounding box of the object to frame
cameraUnityEngine.CameraThe camera (for FOV)
paddingPercentSystem.SinglePadding as a percentage (e.g., 2 for 2%)
angleXSystem.SingleVertical camera angle in degrees (0 = eye level, 90 = top-down)
angleYSystem.SingleHorizontal camera angle in degrees (rotation around Y axis)
fillFractionSystem.SingleTarget 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

NameTypeDescription
cameraUnityEngine.CameraThe camera to move.
pointsSystem.Collections.Generic.IReadOnlyList{UnityEngine.Vector3}World space points that have to be visible.
paddingPercentSystem.SingleAdditional 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

NameTypeDescription
cameraUnityEngine.CameraThe camera to move, keeping its direction.
centerUnityEngine.Vector3The point the camera will orbit around.
pointsSystem.Collections.Generic.IReadOnlyList{UnityEngine.Vector3}World space points that have to be visible.
paddingPercentSystem.SingleAdditional padding as a percentage (e.g., 2 for 2%).
public static float CalculateCameraDistance(Bounds bounds, Camera camera)

Simplified overload using current config settings for angles and padding

Parameters

NameType
boundsUnityEngine.Bounds
cameraUnityEngine.Camera

Returns

System.Single

public static void PositionCameraFor3D(Camera camera, Bounds bounds)

Position perspective camera for 3D object rendering

Parameters

NameType
cameraUnityEngine.Camera
boundsUnityEngine.Bounds