Class MapEditing

Namespace
TDMaker.Editor
Assembly
TDMaker.Editor.dll

Undoable level-authoring operations behind the Map Editor (and usable from your own editor scripts): edit points of curve and polyline paths, create/delete/duplicate/align build slots with automatic rally points, path order, painted background setup and baking scene geometry into a LevelAsset.

public static class MapEditing
Inheritance
MapEditing
Inherited Members

Fields

SlotsRootName

Name of the child object that holds build slots created by the Map Editor.

public const string SlotsRootName = "Build Slots"

Field Value

string

Methods

Align(IList<BuildSlotAuthoring>, int)

Moves slots to the same X (axis 0) or Y (1) as the first one.

public static void Align(IList<BuildSlotAuthoring> slots, int axis)

Parameters

slots IList<BuildSlotAuthoring>
axis int

ApplyBackground(LevelView, TDCameraController, Sprite, Vector2)

Uses sprite as the level's painted map on view (pivot at pivot) and, when camera is given, clamps the game camera to the map rectangle and centres it there.

public static void ApplyBackground(LevelView view, TDCameraController camera, Sprite sprite, Vector2 pivot)

Parameters

view LevelView
camera TDCameraController
sprite Sprite
pivot Vector2

AutoRally(BuildSlotAuthoring, IReadOnlyList<PathData>, bool)

Moves a slot's rally point to the nearest point on the nearest ground path. Returns false when there is no path.

public static bool AutoRally(BuildSlotAuthoring slot, IReadOnlyList<PathData> paths, bool recordUndo = true)

Parameters

slot BuildSlotAuthoring
paths IReadOnlyList<PathData>
recordUndo bool

Returns

bool

BackgroundHints(Sprite)

Non-blocking advice for a map sprite: aspect other than 16:9, very large textures and uncompressed import (with a memory estimate). Empty when nothing stands out.

public static string BackgroundHints(Sprite sprite)

Parameters

sprite Sprite

Returns

string

BakeToAsset(LevelAuthoring, bool)

Writes the scene paths and build slots into the level's LevelAsset (undoable) and saves it.

public static bool BakeToAsset(LevelAuthoring level, bool save = true)

Parameters

level LevelAuthoring
save bool

Returns

bool

CameraBounds(TDCameraController)

The game camera's fixed bounds, or null when it fits the level geometry.

public static Rect? CameraBounds(TDCameraController camera)

Parameters

camera TDCameraController

Returns

Rect?

Changed(PathAuthoring)

Regenerates the curve (curve mode) and marks the path dirty. Call after editing edit points directly.

public static void Changed(PathAuthoring path)

Parameters

path PathAuthoring

CreateLevel(LevelAsset)

Creates a level root (Level Authoring) in the active scene.

public static LevelAuthoring CreateLevel(LevelAsset asset = null)

Parameters

asset LevelAsset

Returns

LevelAuthoring

CreatePath(LevelAuthoring, Vector2, bool, int, float, float, string)

Creates a path under the level with its first edit point at worldPoint.

public static PathAuthoring CreatePath(LevelAuthoring level, Vector2 worldPoint, bool curve = true, int laneCount = 2, float laneSpacing = 0.4, float nodeSpacing = 0.6, string name = null)

Parameters

level LevelAuthoring
worldPoint Vector2
curve bool
laneCount int
laneSpacing float
nodeSpacing float
name string

Returns

PathAuthoring

CreateSlot(LevelAuthoring, Vector2, TowerAsset)

Places a build slot at world; its rally point goes to the nearest point on the nearest ground path (when the level has one). Optional previewTower is drawn around the slot in the Scene view.

public static BuildSlotAuthoring CreateSlot(LevelAuthoring level, Vector2 world, TowerAsset previewTower = null)

Parameters

level LevelAuthoring
world Vector2
previewTower TowerAsset

Returns

BuildSlotAuthoring

DeletePath(LevelAuthoring, PathAuthoring)

Deletes a path object and removes it from the level's list.

public static void DeletePath(LevelAuthoring level, PathAuthoring path)

Parameters

level LevelAuthoring
path PathAuthoring

DeletePoint(PathAuthoring, int)

Deletes an edit point; paths keep at least two.

public static bool DeletePoint(PathAuthoring path, int index)

Parameters

path PathAuthoring
index int

Returns

bool

DeleteSlots(LevelAuthoring, IList<BuildSlotAuthoring>)

Deletes build slots and removes them from the level's list.

public static void DeleteSlots(LevelAuthoring level, IList<BuildSlotAuthoring> slots)

Parameters

level LevelAuthoring
slots IList<BuildSlotAuthoring>

Distribute(IList<BuildSlotAuthoring>, int)

Spaces slots evenly between the outermost two along X (axis 0) or Y (1).

public static void Distribute(IList<BuildSlotAuthoring> slots, int axis)

Parameters

slots IList<BuildSlotAuthoring>
axis int

DuplicateSlots(LevelAuthoring, IList<BuildSlotAuthoring>, Vector2)

Duplicates build slots shifted by offset; the copies get fresh automatic rally points.

public static List<BuildSlotAuthoring> DuplicateSlots(LevelAuthoring level, IList<BuildSlotAuthoring> slots, Vector2 offset)

Parameters

level LevelAuthoring
slots IList<BuildSlotAuthoring>
offset Vector2

Returns

List<BuildSlotAuthoring>

EditPoints(PathAuthoring)

The points the user edits: curve control points in curve mode, else the polyline points (local space).

public static List<Vector2> EditPoints(PathAuthoring path)

Parameters

path PathAuthoring

Returns

List<Vector2>

EditWidths(PathAuthoring)

Per-edit-point lane spacing overrides (index-aligned with EditPoints(PathAuthoring); may be shorter).

