Skip to main content

Map Layers

A map layer is a group of GameObjects associated with a map. A map layer is controlled by the MapLayer class. You can associate a map layer with a feature builder through the Unity UI. See How to Place Objects Using a MapLayer. In order to use a MapLayer, there must be a MapLayer prefab somewhere in the scene.

Map layers are similar to Feature Builders because both allow you to customize the map's visual style by placing objects or rendering geometry. Map layers differ from feature builders in two key ways:

  1. A MapLayer applies to the entire map view, rather than to individual maptiles.
  2. Because MapLayers do not have data from individual tiles, you will usually use them for data from other sources, or from actions the user takes.

A map layer can support one or more MapLayer components that spawn and position objects. You can use multiple layers together as long as the parent GameObject has a MapLayer component. To view all the map layers in use by the Lightship Map Prefab, look for the Map Layers list in the prefab's Inspector.

Map layers can support a single stationary GameObject or multiple moving GameObjects, along with line or polygon rendering:

You can extend any of these components to customize their spawning or placement behavior.

Empty MapLayer

An empty map layer prefab holds just the MapLayer component. This can be used when you need more flexibility or multiple layers. You can find an example of this in the Map-Based Resource Game sample. The BuildingLayer is an empty layer that contains other layers for spawning stone, sawmills and strongholds.

Empty MapLayer

LayerGameObjectPlacement / LayerGameObjectInstance

You can use LayerGameObjectPlacement to instantiate multiple objects. You can group objects into multiple MapLayers, which are all then children of the LightshipMap. All of these objects can be moved around the map.

Layer Game Object Placement

You can use the LayerGameObjectInstance to place a single GameObject on the map. Once this object is placed, it can only be moved by code external to the MapLayer. It will preserve the object's position, rotation, and scale relative to the LightshipMapView where you place it. It does not require event handlers to reposition the object when the map's view position changes. It can also scale with the view radius, so it stays the same size as the user zooms in and out.

Layer Game Object Placement

Both components include these settings:

  • Name - The name of the GameObject prefab to instantiate.
  • Scale with Map Radius - If checked, the game object will scale relative to the map.
  • Relative Scale - The numerical value for the scale ratio.
  • Minimum Scale - The smallest possible relative scale.
  • Maximum Scale - The largest possible relative scale.

These settings are only for LayerGameObjectPlacement:

  • Prefab - The prefab GameObject to instantiate.
  • Height Offset - The y-axis offset.

LayerLineRenderer / LayerPolygonRenderer

The LayerLineRenderer renders a lined border around a specified area on the map. The line rendering layer can only render loops.

The LayerPolygonRenderer renders a polygon.

In this image, from the Custom Map Layer Sample, Washington and Oregon are covered with a polygon and the Oregon polygon has a line around it:

Oregon and Washington

Both components include these settings:

  • Name - The name of the GameObject prefab to instantiate.
  • Fill Material - The fill material to use.
  • Height Offset - The y-axis offset.

LayerLineRenderer includes:

  • Line Width - The width of the rendered line.