What's It Good For

Are tiles with instance data worth the trouble? This post discusses the tile class architecture, then we can talk about specific tiles.

Here's the class diagram:

ClassH.png

TilePlusBase

TilePlusBase subclasses Tile and implements the ITilePlus interface. The interface specifies a set of properties and a few methods required by other parts of the system. Tiles provided with the Asset Store version of the asset all derive from TilePlusBase. The CreateAssetMenu attribute of this class is commented out because there's no reason to ever create a tile based on this class.

Seven different tiles subclass TilePlusBase. Those on the left side of the diagram are not subclassed any further while those on the right all subclass TpFlexAnimatedTile.

TpAnimatedTile

This is a simple animated tile but adds one-shot animation and other features.

Public fields:

  • PlayOnStart: Begin animation when the game starts.
  • AnimationSpeed: Set animation speed relative to that set in the Tilemap
  • OneShot: Play the animation once, then stop.
  • ManualTimeout: A manual timeout for One-shot mode.
  • UnchangingSprites: Click this toggle ON if you don’t intend to change sprites at runtime.
  • AnimatedSprites: A list of sprites to animate.

TpFlexAnimatedTile

TpFlexAnimatedTile is an upgraded TpAnimatedTile that adds the ability to have multiple animation sequences contained in an asset file. Once placed, you can select on a per-tile basis which animation sequence is used initially, and several other settings, including whether to play automatically when the Scene is loaded, and which sequence is in use. When using many animated tiles, the use of an asset is more memory efficient than TpAnimatedTile.

The asset file for this tile is TpSpriteAnimationClipSet, and its fields are mostly the same as those for TpAnimatedTile. You can create it from the Assets/Create menu.

TpPrefab

TpPrefab tiles have a linked Prefab. When the tile is painted on a Tilemap, the Prefab is automatically added as a child GameObject to the Tilemap at the same position that the tile is placed; it’s immediately visible. Linked means that during Editor sessions, if you delete one of the pair then the other one is deleted. If you select, then move the TpPrefab tile then the linked Prefab is moved in a relative fashion, even if you’ve changed the Prefab’s position. This works in-editor or at runtime; including optional easing built-in (refer to Programmer’s Guide, Third-Party Libraries).

Why do this? You can paint prefabs right from the Palette. The tile’s sprite appears in the Palette. You can have that sprite or icon as a visual cue in the Palette.

For scripters, it means that one can locate the prefab’s GameObject by examining fields in the TPT tile. It’s as easy as reading any other tile from a Tilemap component; and you can build actions that affect the prefab right into the Tile. No more searching for named prefabs or tags, just use the position. You can also find the paired tile from the Prefab with a TpLib method.

Public fields:

  • AutoInstantiatePrefab: Automatically place the prefab above the tile when it’s painted.
  • PrefabToInstance: The prefab to use.
  • ForceLayer: Make the prefab’s layer the same as it’s parent Tilemap.
  • TileSpriteClear: Clear the sprite when painted, when the game runs, both, or not at all.
  • EasePrefab: If the tile is moved, the prefab position is Eased. If false, the prefab moves instantly.
  • EasingFunction: If Easing is used, which Easing function to use (Linear, EaseInQuad, etc.).
  • EaseSpeed: if Easing is used, how fast should the tile move.

TpSlideShow

TpSlideShow lets you display one Sprite at a time from a list of Sprites contained in an asset file. The initial Sprite to display can be changed, and you move from one Sprite to the next programmatically, with automatic wrapping or limiting. Wrapping means that incrementing from the last slide returns to the first slide (or when decrementing, from the last slide to the first slide) and limiting means that incrementing from the last slide or decrementing from the first slide has no effect. This tile is used for the background in the BasicTiles demo.

The asset file for this tile is TpSlideShowSpriteSet. You can create it from the Assets/Create menu.

Public fields:

  • SlidesClipSet: The TpSlideShowSpriteSet asset from your Project folder.
  • SlideShowAtStart: The name of the slide show to show when your game starts.
  • WrappingOverride: Override the ‘wrap’ setting from the TpSlideShowSpriteSet asset.

When inspecting one of these tiles using the Tile+Brush Selection Inspector you’ll see a dropdown where you can select which slideshow set from the TpSlideShowSpriteSet to be used at start. This can also be changed via code.

In the next post I'll talk about some of the more complex tiles.