Utilities
Four small helper components: two that dim or disable UI controls while instructions run, one that snaps transforms to pixel or grid positions, and one that drives depth sorting order based on Y position.
DisableOnRunning
Dims a CanvasGroup to half opacity and blocks interaction while the instruction runner is active. On stop, full opacity and interaction are restored. Requires a CanvasGroup on the same GameObject. Subscribes to LevelManager events automatically on Start.
Methods
| Method | Description |
|---|---|
Enable(ExecutionContext context) | Restores alpha to 1 and re-enables interaction. Wired to LevelManager.OnStop. |
Disable(ExecutionContext context) | Sets alpha to 0.5 and disables interaction. Wired to LevelManager.OnPlay. |
DisableButtonOnRunning
Toggles a Button's interactability while the instruction runner is active. Lighter-weight alternative to DisableOnRunning when dimming is not needed — only the click behaviour is blocked. Requires a Button on the same GameObject. Subscribes automatically on Start.
Methods
| Method | Description |
|---|---|
Enable(ExecutionContext context) | Re-enables the button. Wired to LevelManager.OnStop. |
Disable(ExecutionContext context) | Disables the button. Wired to LevelManager.OnPlay. |
PixelSnaper
Snaps the transform's position to the nearest pixel boundary every frame, eliminating sub-pixel drift in pixel-art games. Runs in both Edit and Play mode ([ExecuteInEditMode]) so you can preview snapping while placing objects in the Scene view.
Inspector Fields
| Field | Type | Description |
|---|---|---|
pixelsPerUnit | float | Pixels per world unit. Must match the sprite's import setting (typically 16 or 32). |
snapToGrid | bool | When enabled, snaps to the nearest grid-cell center rather than individual pixels. |
cellSize | float | Size of one grid cell in pixels. Only used when snapToGrid is enabled. |
DepthSortingOrder
Adjusts a SpriteRenderer's sortingOrder each frame based on the object's Y position relative to a reference transform, producing correct painter's-algorithm depth for top-down or isometric perspectives.
The formula is: sortingOrder = Floor((topLimit.y × 100) − (transform.y × 100)). Objects closer to the top reference render behind objects lower on screen.
Inspector Fields
| Field | Type | Description |
|---|---|---|
topLimit | Transform | Reference transform marking the top Y boundary for depth calculations. Place this at the topmost row of the level. |