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

This is a 'union' of the most likely Types of objects one might like to send. For the UnityObject and object values the type is is available. The optional info string can be used to provide context (ie target switching actions based on what the string is), debug info, or left empty. More...

Inheritance diagram for TilePlus.ObjectPacket:
Collaboration diagram for TilePlus.ObjectPacket:

Public Types

enum  ZoneCapability { None = 0 , SendOnValueChange = 1 , AcceptFromOthers = 2 }
 This enum controls how a tile works with Zones, if at all. Has no meaning outside of that context. More...
enum  EventsPropagationMode { None = 0 , ZoneEvents = 1 , TriggerEvents = 2 , Both = ZoneEvents | TriggerEvents }
 Controls event propagation, if any. More...

Public Member Functions

override void Reset ()
 Reset this instance. Useful if pooled.
void UpdateInstance (Object? sourceInstance, UnityEngine.Object unityEngineObject, object csObject, string info="", EventsPropagationMode mode=EventsPropagationMode.None)
 UPDATE INSTANCE. When pooling, use this to set the main values since Ctor can't be used.
 ObjectPacket (Object? sourceInstance=null)
 Use this for pooling or creating an empty instance. Not necc to provide a sourceInstance value. This artifice is required because the base class doesn't have (nor can have) a parameterless constructor.
 ObjectPacket (Object sourceInstance, string info="", EventsPropagationMode eventsPropagation=EventsPropagationMode.None)
 Initializes a new instance of the class with just the source instance.
 ObjectPacket (Object? unityObject, Object? sourceInstance=null, string info="", EventsPropagationMode eventsPropagation=EventsPropagationMode.None)
 Initializes a new instance of the class with just a unityObject.
 ObjectPacket (Object? unityObject, object? objectValue, Object? sourceInstance=null, EventsPropagationMode eventsPropagation=EventsPropagationMode.None, string info="")
 Initializes a new instance of the class with a GameObject and a c# object.
 ObjectPacket (object? objectValue, Object? sourceInstance=null, EventsPropagationMode eventsPropagation=EventsPropagationMode.None, string info="")
 Initializes a new instance of the class with just a c# object.
override string ToString ()

Properties

EventsPropagationMode EventsPropagation [get, set]
 Control events pass-thru when this packet is sent to tiles that can post events. The default value is zero which means NO events pass thru. Note that this is a FLAGS enum.
string Command [get, set]
 optional 'command' string, can be used for anything but typically is a string value used by the message target. E.G., Command_ZoneAction is the value when a TpTileZoneAction emits this packet. Please note that the 'command' XY_ZZ_Y is reserved for use by the Service manager's messaging scheme.
bool HasCommand [get]
 true if command string isn't empty.
ObjectUnityObject [get, set]
 UnityEngine.Object.
bool HasUnityObject [get]
 True if there's a Unity Object in this instance.
TypeUnityObjectType [get]
 The type of the Unity Object.
object? ObjectValue [get, set]
 c# object
bool HasObject [get]
 True if there's a C# object in this instance.
TypeObjectType [get]
 The type of the c# object.
bool? BoolValue [get, set]
 Optional Arbitrary Boolean value.
bool HasBoolValue [get]
 True if the bool in this instance is valid.
int? IntValue [get, set]
 Optional Arbitrary Integer value.
bool HasIntValue [get]
 True if the Int in this instance is valid.
string StringValue [get, set]
 Optional Arbitrary String value.
bool HasStringValue [get]
 True if the string in this instance is neither null nor empty.
Properties inherited from TilePlus.MessagePacket< T >
ObjectSourceInstance [get, set]
 The instance that's the source of the message. Can be null.
ulong Id [get, set]
 The ID of this packet. Packet recepients can test this to see if they're being sent the same message repeatedly. Note that 0 is not used except internally.

Additional Inherited Members

Protected Member Functions inherited from TilePlus.MessagePacket< T >
 MessagePacket (Object? sourceInstance)
 Source Instance for this packet. Can be null.

Detailed Description

This is a 'union' of the most likely Types of objects one might like to send. For the UnityObject and object values the type is is available. The optional info string can be used to provide context (ie target switching actions based on what the string is), debug info, or left empty.

