Listeners
To extend Core GameKit to the limit of your imagination, we have Listener scripts so that you can add custom behavior through code that will hook into a great many Core GameKit events. Each Listener script is an empty skeleton code template that you should not modify. Instead you should create subclasses from them to use for your purposes.
For each method in these events, you are passed context objects so you can tell exactly what is happening. If you need more events to listen to, let us know!
Hooking Up Listeners
Hooking up Listener scripts is easy. Let's take a look at Killable Listener. To set it up:
- Select a Killable object in your Scene.
- In the Inspector, add a Killable Listener script from the Component menu (let's just use the stock one for now).
That's it! The Listener will look for a compatible object to listen to in the same Game Object automatically. i.e. adding a Killable Listener to a Game Object with Killable will automatically hook them together.
Note: If you want the listener to live in a different Game Object, the steps are a little different.
- In the Inspector, add a Killable Listener script from the Component menu (let's just use the stock one for now) to the Game Object you want to listen.
- Select the Killable you want to listen to in the Hierarchy.
- Under the Inspector for the Killable script, notice the "Listener" field which is currently unassigned. Drag the Game Object with the Killable Listener script into there.
That's it! Your Listener is now hooked up and will get called from Killable when the events occur. Note that the Listener does not need to be in the same object as the Killable.
Included Listeners & Events
We have included Listeners for the following. Click on a link to jump to that section:
- Level Wave Settings: Events for Level Wave Settings
- Killable: Events for Killable
- Pool Boss: Events for Pool Boss
- Prefab Pool: Events for Prefab Pools
- Triggered Spawner: Events for Triggered Spawners
- Syncro Spawner: Events for Syncro Spawners
- World Variable: Events for World Variables. Can display / update the value on a Text component in Unity uGUI, NGUI, or TextMeshPro.
- Timed Despawner: Events for Timed Despawner
- Triggered Despawner: Events for Triggered Despawner
- Wave Music Changer: Events for Wave Music Changer
Level Settings Listener Events
- GameOver
- Lose (GameOver but you didn't win)
- LevelStarted (fired when the first Wave in a Level starts).
- LevelEnded (fired when the last Wave in a Level is completed).
- WaveItemsRemainingChanged (to update a display or any logic)
- WaveTimeRemainingChanged (to update a display of seconds)
-
WaveStarted
Tip: Use LevelSettings.CurrentLevelWave
if you want to get the wave #. - WaveEnded
- WaveEndedEarly
- WaveSkipped
- WaveCompleteBonusesStart (in case you want to modify the bonuses before they're awarded).
- WaveRestarted
- Win
Killable Listener Events
- Awake
- SpawnerDestroyed
- Despawning
- TakingDamage
- DamagePrefabSpawned
- DamagePrefabFailedToSpawn
- DeathDelayStarted
- DeathPrefabSpawned
- DeathPrefabFailedToSpawn
- ModifyingDamageWorldVariables
- ModifyingDeathWorldVariables
- WaitingToDestroyKillable (used to play a death animation or other side effect)
- DestroyingKillable
- DeterminingScenario - used to change the Scenario used (which set of World Variables are going to be modified)
Pool Boss Listener Events
- PercentInitialized
- InitializationComplete
- ItemSpawned
- ItemDespawned
Prefab Pool Listener Events
- PrefabGrabbedFromPool
- PoolRefilling
Triggered Spawner Listener Events
- CustomEventReceived
- Despawned
- EventPropagating
- PropagatedEventReceived
- WaveEndedEarly
- PropagatedWaveEndedEarly
- ItemFailedToSpawn
- ItemSpawned
- Spawned
- WaveEliminated
- WaveFinishedSpawning
- WaveStart
- WaveRepeat
- SpawnerDespawning
Syncro Spawner Listener Events
- EliminationWaveCompleted
- ItemFailedToSpawn
- ItemSpawned
- WaveFinishedSpawning
- WaveStart
- WaveRepeat
World Variable Listener Events
- UpdateValue
World Variable Listener also has some fields for display logic.
- Decimal Places (number of decimal places).
- Use Comma formatting.
Timed Despawner Listener Events
- Despawning
Triggered Despawner Listener Events
- Despawning
Wave Music Changer Listener Events
- MusicChanging