-
Notifications
You must be signed in to change notification settings - Fork 3
Beacon Handle Extensions
BeaconHandleExtensions provides typed convenience helpers for reading Beacon payloads without expanding the small immutable BeaconHandle core API.
The positional helpers access known payload indexes directly. They do not scan or enumerate the payload collection.
| Feature | Description |
|---|---|
| First-item access | Read payload item zero without writing an index |
| Multi-value TryGet | Read the first two through five typed payload values in one call |
| Fallback values | Return a fallback when an item is missing or has another type |
| Type checks | Test whether a payload position contains a requested type |
| Topic checks | Compare a handle against a string or enum topic |
| Payload checks | Test whether a handle has any data |
Get<T>() reads payload item zero.
Player player = handle.Get<Player>();This is equivalent to:
Player player = handle.Get<Player>(0);Indexed access remains available directly on BeaconHandle when another payload position is needed.
Read the first payload item:
if (handle.TryGet(out Player player))
{
UsePlayer(player);
}Multiple positional payload items can be read together, up to five values:
if (handle.TryGet<Vect2, int, string>(
out var position,
out var score,
out var reason))
{
ShowResult(position, score, reason);
}All requested positions must exist and match their requested types for the multi-value overload to return true.
For indexed access, use the core handle method:
if (handle.TryGet<int>(1, out var damage))
{
ApplyDamage(damage);
}Return a fallback when the payload is missing or has another type.
First item:
int score = handle.GetOr(0);Indexed item:
int damage = handle.GetOr(1, 0);Check the first payload item:
bool hasPlayer = handle.Has<Player>();Check a specific payload position:
bool hasDamage = handle.Has<int>(1);Compare the handle topic against a string:
if (handle.IsTopic("PlayerDied"))
{
// Handle PlayerDied.
}Or against an enum:
if (handle.IsTopic(GameBeacons.PlayerDied))
{
// Handle PlayerDied.
}Enum topics use the same enum-string representation as the Beacon Manager.
if (handle.HasData())
{
// One or more payload items are available.
}
if (handle.IsEmpty())
{
// No payload items were published.
}These map directly to the handle's payload count.
BeaconManager.Instance.Subscribe(GameBeacons.PlayerDied, handle =>
{
if (!handle.TryGet<Vect2, int>(out var position, out var score))
return;
if (handle.IsTopic(GameBeacons.PlayerDied))
ShowDeathScreen(position, score);
});For the publish/subscribe flow itself, see Beacon Event System. For subscription lifetime helpers such as SubscribeOnce, see BeaconManager Extensions.
| Method | Description |
|---|---|
Get<TData>() |
Get payload item zero as TData
|
TryGet<T1>(out T1) |
Try to read payload item zero |
TryGet<T1, ... T5>(...) |
Try to read the first two through five payload items |
GetOr<TData>(fallback) |
Read item zero or return a fallback |
GetOr<TData>(index, fallback) |
Read an indexed item or return a fallback |
Has<TData>() |
Test item zero for a type |
Has<TData>(index) |
Test an indexed item for a type |
IsTopic(string / Enum) |
Test the handle's topic |
HasData() |
true when one or more payload items exist |
IsEmpty() |
true when the payload is empty |
Home · Getting Started · Rendering · Custom Renderers · GitHub · Report an Issue
Built with VOID Engine · MIT License
- Coroutines
- State Machine
- Save System
- Pathfinding
- Logging
- Beacon Manager
- Beacon Event System
- Discoverable System
- Instance Helper
- BeaconManager Extensions
- BeaconHandle Extensions
- Enum Extensions
- String Extensions
- Int Extensions
- Float Extensions
- IEnumerable Extensions
- Random Extensions
- Sound Extensions
- Font Extensions