This was created primarily for tile-to-tile messaging and event propogation but it can obviously be used for other things.

This is a class with a lot of fields etc so pooling might be used. There's a reset method if you decide to do so. Normally that should be used when an instance is returned to the pool so that references are not held. -------------—*******************-----------------— NOTE: if not pooling, use Reset if possible when done with the instance so that GC can work properly. -------------—*******************-----------------— There's a pool for this object set up in TpMessaging. Example: using (TpMessaging.S_ObjectPacketInPool.Get(out var packet)) { //init packet via properties or UpdateInstance TpMessaging.SendMessage<EmptyPacket, ObjectPacket, ITpMessaging<EmptyPacket, ObjectPacket>>(..) }

Useful for TPT tiles since they can't have scene references. For that use case, a GameObject can be passed as the UnityEngine.Object reference as an 'injection'.

This class is also useful for passing around messages between tiles, as can be seen in 'Zone Actions' and the TileUi demo and customized tiles for UI use.

NOTE that since there are object and Object refs in here, don't cache these unless you null the objects after use (use Reset) or you'll have memory leaks. If pooling, use RESET when returning to the pool. The pool in TpMessaging does this.

Optional string, int, and bool values are provided as properties. When you create an instance of this packet set those as appropriate.

The int and bool values are nullable so be sure to use .hasValue or use the supplied 'Has' properties, and use int.Value or bool.Value.

HasInfoString, HasBoolValue, HasIntValue, and HasStringValue are updated when the corresponding properties are Set, so use those rather than .hasValue or explicit null checks if possible. The packet may be evaluated by many tiles so these 'Has' properties are much more efficient.

Similarly, use HasUnityObject and HasObject rather than explicit null checks.

Use HasInfoString instead of string.Empty, for efficiency.

All of the 'Has' values are pre-created in the constructor (when it sets the properties) or when you directly write to any of the properties including the three optional properties BoolValue, IntValue, StringValue.

Member Enumeration Documentation

◆ EventsPropagationMode

Controls event propagation, if any.

Enumerator
None 

No events.

ZoneEvents 

Propagate Zone events.

TriggerEvents 

Propagate Trigger events.

Both 

Propagate both types of events.

◆ ZoneCapability

This enum controls how a tile works with Zones, if at all. Has no meaning outside of that context.

Note: is FLAGS enum so BOTH operations are possible. If both SEND and ACCEPT are active it's up to you to ensure no loops. There's some checking for this but it's not exhaustive.

It's easy to check for 'loops' like this in the TpTileZoneAction

Enumerator
None 

Zone features not used.

SendOnValueChange 

This tile will send events if a ZoneAction S.O. exists (this is in the TilePlusBase class)

AcceptFromOthers 

This indicates that this tile is willing to accept ObjectPacket messages. Note that implementing IZoneActionTarget is also required.

Constructor & Destructor Documentation

◆ ObjectPacket() [1/5]

TilePlus.ObjectPacket.ObjectPacket ( Object? sourceInstance = null)

Use this for pooling or creating an empty instance. Not necc to provide a sourceInstance value. This artifice is required because the base class doesn't have (nor can have) a parameterless constructor.

Use this for creating a new instance when pooling. Note that you have to use UpdateInstance or properties if you want something useful! BE SURE TO UPDATE SOURCEINSTANCE /remarks>

◆ ObjectPacket() [2/5]

TilePlus.ObjectPacket.ObjectPacket ( Object sourceInstance,
string info = "",
EventsPropagationMode eventsPropagation = EventsPropagationMode::None )

Initializes a new instance of the class with just the source instance.

Parameters
sourceInstancethe source of this packet or null. Note that for this Ctor the sourceInstance CANNOT be null and it's not a 'nullable' value. Therefore, if sourceInstance IS null, an exception is thrown. Your IDE ought to warn you when making this mistake.
infoOptional Info string
eventsPropagationControl events propogation

◆ ObjectPacket() [3/5]

TilePlus.ObjectPacket.ObjectPacket ( Object? unityObject,
Object? sourceInstance = null,
string info = "",
EventsPropagationMode eventsPropagation = EventsPropagationMode::None )

Initializes a new instance of the class with just a unityObject.

Parameters
unityObjectvalue for this packet
sourceInstanceSource of message or null
infoOptional string.
eventsPropagationOptional EventsPropogationMode setting

◆ ObjectPacket() [4/5]

TilePlus.ObjectPacket.ObjectPacket ( Object? unityObject,
object? objectValue,
Object? sourceInstance = null,
EventsPropagationMode eventsPropagation = EventsPropagationMode::None,
string info = "" )

Initializes a new instance of the class with a GameObject and a c# object.

Parameters
unityObjectUnityEngine.Object for this packet
objectValueobject for this packet
sourceInstanceSource of message or null
eventsPropagationOptional EventsPropogationMode setting
infoOptional string.

◆ ObjectPacket() [5/5]

TilePlus.ObjectPacket.ObjectPacket ( object? objectValue,
Object? sourceInstance = null,
EventsPropagationMode eventsPropagation = EventsPropagationMode::None,
string info = "" )

Initializes a new instance of the class with just a c# object.

Parameters
objectValueobject for this packet
sourceInstanceSource of message or null
eventsPropagationOptional EventsPropogationMode setting
infoOptional string.

Member Function Documentation

◆ Reset()

override void TilePlus.ObjectPacket.Reset ( )
virtual

Reset this instance. Useful if pooled.

Reimplemented from TilePlus.MessagePacket< T >.

◆ ToString()

override string TilePlus.ObjectPacket.ToString ( )

◆ UpdateInstance()

void TilePlus.ObjectPacket.UpdateInstance ( Object? sourceInstance,
UnityEngine.Object unityEngineObject,
object csObject,
string info = "",
EventsPropagationMode mode = EventsPropagationMode::None )

UPDATE INSTANCE. When pooling, use this to set the main values since Ctor can't be used.

Parameters
sourceInstancesource of the packet or null.
unityEngineObjectUnityEngine.Object or null
csObjectc-sharp object or null
infoInfo string or string.empty
modeEvents propogation mode.

Use this to update an existing instance when using pooling. Alternatively use the properties directly.

Property Documentation

◆ BoolValue

bool? TilePlus.ObjectPacket.BoolValue
getset

Optional Arbitrary Boolean value.

◆ Command

string TilePlus.ObjectPacket.Command
getset

optional 'command' string, can be used for anything but typically is a string value used by the message target. E.G., Command_ZoneAction is the value when a TpTileZoneAction emits this packet. Please note that the 'command' XY_ZZ_Y is reserved for use by the Service manager's messaging scheme.

◆ EventsPropagation

EventsPropagationMode TilePlus.ObjectPacket.EventsPropagation
getset

Control events pass-thru when this packet is sent to tiles that can post events. The default value is zero which means NO events pass thru. Note that this is a FLAGS enum.

◆ HasBoolValue

bool TilePlus.ObjectPacket.HasBoolValue
get

True if the bool in this instance is valid.

◆ HasCommand

bool TilePlus.ObjectPacket.HasCommand
get

true if command string isn't empty.

◆ HasIntValue

bool TilePlus.ObjectPacket.HasIntValue
get

True if the Int in this instance is valid.

◆ HasObject

bool TilePlus.ObjectPacket.HasObject
get

True if there's a C# object in this instance.

◆ HasStringValue

bool TilePlus.ObjectPacket.HasStringValue
get

True if the string in this instance is neither null nor empty.

◆ HasUnityObject

bool TilePlus.ObjectPacket.HasUnityObject
get

True if there's a Unity Object in this instance.

◆ IntValue

int? TilePlus.ObjectPacket.IntValue
getset

Optional Arbitrary Integer value.

◆ ObjectType

Type? TilePlus.ObjectPacket.ObjectType
get

The type of the c# object.

◆ ObjectValue

object? TilePlus.ObjectPacket.ObjectValue
getset

c# object

◆ StringValue

string TilePlus.ObjectPacket.StringValue
getset

Optional Arbitrary String value.

◆ UnityObject

Object? TilePlus.ObjectPacket.UnityObject
getset

UnityEngine.Object.

◆ UnityObjectType

Type? TilePlus.ObjectPacket.UnityObjectType
get

The type of the Unity Object.


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