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
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
slotsIList<BuildSlotAuthoring>axisint
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
viewLevelViewcameraTDCameraControllerspriteSpritepivotVector2
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
slotBuildSlotAuthoringpathsIReadOnlyList<PathData>recordUndobool
Returns
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
spriteSprite
Returns
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
levelLevelAuthoringsavebool
Returns
CameraBounds(TDCameraController)
The game camera's fixed bounds, or null when it fits the level geometry.
public static Rect? CameraBounds(TDCameraController camera)
Parameters
cameraTDCameraController
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
pathPathAuthoring
CreateLevel(LevelAsset)
Creates a level root (Level Authoring) in the active scene.
public static LevelAuthoring CreateLevel(LevelAsset asset = null)
Parameters
assetLevelAsset
Returns
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
levelLevelAuthoringworldPointVector2curveboollaneCountintlaneSpacingfloatnodeSpacingfloatnamestring
Returns
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
levelLevelAuthoringworldVector2previewTowerTowerAsset
Returns
DeletePath(LevelAuthoring, PathAuthoring)
Deletes a path object and removes it from the level's list.
public static void DeletePath(LevelAuthoring level, PathAuthoring path)
Parameters
levelLevelAuthoringpathPathAuthoring
DeletePoint(PathAuthoring, int)
Deletes an edit point; paths keep at least two.
public static bool DeletePoint(PathAuthoring path, int index)
Parameters
pathPathAuthoringindexint
Returns
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
levelLevelAuthoringslotsIList<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
slotsIList<BuildSlotAuthoring>axisint
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
levelLevelAuthoringslotsIList<BuildSlotAuthoring>offsetVector2
Returns
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
pathPathAuthoring
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
pathPathAuthoring
Returns
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
pathPathAuthoringentryVector2directionVector2
Returns
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
cameraTDCameraControllerareaRect
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
pathPathAuthoringindexintlocalVector2undoNamestring
MinPoints(PathAuthoring)
Smallest number of edit points a path keeps when deleting.
public static int MinPoints(PathAuthoring path)
Parameters
pathPathAuthoring
Returns
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
levelLevelAuthoringpathPathAuthoringdeltaint
MovePoint(PathAuthoring, int, Vector2)
Moves an edit point to a local position.
public static void MovePoint(PathAuthoring path, int index, Vector2 local)
Parameters
pathPathAuthoringindexintlocalVector2
PathColor(int)
A distinct gizmo color per path index.
public static Color PathColor(int index)
Parameters
indexint
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
levelLevelAuthoring
Returns
PointWidth(PathAuthoring, int)
Effective lane spacing at an edit point.
public static float PointWidth(PathAuthoring path, int index)
Parameters
pathPathAuthoringindexint
Returns
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
levelLevelAuthoringfromRecttoRect
Returns
Rename(Object, string)
Renames a scene object with undo.
public static void Rename(Object target, string newName)
Parameters
targetObjectnewNamestring
ResetWaveCall(PathAuthoring)
Returns the wave-call button to its default spot just ahead of the entry.
public static void ResetWaveCall(PathAuthoring path)
Parameters
pathPathAuthoring
Reverse(PathAuthoring)
Reverses travel direction (edit points, widths and wave-call override).
public static void Reverse(PathAuthoring path)
Parameters
pathPathAuthoring
ScenePaths(LevelAuthoring)
World-space path data of the level's scene paths.
public static List<PathData> ScenePaths(LevelAuthoring level)
Parameters
levelLevelAuthoring
Returns
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
pathPathAuthoringTruebool
SetNodeSpacing(PathAuthoring, float)
Sets the curve node spacing and regenerates.
public static void SetNodeSpacing(PathAuthoring path, float spacing)
Parameters
pathPathAuthoringspacingfloat
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
spriteSpriteppufloat
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
pathPathAuthoringindexintspacingfloat
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
pathPathAuthoringworldVector2
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
levelLevelAuthoring
Returns
SlotsRoot(LevelAuthoring)
The child that holds build slots (created when missing).
public static Transform SlotsRoot(LevelAuthoring level)
Parameters
levelLevelAuthoring
Returns
- Transform
Snap(Vector2, float)
Rounds a world point to a grid of step.
public static Vector2 Snap(Vector2 p, float step)
Parameters
pVector2stepfloat
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
sourceObject
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
pathPathAuthoring
Returns
- Vector2