Skip to main content

Types Sample

A spawner whose enemy type and wave pattern are picked in the Inspector, without touching code.

A wave of regular and elite enemies moves toward the center.A wave of regular and elite enemies moves toward the center.

A wave of regular and elite enemies moves toward the center.

Open it​

  1. Import the sample: Tools → Aspid 🐍 → FastTools → Welcome → Samples → Import on Types.
  2. Open Scenes/Types.unity and enter Play Mode: every six seconds eight enemies appear in a circle, every fourth one an ArmoredGrunt, and walk to the center.

Try​

Exit Play Mode and select Enemy Spawner.

Enemy types and spawn pattern in the Inspector.Enemy types and spawn pattern in the Inspector.

Enemy types and spawn pattern in the Inspector.

  1. A type that survives a rename. Enemy Type is a SerializableMonoScript<Enemy>. Rename Grunt to Footman in the code, the file and its .meta, so that ArmoredGrunt follows: after the recompile the field shows Footman.
  2. A dependent picker. Elite Type offers only the class in Enemy Type and its subclasses. Switch Enemy Type to Archer and open Elite Type: only Archer is left.
  3. Names, groups and icons. Open Pattern: Circle and Line sit in the Spawn Patterns group with icons from [TypeSelectorDisplay], and the Hidden OriginPattern is left out. Pick Line and enter Play Mode: the enemies start in a line.
  4. Swap a component in place. Select Placed Enemy (swap its type) and set Health to 250. In the ComponentTypeSelector dropdown at the top of its Inspector, switch Archer to Grunt: Health stays 250, and Keep Distance, which only Archer has, is gone.

Where to look​

FileShows
Scripts/EnemySpawner.csSerializableMonoScript<T>, SerializableType<T> and [TypeSelector] that follows another field
Scripts/Enemies/Enemy.csThe ComponentTypeSelector field
Scripts/Spawning/[TypeSelectorDisplay] names, groups and icons, and [Preserve]: a pattern is stored only by its name, so without it managed code stripping removes the class from a player

Reference: Serializable Types, TypeSelector and ComponentTypeSelector.