Get RAPTOR

RaptorSuiteBoxDraw

The New Block box-draw gesture for tools in other assemblies.

NamespaceAssemblyKindStability
Raptor.EditorToolsRaptor.Editorclasspreview, since 0.1.0

Uses the same gesture as New Block: click a corner on a surface, click the far corner, then click the height. Snapping, the size-labelled preview and the toasts are also the same. The caller creates the box.

All tools share one gesture state, since only one toolbar tool can be equipped at a time. Call Claim so that another tool's draw-mode reset does not clear your box.

Call SceneEvent from SceneView.beforeSceneGui and DrawPreview from SceneView.duringSceneGui on Repaint. A tool with its own event loop can drive the gesture with Track, (which returns a Press), Box, Model, Committed, Cancel, Reset, Cursor, YieldsPress and RoomRefusal.

public static class RaptorSuiteBoxDraw

Fields

MeshRoomText

public const string MeshRoomText;

The toast shown when the target model is a Mesh model. Returned by RoomRefusal.

ReadOnlyRoomText

public const string ReadOnlyRoomText;

The toast shown when the target model is a read-only model of the older kind. Returned by RoomRefusal.

TooSmallText

public const string TooSmallText;

The toast shown when the box is too small.

Properties

Claimed

public static bool Claimed { get; }

Whether an outside tool owns the gesture.

Drawing

public static bool Drawing { get; }

Whether a box is being made, in either the footprint or the height stage.

GridStep

public static float GridStep { get; }

The grid step the draw snaps to, in metres.

Hovering

public static bool Hovering { get; }

Whether the draw is idle with the pointer over a surface a box can start on.

LastReadout

public static string LastReadout { get; }

The size readout the last preview drew, such as "w 2 m", "h 1.5 m" or "d 3 m". Empty when idle. Used by tests.

Model

public static RaptorModel Model { get; }

The model the first click landed on, or null for the work plane or ground.

Methods

Box

public static bool Box(out Vector3 center, out Quaternion rotation, out Vector3 size)

Gets the box being made, as it would turn out.

ParameterTypeDescription
centerout Vector3The box's centre.
rotationout QuaternionThe box's rotation.
sizeout Vector3The box's size.

Returns: False when idle.

BoxFrom

public static void BoxFrom(Vector3 a, Vector3 b, Vector3 u, Vector3 v, Vector3 n, float height, out Vector3 center, out Quaternion rotation, out Vector3 size)

Computes the box a draw gesture makes, as New Block places it (CreateMeshBox). Has no side effects. The footprint runs from a to b on the draw plane's u and v axes and is extruded by height along n.

When n, u and v lie on world axes, the box has no rotation and its size is in world axes (Width = X, Height = Y, Depth = Z). Otherwise the box is rotated to the plane: local Y is the normal (Height), local Z is v (Depth) and local X is ±u (Width). center is the box's centre in both cases.

ParameterTypeDescription
aVector3One footprint corner.
bVector3The opposite corner.
uVector3The draw plane's first axis.
vVector3The draw plane's second axis.
nVector3The plane's normal.
heightfloatThe extrusion; negative goes into the surface.
centerout Vector3The box's centre.
rotationout QuaternionThe box's rotation.
sizeout Vector3The box's size.

Cancel

public static bool Cancel()

Cancels the box being made.

Returns: True when a box was in progress.

Claim

public static void Claim(Func<bool> drawing)

Claims the gesture. While drawing returns true, the box in progress belongs to the caller.

ParameterTypeDescription
drawingFunc<bool>Returns true while the caller owns the box in progress.

Click

public static Press Click(float minSize)

Handles a left press in the 3D view. Call Track for the event first. When idle, the press places the first corner and fixes the plane and the model. In the footprint stage it places the far corner; a footprint smaller than minSize is refused and sizing continues. In the height stage it returns Press.Commit when the box is ready, or Press.TooSmall when it is too thin. After Press.Commit, make the box and call Committed.

ParameterTypeDescription
minSizefloatThe smallest side a box may have, in metres.

Returns: What the press did.

Committed

public static void Committed()

Resets the draw to idle. Call it after the box is made.

ContainerFor

public static Transform ContainerFor(RaptorModel model, string sceneRootName)

Gets the parent for a newly made object. With a model, this is the model's Gameplay container. Without one, it is the open prefab's root, or else the root scene object named sceneRootName. Missing containers are created in the current Undo group.

ParameterTypeDescription
modelRaptorModelThe model, or null.
sceneRootNamestringThe root scene object's name, used when there is no model.

Returns: The container.

Cursor

public static bool Cursor(out Vector3 point)

Gets the corner being placed. When idle, this is the hover point. Otherwise it is the far corner.

ParameterTypeDescription
pointout Vector3The corner.

Returns: False when no surface is under the pointer.

DefaultModel

public static RaptorModel DefaultModel()

Gets the model "+ Add" uses when nothing was clicked. This is the pinned target, or else the selection's model, or else the only model.

Returns: The model, or null when there is none or it is locked in this mode.

DrawBox

public static void DrawBox(Vector3 center, Quaternion rotation, Vector3 size, bool withHeight)

Draws a box in New Block's preview style, labelled with its Width and Depth, and with its Height when withHeight is true. Draws on Repaint only.

ParameterTypeDescription
centerVector3The box's centre.
rotationQuaternionThe box's rotation.
sizeVector3The box's size.
withHeightboolWhether to label the height.

DrawPreview

public static void DrawPreview(SceneView view)

Draws the box in progress with its sizes, or the corner marker when idle. Draws on Repaint only.

ParameterTypeDescription
viewSceneViewThe Scene view.

Reset

public static void Reset()

Clears the box in progress and the hover. Call it when leaving the tool or mode.

RoomRefusal

public static string RoomRefusal(RaptorModel model)

Gets the reason a new object can't go into model because of its kind lock.

ParameterTypeDescription
modelRaptorModelThe model.

Returns: ReadOnlyRoomText or MeshRoomText, or null when the model accepts new objects.

SceneEvent

public static bool SceneEvent(SceneView view, Event e, float minSize, CommitBox commit)

Handles one 3D view event. A left press inside the view places the next corner or the height, then calls commit, unless a handle is under the pointer. Esc cancels a box in progress. Camera navigation passes through and keeps the box. MouseMove is tracked but not used.

ParameterTypeDescription
viewSceneViewThe Scene view.
eEventThe event.
minSizefloatThe smallest box size, in metres; a smaller one is refused.
commitCommitBoxCalled once with the finished box.

Returns: True when it used the event.

Track

public static void Track(SceneView view, Event e)

Updates the hover and corner from e. Call it before reading Hovering on a press, because a zoom or keyboard camera move sends no MouseMove.

ParameterTypeDescription
viewSceneViewThe 3D view.
eEventThe event.

YieldsPress

public static bool YieldsPress()

Whether a handle under the pointer, such as a resize dot or a billboard, should take a left press instead of starting a box. A handle counts when the last Layout pick found a control closer than Unity's 5 px pick distance; Unity's default rect selection, at exactly 5 px, does not count. Always false while a box is being made.

Returns: True when a handle should take the press.