Overview
TilePlus Messaging and Events
TpLib has general-purpose messaging and Event functionality. Messages get sent to tiles, and tiles can post events.
Messages functionality uses the TpMessaging Service and Events functionality uses the TpEvents static class.
The use of Messages and Events facilitates event-driven design with TilePlus tiles. As your game proceeds you send Messages to tiles; usually from a Monobehaviour or other code which is responding to user input. Tiles post Events in response.
Messages are sent immediately. Events are stored and evaluated later.
A simple example: a game where there's a player character moving around. Your code messages all tiles interested in knowing where the player is located. If one of the messaged tiles decides that the player is at that tile's position or nearby it "posts" an Event. Your controlling program gets a callback announcing that an Event had been posted. At some point, perhaps during Update, you call a method in TpEvents to process the events.
The TpInputActionToTile
Component is a convenient way to use the Unity's New Input System. Attached to a GameObject and properly configured, it can be used to process the New Input System events and:
- Message a tile using the Messaging System
- Or get callbacks that a Click or other New Input System event had occurred.
- Automatically handle Events sent from tiles using EventAction Scriptable Objects.
- And/Or get information about which tiles posted Events and handle them yourself.
It's highly configurable and really useful: check it out in the Components chapter.