Camera2D#
The scene's 2D camera: a built-in Script marking an entity as the active camera and setting how much of the world it shows. Shipped by the engine itself rather than a project script, as Unity's Camera is. The runtime looks for an attached Camera2D rather than special-casing a "Camera2D" string. World framing: with ViewHeight and ViewWidth both 0 the camera shows 2 world units times its own scale vertically (the legacy rule). ViewHeight alone fixes the visible height and the width follows the window. ViewWidth alone fixes the width. With both set, Fit chooses which dimension to preserve. Screen mode uses design pixels, a centred origin and +Y up; camera pose is ignored.
public sealed class Camera2D : ScriptMembers: Fit · Frame · Mode · PointerOver · PointerToWorld · PointerWorld · ViewHeight · ViewWidth
Fit#
[System.ComponentModel.DefaultValue(CameraFit2D.Expand)]
public CameraFit2D Fit { get; set; }Expand shows the whole reference frame, revealing more at one axis. FitHeight or FitWidth fixes that dimension and may crop the other; with only one World dimension set, that dimension always wins.
Frame#
public static Mat3 Frame(Mat3 world, CameraFrame2D frame, float aspect);The camera model for a window of the given aspect (width over height). World mode keeps position and rotation; Screen mode ignores pose and centres design pixels at the origin. Its uniform scale is half the visible height.
Mode#
[System.ComponentModel.DefaultValue(CameraMode2D.World)]
public CameraMode2D Mode { get; set; }World mode follows the camera pose. Screen mode fixes a reference rectangle in design pixels, with (0,0) at its centre, +X right and +Y up. One unit is one pixel at the reference resolution; window resizing scales it.
PointerOver#
public bool PointerOver(RuntimeEntity target, float width, float height);Whether the pointer is inside a rectangle of width × height units centred on target, in this camera's space (the object's rotation is ignored).
PointerToWorld#
public static System.Numerics.Vector2 PointerToWorld(Mat3 cameraModel, System.Numerics.Vector2 pointer, float aspect);Maps a pointer position (0…1 from the top-left of the view) through a camera model (see Frame) into that camera's world, for a view of the given aspect (width over height).
PointerWorld#
public System.Numerics.Vector2 PointerWorld { get; }Where the pointer is in this camera's world, at the view the scene was last drawn with: the point a HUD button under this camera compares against its own rectangle. Each layer camera maps the same pointer into its own space.
ViewHeight#
[System.ComponentModel.DefaultValue(0f)]
public float ViewHeight { get; set; }Reference height in world units, or design pixels in Screen mode. 0 uses legacy scale in World mode when width is also 0; in Screen mode 0 means 1080 design pixels.
ViewWidth#
[System.ComponentModel.DefaultValue(0f)]
public float ViewWidth { get; set; }Reference width in world units, or design pixels in Screen mode. In World mode 0 follows the window's aspect; in Screen mode 0 means 1920 design pixels.
Related types#
CameraFit2D · CameraFrame2D · CameraMode2D · Mat3 · RuntimeEntity · Script
Source#
- Camera2D.cs