-
Notifications
You must be signed in to change notification settings - Fork 4
Editor Tools
A tool is a class that inherits from the EditorTool class. A tool is anything you can take out of the tool box and use in the editor.
A tool also requires an id, this id is saved into the file so the tool can easily be referenced. It also by default is used to create the title and description localization keys.
In general, when working with a tool, you will have to refer to EditorController.Instance to get most things done, such as adding IEditorVisuals or adding content to EditorController.Instance.levelData
Unless you are adding a structure or some kind of special utility tool, you almost never need to actually create your own tool class.
Below is the list of tools for various different types in the editor. Constructing these is usually as easy as passing in a string for the element ID and then a sprite for the icon in editor.
- ActivityTool
- DoorTool
- ElevatorTool
- NPCTool
- ObjectTool
- ObjectToolNoRotation
- PosterTool
- RoomTool
- OnlyOneRoomTool
- WindowTool
- TileBasedObjectTool
BulkObjectTool and BulkObjectRandomizedTool can be used for placing basic objects in bulk, akin to a prefab. (Though each placed object is still seperate)
Below are examples for creating each, copied from the editor source code. (Modified slightly as the editor uses internal/private constructors that don't need the sprite to be passed in.)
This tool places 5 lockers side by side, relative to the direction the user selects.
new BulkObjectTool("multilockers", multiLockerSprite, new BulkObjectData[] { new BulkObjectData("locker", new Vector3(-4f,0f,4f)), new BulkObjectData("locker", new Vector3(-2f,0f,4f)), new BulkObjectData("locker", new Vector3(0f,0f,4f)), new BulkObjectData("locker", new Vector3(2f,0f,4f)), new BulkObjectData("locker", new Vector3(4f,0f,4f)) });
This tool places 5 lockers side by side, with one of them being randomly being a blue locker. Relative to the direction the user selects.
new BulkObjectRandomizedTool("lockerrandomblue", randomBlueLockerSprite, new BulkObjectData[] { new BulkObjectData("locker", new Vector3(-4f,0f,4f)), new BulkObjectData("locker", new Vector3(-2f,0f,4f)), new BulkObjectData("locker", new Vector3(0f,0f,4f)), new BulkObjectData("locker", new Vector3(2f,0f,4f)), new BulkObjectData("locker", new Vector3(4f,0f,4f)) }, new List<KeyValuePair<string, string>>() { new KeyValuePair<string, string>("locker", "bluelocker") });
There are two built in abstract classes or "tool bases" that inherit from EditorTool that you can use to avoid re-implementing basic logic, assuming you don't need anything extra.
The functionality of this tool base is simple. Click on a cell, then it will "place" something. This base is used by lights and basic objects without rotation.
All you need to do to is implement TryPlace. Note that this can do anything you want.
There is also ValidLocation, which is checked before TryPlace is called.
The functionality of this tool base is simple. Click on a cell, then select a rotation, which will then place something. This base is used by windows, doors, and more.
When you inherit from this tool, all you need to do is implement TryPlace. Note that this can do anything you want.
There is also ValidLocation, which is used to determine if a tool should enter the rotation selection phase when a cell is clicked.