Selectors
Selectors are used by the layout system to determine what and how to load. Each Selector has a reference to one or more TileFabs (but usually just one) and a LoadFlags field.
There are two types provided with this distribution: SingleFabChunkSelector
and ChunkZoneSelector
.
SingleFabChunkSelector
is very simple and just causes the same TileFab to be painted to each Zone. This Selector does not accommodate variable Chunk Size: Chunk Size is the size of the TileFab referenced by the SingleFabChunkSelector.
ChunkZoneSelector
is almost the same, however, its initialization method causes all the child Bundles of the referenced TileFab to subdivide themselves into the specified chunk size.
When Bundles “Chunkify” themselves, they ready their tiles for Tilemap loading using SetTiles(TileChangeDataArray). The tiles are organized into several small arrays; one for each Chunk. For example, if a Bundle has a size of 512 x 512 and the Chunk Size is for the TScene is 128 then the Bundle is subdivided into 16 chunks arranged in a 4 x 4 matrix. Since this is performed at runtime, you can use any applicable chunk size.
This is a big advantage since you can easily tweak the chunk size during development or even in a deployed app for performance optimization on different platforms.
Useful Selector Methods
public List<RectInt>? AllLocators
Get all of the locators for this Selector.
This subdivides the entire bounds of the TileFab into N RectInts of a size equal to the Selector's Chunk Size.
BoundsInt SelectorTotalSize(TpZoneLayout layout)
The returned BoundsInt defines the size of a single complete image ie the entirety of the template's TileFabs. By default this is placed in Quadrant 1 of a 2D plane whose origin is at m_Layout.m_WorldOrigin
and the size is always a square.
List<TemplateSelectorQueryResults<T>> GetTilePlusTilesOfType<T>(Func<T, string, bool>? filter = null,
int size = 16,
object? options = null)
where SelectorQueryResults
is:
/// <summary>
/// name of TileMap
/// </summary>
public readonly string m_MapName;
/// <summary>
/// the tile instance of type T
/// </summary>
public readonly T m_Tile;
/// <summary>
/// the position
/// </summary>
public readonly Vector3Int m_Position;
What's this for?
When you load a new TileScene you will need information from it. For example, if you are using waypoints you might want to find out all the waypoints so you can position your player at a specific location: the most recently enabled waypoint.
Using GetTilePlusTilesOfType<T>
is an easy way to extract this information. You can see how it's used in the next section.
This is a generic Query method which examines the Selector's TileFab, returning a list of