/// <summary> Registers the given <paramref name="tilemap"/> keyed by the given <typeparamref name="T"/>. </summary> /// <typeparam name="T"> The <see cref="Type"/> of the <see cref="BaseTilemap{T}"/>. </typeparam> public void RegisterTilemap <T>(BaseTilemap <T> tilemap) where T : struct, ITileData { // If the given tilemap is null, do nothing. if (tilemap == null) { return; } // Add the tilemap keyed by the given type. mapsByType.Add(typeof(T), tilemap); }
/// <summary> Finds the <see cref="BaseTilemap{T}"/> with the given <typeparamref name="T"/> from the <see cref="GameObject"/>'s children of this behaviour, and registers it. </summary> /// <typeparam name="T"> The <see cref="Type"/> of the <see cref="BaseTilemap{T}"/>. </typeparam> /// <returns> The <see cref="BaseTilemap{T}"/> with the matching <see cref="Type"/>, or null if none was found. </returns> private BaseTilemap <T> findAndRegisterTilemap <T>() where T : struct, ITileData { // Get the tilemap within the children of this GameObject. BaseTilemap <T> tilemap = GetComponentInChildren <BaseTilemap <T> >(); // If a tilemap was found, register it. if (tilemap != null) { RegisterTilemap(tilemap); } // Return the tilemap, which could be null if none was found. return(tilemap); }
/// <summary> Queries the given <paramref name="tile"/> against the given <paramref name="tilemap"/> using the given position, and checks that the tile can be placed. </summary> /// <param name="tilemap"> The <see cref="BaseTilemap{T}"/> against which the <paramref name="tile"/> is being queried. </param> /// <param name="x"> The x co-ordinate of the position. </param> /// <param name="y"> The y co-ordinate of the position. </param> /// <returns> True if the tile can be placed; otherwise, false. </returns> public virtual bool CanPlace(BaseTilemap <T> tilemap, int x, int y) => true;
/// <summary> Is fired every tick of the given <paramref name="tilemap"/>. </summary> /// <param name="tilemap"> The <see cref="BaseTilemap{T}"/> on which this tile resides. </param> /// <param name="x"> The x co-ordinate of the position. </param> /// <param name="y"> The y co-ordinate of the position. </param> public virtual void OnTick(BaseTilemap <T> tilemap, int x, int y) { }
/// <summary> Is fired immediately after a tile is destroyed. </summary> /// <param name="tilemap"> The <see cref="BaseTilemap{T}"/> on which this tile resided. </param> /// <param name="x"> The x co-ordinate of the position. </param> /// <param name="y"> The y co-ordinate of the position. </param> public virtual void OnTileDestroyed(BaseTilemap <T> tilemap, int x, int y) { }
/// <summary> Is fired immediately after a tile is placed. </summary> /// <param name="tilemap"> The <see cref="BaseTilemap{T}"/> on which this tile now resides. </param> /// <param name="x"> The x co-ordinate of the position. </param> /// <param name="y"> The y co-ordinate of the position. </param> public virtual void OnTilePlaced(BaseTilemap <T> tilemap, int x, int y) { }