CameraController - alexneargarder/Broforce-Docs GitHub Wiki

CameraController

Table of Contents

Unity Lifecycle & Setup

Methods

protected void Awake()

Unity Awake lifecycle method that initializes the singleton instance and configures post-processing effects based on quality settings. Sets up the global instance reference and disables performance-intensive effects (displacement and distortion) when ScreenPostFXLevel is less than 1.


protected void Update()

Unity Update lifecycle method that maintains camera synchronization. Ensures all cameras maintain matching aspect ratios and orthographic sizes with the main camera. The sky camera receives special handling, with its size interpolated based on the SamRaimiEffectM value to create dynamic atmospheric effects.


Camera Management

Properties

public static Camera MainCam { get; set; }

Gets the main camera used for rendering. This property provides static access to either the instance's mainCamera if available, or falls back to Camera.main with frame-based caching for performance optimization. The caching mechanism prevents repeated Camera.main lookups within the same frame.


Fields

public Camera backgroundCamera

Camera dedicated to rendering background elements. Part of the multi-camera layered rendering system that allows separate control over background visuals.


public Camera displacementCamera

Camera used for displacement mapping effects. Works in conjunction with displacementScript to create visual distortion effects. Disabled when ScreenPostFXLevel is less than 1.


public Camera distortionCamera

Camera for rendering distortion effects. Part of the post-processing pipeline and is disabled when ScreenPostFXLevel is less than 1 to improve performance on lower-end systems.


public Camera effectsamera

Camera dedicated to rendering special effects. Note the typo in the field name (effectsamera instead of effectsCamera) is preserved from the original code.


public Camera foliageCamera

Camera responsible for rendering foliage and plant elements. This separate camera allows for specialized rendering of vegetation with different settings or effects.


public Camera groundCamera

Camera for rendering ground and terrain elements. Part of the layered rendering system that separates terrain from other visual elements.


public static CameraController instance

Singleton instance of the CameraController. Set during Awake() to provide global access to the camera management system. This allows other systems to access camera functionality without needing direct references.


public Camera lightingCamera

Camera used for rendering lighting effects. This dedicated camera enables special lighting passes and effects to be composited into the final image.


public Camera mainCamera

Reference to the main rendering camera. This is the primary camera that renders the main game view and serves as the reference for synchronizing orthographic sizes across all other cameras in the system.


public Camera skyCamera

Camera for rendering sky and atmospheric elements. Its orthographic size is specially adjusted based on the SamRaimiEffectM value to create dynamic sky effects.


public Camera uiCamera

Camera dedicated to rendering UI elements. This separation ensures UI renders on top of game elements and isn't affected by game camera effects.


public Camera uiGameplayCamera

Camera for rendering gameplay-related UI elements. Separate from the main UI camera to allow different rendering settings for in-game UI versus menu UI.


public Camera waterCamera

Camera specifically for rendering water effects and surfaces. Allows specialized water rendering techniques to be applied separately from other elements.


Camera Configuration

Properties

public static float DefaultHalfWidth { get; set; }

Gets the default half-width value used for calculating the default orthographic size. This constant value (227f) represents half the horizontal view width in world units.


public static float DefaultOrthographicSize { get; set; }

Gets the default orthographic size calculated from the default half-width and current screen aspect ratio. This provides a consistent base size regardless of screen resolution.


public static float OrthographicSize { get; set; }

Gets or sets the orthographic size for all cameras in the system. When set, synchronizes the orthographic size across all 11 cameras (with special handling for skyCamera based on SamRaimiEffectM). This ensures all visual layers maintain consistent scale.


Visual Effects

Properties

public static float SamRaimiEffectM { get; set; }

Gets or sets the interpolation factor for the "Sam Raimi effect" (named after the filmmaker known for dynamic camera work). This value (0-1) controls special sky camera behavior, with the sky camera's orthographic size interpolating between 128f and the main camera's size based on this factor.


public static int ScreenPostFXLevel { get; set; }

Gets or sets the post-processing effects quality level. This value is stored in PlayerOptions and determines which visual effects are enabled. Values less than 1 disable displacement and distortion effects for performance.


Fields

public DisplacementCamera displacementScript

Reference to the DisplacementCamera component that handles displacement mapping effects. This script is disabled when ScreenPostFXLevel is less than 1 during initialization for performance optimization.


public ImageRefractionEffect imageDistortionScript

Reference to the ImageRefractionEffect component that creates image distortion/refraction effects. Disabled when ScreenPostFXLevel is less than 1 to improve performance on lower-end systems.


private static float samRaimiEffectM

Private static backing field for the SamRaimiEffectM property. Stores the interpolation value (0-1) used to create dynamic sky camera effects inspired by Sam Raimi's cinematography style.


Helper & Utility

Methods

public List<Camera> GetCamerasForGIF()

Creates a list containing only the background camera for GIF capture purposes. This method is used by the GIF recording system to capture simplified footage, focusing only on the background layer rather than the full multi-camera composite.

Returns:

  • List<Camera>: A new List containing only the backgroundCamera reference.

Fields

private static int cachedFrame = -1

Stores the frame number when Camera.main was last cached. Used in the MainCam property getter to optimize performance by preventing repeated Camera.main lookups within the same frame. Initialized to -1 to ensure the first access triggers a cache update.


private static Camera CurCameraMain

Cached reference to Camera.main used by the MainCam property. This caching mechanism works with cachedFrame to avoid the performance cost of repeatedly accessing Camera.main within a single frame, only updating when the frame count changes.


⚠️ **GitHub.com Fallback** ⚠️