logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class PreviewHitTesting

    Turns a preview element's live UnityEngine.RectTransform into a rotation-safe PreviewQuad, and resolves mouse points against it: which element is under the pointer, and which handle of the selected one.

    Inheritance
    object
    PreviewHitTesting
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.Ui.Infrastructure.Editor.Preview
    Assembly: Serenity.UnityUi.Infrastructure.Editor.dll
    Syntax
    public static class PreviewHitTesting
    Remarks

    Every method here is meant to be called fresh at draw time, never cached across frames — the rig rebuilds its content on every render, and a ContentSizeFitter has not necessarily settled inside the build callback itself, so the only safe moment to read bounds is while actually drawing.

    Methods

    CentreLocal(PreviewQuad)

    The quad's centre, in the element's own local space.

    Declaration
    public static Vector2 CentreLocal(PreviewQuad quad)
    Parameters
    Type Name Description
    PreviewQuad quad

    The element's quad.

    Returns
    Type Description
    Vector2

    The midpoint of the quad's local bounds.

    DeformedAxesFor(PreviewHandle)

    Which of the element's own local axes a scale handle deforms.

    Declaration
    public static (bool X, bool Y) DeformedAxesFor(PreviewHandle handle)
    Parameters
    Type Name Description
    PreviewHandle handle

    The handle to classify.

    Returns
    Type Description
    (bool X, bool Y)

    Whether the local X and Y axes are each deformed by this handle.

    Remarks

    An edge handle deforms only the axis it sits on; a corner handle deforms both, independently.

    FramePointFor(PreviewQuad, PreviewHandle)

    The frame-space position a handle draws and hit-tests at.

    Declaration
    public static Vector2 FramePointFor(PreviewQuad quad, PreviewHandle handle)
    Parameters
    Type Name Description
    PreviewQuad quad

    The element's quad.

    PreviewHandle handle

    The handle to locate; a rotate band handle resolves to its corner's position, and the rotation handle resolves to its knob's position.

    Returns
    Type Description
    Vector2

    The handle's frame-space position.

    GestureKindFor(PreviewHandle)

    Which kind of gesture grabbing this handle starts.

    Declaration
    public static PreviewGestureKind GestureKindFor(PreviewHandle handle)
    Parameters
    Type Name Description
    PreviewHandle handle

    The grabbed handle.

    Returns
    Type Description
    PreviewGestureKind

    The gesture the handle begins.

    InflatedForRotateBand(Rect)

    The frame grown by however far a rotate gesture can legitimately start outside it.

    Declaration
    public static Rect InflatedForRotateBand(Rect frame)
    Parameters
    Type Name Description
    Rect frame

    The preview frame, in screen pixels.

    Returns
    Type Description
    Rect

    The frame inflated by the outer reach of the rotate affordances.

    Remarks

    The rotation handle's knob can reach further out than the corner band alone: a top-anchored element's knob sits stick-length-plus-hit-radius above the frame, past where the band's own radius would already have covered it. Taking the larger of the two keeps a selected element pinned to a frame corner fully grabbable.

    IsRotateHandle(PreviewHandle)

    Whether a handle is one of the four rotate band zones or the rotation handle's knob.

    Declaration
    public static bool IsRotateHandle(PreviewHandle handle)
    Parameters
    Type Name Description
    PreviewHandle handle

    The handle to classify.

    Returns
    Type Description
    bool

    LocalAxesFor(PreviewQuad)

    The element's own local +X and +Y axes, in frame-space screen pixels.

    Declaration
    public static (Vector2 X, Vector2 Y) LocalAxesFor(PreviewQuad quad)
    Parameters
    Type Name Description
    PreviewQuad quad

    The element's quad.

    Returns
    Type Description
    (Vector2 X, Vector2 Y)

    The local +X and +Y axes, not necessarily normalized.

    Remarks

    Read straight off the quad's own corners rather than derived from its rotation, so the axes automatically follow whatever the quad already carries — including mirroring. The constructor order is TopLeft, TopRight, BottomRight, BottomLeft, so local +X is the top edge (TopRight − TopLeft) and local +Y is the left edge read bottom-to-top (TopLeft − BottomLeft), not BottomLeft − TopLeft: frame space runs +Y down while the element's own local space runs +Y up, and taking the edge the other way silently inverts every vertical deform ratio.

    LocalPointFor(PreviewQuad, PreviewHandle)

    The local-space position (in the element's own reference units) a handle sits at.

    Declaration
    public static Vector2 LocalPointFor(PreviewQuad quad, PreviewHandle handle)
    Parameters
    Type Name Description
    PreviewQuad quad

    The element's quad.

    PreviewHandle handle

    The handle to locate.

    Returns
    Type Description
    Vector2

    The handle's local position.

    OppositeLocalPointFor(PreviewQuad, PreviewHandle)

    The local-space position of the handle diagonally or edge-wise opposite a scale handle.

    Declaration
    public static Vector2 OppositeLocalPointFor(PreviewQuad quad, PreviewHandle handle)
    Parameters
    Type Name Description
    PreviewQuad quad

    The element's quad.

    PreviewHandle handle

    The grabbed scale handle.

    Returns
    Type Description
    Vector2

    The opposite handle's local position.

    Remarks

    The default fixed point a scale gesture holds still, unless Alt asks for the centre instead.

    ResolveFixedPointLocal(PreviewQuad, PreviewHandle, bool)

    The point a gesture holds still, per the modifier table: a move always holds the centre; a scale holds the opposite corner/edge by default and the centre with Alt; a rotate holds the centre by default and the anchor — uncompensated — with Alt.

    Declaration
    public static Vector2 ResolveFixedPointLocal(PreviewQuad quad, PreviewHandle handle, bool useAnchor)
    Parameters
    Type Name Description
    PreviewQuad quad

    The element's quad at gesture start.

    PreviewHandle handle

    The grabbed handle.

    bool useAnchor

    Whether Alt is held, which swaps the default fixed point.

    Returns
    Type Description
    Vector2

    The fixed point in the element's own local space.

    ResolveHandle(PreviewQuad, Vector2)

    Resolves which part of the selected element's gizmo a point is over, in priority order: the rotation handle's knob first (the explicit affordance wins any tie with a corner underneath it), then the rotate band outside a corner, then a scale handle, then the element's own body.

    Declaration
    public static PreviewHandle ResolveHandle(PreviewQuad quad, Vector2 point)
    Parameters
    Type Name Description
    PreviewQuad quad

    The selected element's quad.

    Vector2 point

    The frame-space point to test.

    Returns
    Type Description
    PreviewHandle

    The handle under the point, or None.

    TryElementQuad(PreviewSceneRenderer, RectTransform, Rect, out PreviewQuad)

    Projects an element's container into a frame-space quad: its untransformed footprint, read in the container's own local space where rotation and scale are identity, then pushed through the container's transform, the canvas root and the renderer's normalization into frame pixels.

    Declaration
    public static bool TryElementQuad(PreviewSceneRenderer renderer, RectTransform container, Rect frame, out PreviewQuad quad)
    Parameters
    Type Name Description
    PreviewSceneRenderer renderer

    The rig that rendered the element, for the canvas-to-normalized mapping.

    RectTransform container

    The element's root UnityEngine.RectTransform.

    Rect frame

    The screen rect the preview texture is currently drawn into.

    PreviewQuad quad

    The projected quad, when this returns true.

    Returns
    Type Description
    bool

    False when the renderer, container or canvas root is unavailable right now.

    TryFindElementAt(PreviewSceneRenderer, IReadOnlyList<PreviewElementHandle>, Rect, Vector2)

    Finds the topmost element under a frame-space point.

    Declaration
    public static int TryFindElementAt(PreviewSceneRenderer renderer, IReadOnlyList<PreviewElementHandle> handles, Rect frame, Vector2 point)
    Parameters
    Type Name Description
    PreviewSceneRenderer renderer

    The rig the elements were rendered with.

    IReadOnlyList<PreviewElementHandle> handles

    Every element's index and container, as built by the last render.

    Rect frame

    The screen rect the preview texture is currently drawn into.

    Vector2 point

    The frame-space point to test, usually the mouse position.

    Returns
    Type Description
    int

    The hit element's index, or -1 when nothing is under the point.

    In this article
    © 2026 Serenity. All Rights Reserved