logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class PreviewSceneRenderer

    Off-screen render rig for the View Preview tool: a hidden WorldSpace UnityEngine.Canvas sized to the chosen reference resolution, captured by an orthographic UnityEngine.Camera into a UnityEngine.RenderTexture. The caller populates the canvas with real (themed) UI prefabs each frame; the rig renders them and returns the texture for the editor window to blit.

    Inheritance
    object
    PreviewSceneRenderer
    Implements
    IDisposable
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    Namespace: Serenity.Ui.Infrastructure.Editor.Preview
    Assembly: Serenity.UnityUi.Infrastructure.Editor.dll
    Syntax
    public sealed class PreviewSceneRenderer : IDisposable
    Remarks

    WorldSpace (not ScreenSpaceCamera) keeps the mapping explicit and edit-mode-stable: the canvas is exactly refW × refH world units centered at the origin, the camera sees exactly that region, so canvas-local coordinates equal reference pixels — which the window reuses for click hit-testing. Everything is created with UnityEngine.HideFlags.HideAndDontSave and torn down in Dispose().

    Constructors

    PreviewSceneRenderer()

    Declaration
    public PreviewSceneRenderer()

    Properties

    CanvasRoot

    The canvas root that builders parent content under (sized to the reference resolution).

    Declaration
    public RectTransform CanvasRoot { get; }
    Property Value
    Type Description
    RectTransform

    ContentScale

    The scale applied to fit the content into the screen (1 = no down-scaling).

    Declaration
    public float ContentScale { get; }
    Property Value
    Type Description
    float

    ReferenceHeight

    The reference height currently configured (canvas units).

    Declaration
    public int ReferenceHeight { get; }
    Property Value
    Type Description
    int

    ReferenceWidth

    The reference width currently configured (canvas units).

    Declaration
    public int ReferenceWidth { get; }
    Property Value
    Type Description
    int

    Methods

    CanvasLocalToNormalized(Vector2)

    Converts a canvas-local point (reference units, origin at canvas centre) to a normalized 0..1 point within the rendered texture (x right, y DOWN to match IMGUI).

    Declaration
    public Vector2 CanvasLocalToNormalized(Vector2 canvasLocalPoint)
    Parameters
    Type Name Description
    Vector2 canvasLocalPoint

    Point in the canvas root's local space.

    Returns
    Type Description
    Vector2

    Normalized point in the displayed texture.

    Dispose()

    Destroys the hidden rig and texture. Safe to call multiple times.

    Declaration
    public void Dispose()

    Render(int, int, Action<RectTransform>, bool)

    Renders the selected view: (re)configures the rig to the reference resolution, clears prior content, lets build populate the canvas, then renders and returns the texture.

    Declaration
    public Texture Render(int refWidth, int refHeight, Action<RectTransform> build, bool fitToContent = false)
    Parameters
    Type Name Description
    int refWidth

    Reference width in canvas units.

    int refHeight

    Reference height in canvas units.

    Action<RectTransform> build

    Callback that builds the view under the provided canvas root.

    bool fitToContent
    Returns
    Type Description
    Texture

    The render texture holding the result (owned by the rig; do not destroy).

    Implements

    IDisposable
    In this article
    © 2026 Serenity. All Rights Reserved