Class PreviewGestureCoordinator
Everything the mouse does over a direct-manipulation preview: hit-testing the pointer against the rendered elements, click-to-select, and running a move/scale/rotate gesture against the selected one.
Inherited Members
Namespace: Serenity.Ui.Infrastructure.Editor.Preview
Assembly: Serenity.UnityUi.Infrastructure.Editor.dll
Syntax
public sealed class PreviewGestureCoordinator
Remarks
Owns the preview's selection and hover state outright, so there is exactly one writer for it — the window and the overlay painter read it back through this object rather than keeping copies. That single ownership is the point of the split: the hover index, the grabbed handle and the gesture's hot control are only ever consistent when one place advances them.
Reaches the window through providers rather than holding it, so nothing here binds to an UnityEditor.EditorWindow: the rig and its element handles are re-read on every call because a render replaces them, and repaint and interaction notices go out as callbacks. What it previews is reached through IPreviewPlacementTarget rather than any one asset type, so the same coordinator drives a HUD preview and any other screen-anchored preview alike.
Constructors
PreviewGestureCoordinator(Func<PreviewSceneRenderer>, Func<IReadOnlyList<PreviewElementHandle>>, IPreviewPlacementTarget, PreviewGestureController, Action, Action<PreviewInteraction>)
Creates a coordinator.
Declaration
public PreviewGestureCoordinator(Func<PreviewSceneRenderer> renderer, Func<IReadOnlyList<PreviewElementHandle>> elementHandles, IPreviewPlacementTarget target, PreviewGestureController controller, Action repaint, Action<PreviewInteraction> interacted)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<PreviewSceneRenderer> | renderer | The preview's current scene renderer, re-read on every call. |
| Func<IReadOnlyList<PreviewElementHandle>> | elementHandles | The rig's element handles from the latest render, re-read on every call. |
| IPreviewPlacementTarget | target | What is being previewed, for reading and writing element placements. |
| PreviewGestureController | controller | Tracks the in-progress gesture, if any. |
| Action | repaint | Requests a repaint of the window hosting this preview. |
| Action<PreviewInteraction> | interacted | Raised when an element is selected or transformed by direct manipulation. |
Properties
Controller
The gesture currently running, for the overlays that draw and describe it.
Declaration
public PreviewGestureController Controller { get; }
Property Value
| Type | Description |
|---|---|
| PreviewGestureController |
HasRenderedContent
Whether the rig has actually rendered something to hit-test and draw over.
Declaration
public bool HasRenderedContent { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Remarks
One reader for both halves of direct manipulation: the mouse must not resolve handles against a rig that a render has since replaced, and the overlays must not draw chrome for elements that no longer have containers. Both ask here rather than each holding their own copy of the rig.
HoverElementIndex
The element under the pointer, or -1 for none.
Declaration
public int HoverElementIndex { get; }
Property Value
| Type | Description |
|---|---|
| int |
HoverHandle
The handle under the pointer on the selected element, or None.
Declaration
public PreviewHandle HoverHandle { get; }
Property Value
| Type | Description |
|---|---|
| PreviewHandle |
IsLive
Whether anything is animating or reacting to the mouse, so the window can idle otherwise.
Declaration
public bool IsLive { get; }
Property Value
| Type | Description |
|---|---|
| bool |
SelectedElementIndex
The element the author has selected, or -1 for none.
Declaration
public int SelectedElementIndex { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
AbandonAfterUndoRedo()
Abandons whatever the preview itself had running because the author's own undo or redo moved the stack underneath it.
Declaration
public void AbandonAfterUndoRedo()
Remarks
Unconditional where Cancel() returns early, and deliberately so: outside a gesture there is no per-frame run to revert — the author's keystroke already put the stack exactly where they meant it — but the controller and the hot control are still cleared, because a controller left holding a half-state across an undo is what a later passive hover would read as a live drag.
Cancel()
Drops the running gesture, restoring the element to its pre-gesture placement.
Declaration
public void Cancel()
Remarks
Also the guard against a stale gesture surviving a domain reload, or one stranded by losing
UnityEngine.GUIUtility.hotControl mid-drag (dragged out of the window, or the reload itself, since
the hot control is not serialized): the gesture controller's own state is [Serializable] and
rides out a reload on the window, but the rig and its element handles do not, so
HandleMouse(Rect) calls this the moment either guard trips.
Every write during the gesture went through UnityEditor.SerializedObject.ApplyModifiedProperties, so it recorded an Undo step whether the target is a saved asset or the wizard's own non-persistent scratch — UnityEditor.Undo.RevertAllDownToGroup(System.Int32) wipes the whole gesture off the Undo stack on either one, leaving it exactly as if it had never happened, with no manual restore needed.
ContainerFor(int)
The live container the rig built for an element, or null when it built none.
Declaration
public RectTransform ContainerFor(int elementIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | elementIndex | The element to locate. |
Returns
| Type | Description |
|---|---|
| RectTransform | The element's container, or null. |
DescribeElement(int)
A label for the element, for overlay chips and tooltips.
Declaration
public string DescribeElement(int elementIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | elementIndex | The element to describe. |
Returns
| Type | Description |
|---|---|
| string | The label, from the target. |
FinishIfRunning()
Collapses the running gesture's per-frame writes into one Undo step and releases the mouse, without repainting — for a window closing mid-gesture, which is about to stop existing anyway.
Declaration
public void FinishIfRunning()
HandleMouse(Rect)
Routes the mouse to hover tracking and, while a gesture is running, to it — otherwise a click either grabs a handle on the already-selected element or selects whatever is under the pointer.
Declaration
public void HandleMouse(Rect frame)
Parameters
| Type | Name | Description |
|---|---|---|
| Rect | frame | The rectangle the preview is drawn into, in screen pixels. |
SelectSilently(int)
Selects an element on the caller's behalf, without raising PreviewInteraction.
Declaration
public void SelectSilently(int elementIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| int | elementIndex | The element to select. |
Remarks
The builder pushing its own selection into the preview is not the preview reporting one back; raising here would echo the selection straight back at the window that just set it.
TryPlacementAt(int, out PreviewElementPlacement)
The placement of the element at an index, read fresh from the target.
Declaration
public bool TryPlacementAt(int elementIndex, out PreviewElementPlacement placement)
Parameters
| Type | Name | Description |
|---|---|---|
| int | elementIndex | The element to read. |
| PreviewElementPlacement | placement | The element's placement, when found. |
Returns
| Type | Description |
|---|---|
| bool | False when the index no longer addresses an element. |
TryQuadFor(int, Rect, out PreviewQuad)
The element's quad for this frame, or false when it has no live container to read.
Declaration
public bool TryQuadFor(int elementIndex, Rect frame, out PreviewQuad quad)
Parameters
| Type | Name | Description |
|---|---|---|
| int | elementIndex | The element to locate. |
| Rect | frame | The rectangle the preview is drawn into, in screen pixels. |
| PreviewQuad | quad | The element's quad in frame space. |
Returns
| Type | Description |
|---|---|
| bool | Whether a quad could be resolved. |