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

Name Type
scene UnityEngine.SceneManagement.Scene
addToScene System.Boolean

Returns

UnityEngine.Camera

public static void SetupCameraBackground(Camera camera)

Setup camera background based on configuration

Parameters

Name Type
camera UnityEngine.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

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

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

public static void PositionCameraFor3D(Camera camera, Bounds bounds)

Position perspective camera for 3D object rendering

Parameters

Name Type
camera UnityEngine.Camera
bounds UnityEngine.Bounds