public static List<float> EditWidths(PathAuthoring path)

Parameters

path PathAuthoring

Returns

List<float>

EntryOf(PathAuthoring, out Vector2, out Vector2)

World position of the entry node and the road direction there, for a scene path.

public static bool EntryOf(PathAuthoring path, out Vector2 entry, out Vector2 direction)

Parameters

path PathAuthoring
entry Vector2
direction Vector2

Returns

bool

FitCamera(TDCameraController, Rect)

Clamps the game camera to area (fixed bounds) and centres its edit-mode view there.

public static void FitCamera(TDCameraController camera, Rect area)

Parameters

camera TDCameraController
area Rect

InsertPoint(PathAuthoring, int, Vector2, string)

Inserts an edit point (local space) and regenerates the curve.

public static void InsertPoint(PathAuthoring path, int index, Vector2 local, string undoName = "Add Path Point")

Parameters

path PathAuthoring
index int
local Vector2
undoName string

MinPoints(PathAuthoring)

Smallest number of edit points a path keeps when deleting.

public static int MinPoints(PathAuthoring path)

Parameters

path PathAuthoring

Returns

int

MovePath(LevelAuthoring, PathAuthoring, int)

Moves a path by delta places in the level order (waves refer to paths by index).

public static void MovePath(LevelAuthoring level, PathAuthoring path, int delta)

Parameters

level LevelAuthoring
path PathAuthoring
delta int

MovePoint(PathAuthoring, int, Vector2)

Moves an edit point to a local position.

public static void MovePoint(PathAuthoring path, int index, Vector2 local)

Parameters

path PathAuthoring
index int
local Vector2

PathColor(int)

A distinct gizmo color per path index.

public static Color PathColor(int index)

Parameters

index int

Returns

Color

Paths(LevelAuthoring)

Paths of a level in index order (the explicit list, else children in hierarchy order).

public static List<PathAuthoring> Paths(LevelAuthoring level)

Parameters

level LevelAuthoring

Returns

List<PathAuthoring>

PointWidth(PathAuthoring, int)

Effective lane spacing at an edit point.

public static float PointWidth(PathAuthoring path, int index)

Parameters

path PathAuthoring
index int

Returns

float

RemapGeometry(LevelAuthoring, Rect, Rect)

Keeps the level aligned with a replaced or rescaled map: maps every path point (curve controls and nodes), build slot and rally point from from to to (per axis), and scales lane widths, curve node spacing and wave-call offsets by the mean scale. Undoable. Returns the number of objects changed.

public static int RemapGeometry(LevelAuthoring level, Rect from, Rect to)

Parameters

level LevelAuthoring
from Rect
to Rect

Returns

int

Rename(Object, string)

Renames a scene object with undo.

public static void Rename(Object target, string newName)

Parameters

target Object
newName string

ResetWaveCall(PathAuthoring)

Returns the wave-call button to its default spot just ahead of the entry.

public static void ResetWaveCall(PathAuthoring path)

Parameters

path PathAuthoring

Reverse(PathAuthoring)

Reverses travel direction (edit points, widths and wave-call override).

public static void Reverse(PathAuthoring path)

Parameters

path PathAuthoring

ScenePaths(LevelAuthoring)

World-space path data of the level's scene paths.

public static List<PathData> ScenePaths(LevelAuthoring level)

Parameters

level LevelAuthoring

Returns

List<PathData>

SetCurve(PathAuthoring, bool)

Switches curve mode. Turning it on with fewer than two control points seeds them from the current polyline (entry to exit), so the road keeps its shape; turning it off keeps the generated nodes as a plain polyline.

public static void SetCurve(PathAuthoring path, bool on)

Parameters

path PathAuthoring
True bool

SetNodeSpacing(PathAuthoring, float)

Sets the curve node spacing and regenerates.

public static void SetNodeSpacing(PathAuthoring path, float spacing)

Parameters

path PathAuthoring
spacing float

SetPixelsPerUnit(Sprite, float)

Changes the pixels-per-unit of a sprite's texture importer (re-imports the texture).

public static Sprite SetPixelsPerUnit(Sprite sprite, float ppu)

Parameters

sprite Sprite
ppu float

Returns

Sprite

SetPointWidth(PathAuthoring, int, float)

Sets the lane spacing override of an edit point (zero or less clears it).

public static void SetPointWidth(PathAuthoring path, int index, float spacing)

Parameters

path PathAuthoring
index int
spacing float

SetWaveCall(PathAuthoring, Vector2)

Places the wave-call button at a world position (turns the override on).

public static void SetWaveCall(PathAuthoring path, Vector2 world)

Parameters

path PathAuthoring
world Vector2

Slots(LevelAuthoring)

Build slots of a level in index order (the explicit list, else children in hierarchy order).

public static List<BuildSlotAuthoring> Slots(LevelAuthoring level)

Parameters

level LevelAuthoring

Returns

List<BuildSlotAuthoring>

SlotsRoot(LevelAuthoring)

The child that holds build slots (created when missing).

public static Transform SlotsRoot(LevelAuthoring level)

Parameters

level LevelAuthoring

Returns

Transform

Snap(Vector2, float)

Rounds a world point to a grid of step.

public static Vector2 Snap(Vector2 p, float step)

Parameters

p Vector2
step float

Returns

Vector2

SpriteFrom(Object)

The sprite of a texture asset, converting its import settings to Sprite (single) when needed.

public static Sprite SpriteFrom(Object source)

Parameters

source Object

Returns

Sprite

WaveCallPosition(PathAuthoring)

World position of the path's wave-call button (same rule as the HUD).

public static Vector2 WaveCallPosition(PathAuthoring path)

Parameters

path PathAuthoring

Returns

Vector2