SandboxTools
namespace Griff.Modules.Contraptions;
public sealed class SandboxTools : ComponentGarry’s Mod style tools for building contraptions while the game runs: grab and throw things, freeze them in place, spawn props, weld, hinge and rope them together, wire buttons to lamps, thrusters and wheels’ motors, and remove them. Pick a tool along the top of the screen (or with the number keys and mouse wheel); Z undoes the last thing made.
Props are prefabs: give them a Body and a collider to grab and weld them, and wiring parts (WireGate, WireButton, WireLamp, Thruster…) to wire them. Things built with the tools are kept in the scene, so Keep Play Changes (Ctrl+K) brings a contraption back to the editor.
This is a component: its saved properties are on its component page.
Properties
Section titled “Properties”Controllable
Section titled “Controllable”public bool Controllable { get; set; }Untick it to put the tools down: no HUD, and clicks and keys go to whatever else has the player’s input. Its Focus action ticks it and unticks it on everything else the player plays, and another’s Focus takes it back.
Current
Section titled “Current”public SandboxTool? Current { get; }The tool in hand, or null if it has none.
CurrentProp
Section titled “CurrentProp”public string? CurrentProp { get; }The prop the Spawn tool puts down, or null if there are none.
GrabStrength
Section titled “GrabStrength”public float GrabStrength { get; set; }How hard a grabbed thing is pulled to the mouse: higher follows more tightly.
PropList
Section titled “PropList”public IReadOnlyList<string> PropList { get; }The props as listed in Props.
public string? Props { get; set; }The props the Spawn tool can put down, by prefab name, separated by commas, e.g. “Crate, Ball, Lamp”.
public float Reach { get; set; }How far from the entity the tools reach, in world units. 0 reaches anywhere on screen.
Selected
Section titled “Selected”public int Selected { get; set; }The tool in hand, counting from 0 along Tools.
SelectedProp
Section titled “SelectedProp”public int SelectedProp { get; set; }The prop the Spawn tool puts down, counting from 0 along Props.
public string? Sound { get; set; }A sound played when a tool does something (spawns, welds, wires).
ToolList
Section titled “ToolList”public IReadOnlyList<SandboxTool> ToolList { get; }The tools as listed in Tools; anything that isn’t a tool is skipped.
public string? Tools { get; set; }The tools it has, in order, separated by commas: Grab, Spawn, Weld, Hinge, Rope, Wire and Remove.
UndoKey
Section titled “UndoKey”public Key UndoKey { get; set; }The key that undoes the last prop, weld, hinge, rope or wire made.
Within
Section titled “Within”public string? Within { get; set; }The part of the scene the tools work on, by an entity’s name: they grab, weld, rope, wire and remove only what’s inside that entity or standing in its area (a Room’s, a tilemap’s, a collider’s), and spawn only in its area (or, for an entity with no area, into it), e.g. “Workshop”. Empty works on the whole scene.
Methods
Section titled “Methods”Covering
Section titled “Covering”public Scope Covering()The part of the scene it covers (see Within).