TilePlus Version 5
Unity3D Tilemap Extension
Loading...
Searching...
No Matches
TilePlus.TpEvents Class Reference

Events library for TilePlus tiles. More...

Static Public Member Functions

static void ClearOnTileEventSubscribers ()
 Clears OnTileEvent events.
static void PostTileEvent (TilePlusBase tpb, bool alwaysUseOnTileEvent=false)
 Post an event.
static bool ProcessEvents (List< TilePlusBase >? output=null, bool handleEventsWithActions=true)
 Get and/or process (using EventActions) all events. CLEARS THE SET OF PENDING EVENTS ON EXIT.
static void RemoveEvent (TilePlusBase instance)
 Remove a single Tile from all event queues.
static bool ClearPendingEvents ()
 Clear any pending events.
static bool GetAllEvents (List< TilePlusBase > output, bool clear=true)
 Get all the pending events into a list which you provide. Useful if it's not desirable to process them using ProcessEvents.

Properties

static bool AnyEvents [get]
 Are there any events to handle?
static int NumEvents [get]
 Count of pending events.

Events

static ? Action< Guid > OnTileEvent
 Subscribe to get notified when your tile sends a event notice in immediate mode or for communication. Note that this includes the GUID of the tile in case you need to access the tile. To avoid memory leaks avoid making persistent copies of TPT tile references outside of the subscriber's event handler for this event. See: TpLib.GetTilePlusBaseFromGuid(Guid,bool)

Detailed Description

Events library for TilePlus tiles.

Member Function Documentation

◆ ClearOnTileEventSubscribers()

void TilePlus.TpEvents.ClearOnTileEventSubscribers ( )
static

Clears OnTileEvent events.

◆ ClearPendingEvents()

bool TilePlus.TpEvents.ClearPendingEvents ( )
static

Clear any pending events.

Returns
FALSE if there were any pending events remaining

◆ GetAllEvents()

bool TilePlus.TpEvents.GetAllEvents ( List< TilePlusBase > output,
bool clear = true )
static

Get all the pending events into a list which you provide. Useful if it's not desirable to process them using ProcessEvents.

Parameters
outputList to place the tile instances which have posted events.
clearclear the internal events list when done.

◆ PostTileEvent()

void TilePlus.TpEvents.PostTileEvent ( TilePlusBase tpb,
bool alwaysUseOnTileEvent = false )
static

Post an event.

Parameters
tpbtile instance sending the event. usually 'this' is OK
alwaysUseOnTileEventAlways emit OnTileEvent event

A HashSet is used to track which tile has events. HashSets ignore repeated adds of the same TilePlusBase instance. Normally, the OnTileEvent is not emitted if the HashSet.Add returns false because the same instance is added more than once. If you really want the OnTileEvent to be emitted for each add attempt, regardless of whether it's the same instance, alwaysUseOnTileEvent should be set to true.

◆ ProcessEvents()

bool TilePlus.TpEvents.ProcessEvents ( List< TilePlusBase >? output = null,
bool handleEventsWithActions = true )
static

Get and/or process (using EventActions) all events. CLEARS THE SET OF PENDING EVENTS ON EXIT.

Parameters
outputList for result, if null: see remarks. If not null, it's cleared
handleEventsWithActionsdefault is true. If true, automatically handle events where the tile has an Event Action. Any tiles that had posted events but don't have Event Actions will be returned in the output list (if it was provided on entry). If there are none then the list is returned empty. If this param is FALSE and output == null then nothing can occur so a warning is sent to the console.

If output is null then an internal list is allocated from a pool. This is only useful if you don't need the list back because all operations in response to the events are handled by TPT tile event actions. If 'output' is null and handleEventsWithActions is false then nothing happens at all.

If a tile has NO event actions it's added to the output list, hence, if you will have events from tiles NOT handled by event actions you really neeed the output list.

the internal set of pending tile events is ALWAYS cleared when this method exits. Alternatively, use GetAllEvents and process them yourself, followed by ClearPendingEvents.

◆ RemoveEvent()

void TilePlus.TpEvents.RemoveEvent ( TilePlusBase instance)
static

Remove a single Tile from all event queues.

Parameters
instancethe tile instance that originally sent the event
Returns
true if successful

Property Documentation

◆ AnyEvents

bool TilePlus.TpEvents.AnyEvents
staticget

Are there any events to handle?

◆ NumEvents

int TilePlus.TpEvents.NumEvents
staticget

Count of pending events.

Event Documentation

◆ OnTileEvent

? Action<Guid> TilePlus.TpEvents.OnTileEvent
static

Subscribe to get notified when your tile sends a event notice in immediate mode or for communication. Note that this includes the GUID of the tile in case you need to access the tile. To avoid memory leaks avoid making persistent copies of TPT tile references outside of the subscriber's event handler for this event. See: TpLib.GetTilePlusBaseFromGuid(Guid,bool)


The documentation for this class was generated from the following file:
  • /Users/jms/Documents/Tpt_55/TPT55/Assets/Plugins/TilePlus/Runtime/StaticLib/TpEvents.cs