arrow-left

All pages
gitbookPowered by GitBook
1 of 7

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Technical Implementation

This page describes some of the inner workings of the tilesystem

hashtag
Setting up a new TileSystem

In order to create a new tilesystem, you need to create a new GameObject in a scene and add the following scripts:

  • TileSystem

  • TileResourceLoader

Furthermore in order to use the creator, you will need to add the ConstructionMenu prefab to the scene.

hashtag
Startup

When playing in runtime, the TileSystem will automatically try to load a saved tilemap from the StreamingAssets folder and recreate it using ScriptableObjects found by the TileResourceLoader.

hashtag
Internal structure

When placed, the tilemap uses the following structure to keep track of all tiles. Ranked in order from the lowest element to the highest:

  1. PlacedItemObject - This script is attached to every itemthat is spawned on the map. Ensures spawning/despawning and is always attached to a GameObject.

  2. PlacedTileObject - This script is attached to every object that is spawned on the map. Ensures spawning/despawning and holds references to any adjacency connectors. Always attached to a GameObject.

  3. TileObject - This class represents a single object on a single layer and can contain one PlacedTileObject. So for each tile position in the world, there is are (number of layers) amount of TileObjects. Not attached to a GameObject.

hashtag
Other parts of the system

  • TileResourceLoader - Reads and holds the ScriptableObjects for each item and tile that can be placed. Used by the TileSystem to figure out what object is placed.

  • Saved-X-Object - Used to hold the state of the corresponding class/struct and is serializable. Used for saving and loading.

  • BuildChecker - Used to validate combinations of placed objects and can check whether an object can be placed. For example, no objects can be build on the Turf layer if a Plenum is missing.

  • TileChunk - A chunk represents a 16 by 16 grid of TileObjects for each layer (16 x 16 x num of layers). Chunks are not really used at the moment, but have to potential to benefit networking and loading for massive maps in the future. Created as a GameObject as a parent to PlacedTileObjects.

  • TileMap - Holds a dictionary of chunks filled with TileObjects and a list of PlacedItemObjects. The later are not position bound so are not part of a chunk. Created as a GameObject as a parent to chunks and items.

  • TileSystem - The system to hold TileMaps, and serves as the main interaction point to place and remove items/tiles. Only a single instance of the TileSystem can exist.

  • SaveSystem - Generic save system that is used for saving and loading of the tilemap from and to a file. Uses the StreamingAssets folder so that builds also receive it.

  • TileMapCreator - Used as an in-game editor for placing and removing tiles/items and saving/loading. Is networked so that clients are also able to work on the map.

  • GhostManager - Used for construction as part of the TileMapCreator to create a "ghost" object to see where you are building.

  • MultiAdjacencyConnector - Used for connecting walls and tables together. Keeps track of which neighbours it is connected to and will replace and rotate meshes accordingly.

  • Creating Maps

    Using the tilemap creator.

    hashtag
    Getting Started

    To get started with the creator, run the game and press B after spawning. This will bring the creator menu up.

    hashtag
    Controls

    • Press left mouse button to place an object

    • Press R to rotate an object

    • Hold left shift to replace an existing object on the same layer

    hashtag
    Building indicators

    hashtag
    Building layers

    Each tile can hold multiple objects on different layers. The following layers are implemented:

    • Plenums - These form the foundations of the station. Always required to be present before another layer can be build

    • Turfs - Walls and floors go on this layer

    • Wires - High, medium and low voltage wires

    Click drag to place/delete/replace in a line form

  • Alt+Click drag to place/delete/replace in a square form

  • Disposal - Disposal pipes fit in this layer
  • Pipes - Atmospheric pipes go here

  • WallMountHigh - Wall mounts that are placed high on the wall

  • WallMountLow - Wall mounts that are placed low on the wall

  • FurnitureBase - Regular objects such as chairs, tables and counters go here

  • FurnitureTop - Objects that go on top of FurnitureBase. For example desk lamps

  • Overlays - Indicators that fit on top of floors go here

  • Valid build location
    Invalid build location
    Object will be deleted

    Adding new items & objects

    hashtag
    Creating ScriptableObjects

    To add a new item or object to the tilemap system, a new scriptableobject needs to be created.

    Right click in the Unity Editor to create a new object

    hashtag
    Location

    Make sure to save the item/tile ScriptableObjects under the corresponding "Content/Data/TileMap/Resources/" folder

    hashtag
    Details

    The following information can be filled in for a TileObjectSo:

    hashtag
    Tile objects

    • Name String - describes the name of the object

    • Prefab - which prefab to spawn

    • Icon - Icon which is used by the creator and construction interface

    hashtag
    Items

    Items can be added in a similar way:

    circle-exclamation

    Make sure the Name String is unique. Not doing so will create issues during loading & saving.

    Layer - which layer the item should be put in
  • Generic Type - Generics types are used to categorize objects on the same layer. Used by the adjacency connector to connect walls for example

  • Specific Type - Specific types are used to specify the material that the object is made of. For example used by carpets to ensure that they don't connect to other floors

  • Width - width of the object. Used for multi-tile objects

  • Height - height of the object. Used for multi-tile objects

  • Details to fill in
    Items follow the same approach

    Adjacency Connections

    The design of the system can be found in the the link below.

    Adjacency connections refers to when a tilemap object is connectable to its neighbors, walls being the typical example of this.

    hashtag
    Adjacency Connectors

    In order to make walls and tables connect to each other, you need to make use of a adjacency connector. This keeps track of which neighbours it is connected to and will replace and rotate meshes accordingly.

    hashtag
    The different adjacency connectors

    There are different types of adjacencies supported right now.

    1. Simple - Used for simple connections without a lot of use cases. Covers the basic shapes such as I, U, O, T and X.

    2. Advanced - Expansion of the Simple type with a lot more edge cases covered.

    3. Offset - Used for meshes which are not placed in the middle (thus offset). Used by pipes for example.

    hashtag
    Implementing an adjacency connector

    The first thing you need is to implement the IAdjacencyConnector interface.

    If your tile object connects only with things from the same layer, adjacent to it, you might want to look at the AbstractHorizontalConnector class and inherit from it.

    It will only ask you to implement the IsConnected() method, as it varies a lot from one connector to another. Door, simple, advanced, offset, pipe all inherits from it. Chances your connector could too.

    If the connections are weirder, such as disposal pipes able to connect to disposal furniture, a different object on a different layer, with a different connector, and with special behavior when it connects, then directly implement the IAdjacencyConnector interface.

    hashtag
    Make a tile object connectable

    Add the right adjacency connector script to your prefab's root game object. You can recognise a Connector script because it implements the IAdjacencyConnector interface. To know which specific script to use, check the connectables design pages.

    Connectable scripts usually ask you to add specific mesh for specific configurations. You need to fill them all up for the connector to work properly.

    Check the Connectables design page for more informations about your specific connector and how the meshes should look.

    Also know that the connectables scripts assume the mesh you link are rotated in a specific fashion, otherwise they may appear incorrectly in game. If you have this issue of meshes badly rotated, try to rotate the models you use, out of the game.

    Refactor notes

    Alain suggested spatial hashing to network big quantities of objects.

    Disposal Furniture - checks if connected from above to a disposal pipe. Very specific one.

  • Disposal Pipe - Used for disposal pipes only.

  • Door - Specific to doors, because of the specific way it connects to other doors and to walls.

  • Pipe - For pipes with an offset (not centered on the tile)

  • A wall adjacency connector

    Interface

    Well, bare in mind that this is the design idea, which we haven't executed yet:

    hashtag
    Exit Button

    Simply the button to exit the map editor.

    hashtag
    Tools Menu

    This menu contains all the tools to edit the tilemap, and has the following tools:

    1. Select

      1. Move around with the mouse.

    2. Edit

    hashtag
    View Menu

    This menu contains all options relating to menu, HUD and view modes.

    1. Reset position to 0

      1. Resets the camera position, zoom, and rotation to the initial values.

    2. Layer view mode

    hashtag
    Map Editing Modes

    The map editing modes are menus to select the list of objects that can be selected to place:

    1. Upper

    2. Lower

    3. Items

    hashtag
    Map Editing Subcategories

    hashtag
    For the Upper mode:

    1. Flooring

    2. Turfs

    3. Doors

    hashtag
    For the Layer mode:

    1. Piping

    2. Disposals

    3. Base tiles

    hashtag
    Items

    1. Items. Bananas, sodas, janicarts.

    hashtag
    Scripting & Placements

    1. Spawn placements

    2. Random item spawners

      1. Triggers.

    hashtag
    Object List

    This menu contains the selected list of objects based on the map editing modes and subcategories.

    hashtag
    Search Bar

    Panel containing a search bar to search usign tags, names or keywords

    Uses the selected object in the object menu with a place hint of the position.

  • Move (with mouse)

    1. Move an object precisely (only for non-tile-locked objects)

  • Undo

    1. Undo

  • Redo

    1. Redo

  • Quicksave

    1. Saves your map on a list of quicksaves.

  • Open map selection

    1. Opens a better saving/loading menu

  • Hide determined layers.

  • Hide UI

    1. Screenshot friendly feature.

  • Camera options

    1. FOV options, camera speed, rotation speed.

  • Map editor settings

    1. Keymap settings, debug options.

  • Scripting & Placements
    1. Spawn placements, random item spawners, triggers.

    TileObjects
  • Wall Attachments

  • spacechevron-right

    Tilemaps

    Functions and features of the tilemap system.

    For mapping design see the Maps Design document linked below.

    spacechevron-right

    The tilemap system forms the basis of the space station and is responsible for the creation and management of all items and 2-dimensional tiles that compose the station. Every static object such as floors, walls and bolted objects (i.e., fixtures) are part of the tilemap. Other systems such as construction or atmospherics have a close integration with the tilemap.

    hashtag
    Features

    Grid-based design with chunks The new design leverages collections more, which allows us to go faster through objects that are on the same layer. Next to that, the map is divided into chunks of 16 x 16 tiles. This should allow more flexibility in the future in cases where we only need to look at objects nearby, without the need to go through the entire map.

    Saving and loading The tilemap is now fully serialized and can be saved and loaded at will. This allows a few options like the ability to save chaotic stations at the end of a round for other game modes, but will also make resolving merge conflicts in the map easier.

    Multi-tile objects Objects that are bigger than a single tile can now be successfully added to the map. You can now place a cryo tube again without having to worry about it colliding with other nearby objects.

    Items Items are now part of the tilemap and can be placed and removed. This means that they are also part of the save system.