Skip to content

SandboxTools

namespace Griff.Modules.Contraptions;
public sealed class SandboxTools : Component

Garry’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.

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.

public SandboxTool? Current { get; }

The tool in hand, or null if it has none.

public string? CurrentProp { get; }

The prop the Spawn tool puts down, or null if there are none.

public float GrabStrength { get; set; }

How hard a grabbed thing is pulled to the mouse: higher follows more tightly.

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.

public int Selected { get; set; }

The tool in hand, counting from 0 along Tools.

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).

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.

public Key UndoKey { get; set; }

The key that undoes the last prop, weld, hinge, rope or wire made.

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.

public Scope Covering()

The part of the scene it covers (see Within).