Skip to main content

Postbox

A class in Root.Township, the global namespace.

The postbox players collect mail from. Server: pulling its lever pops the puller's queued items out of their PlayerPostboxStorage one by one; each player sees its flag raised only when they have mail.

Constructors​

MemberWhat it is
Postbox()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

14 private and internal fields
MemberWhat it is
private static int ActiveAnimator hash for the flag's Active bool.
private Animator flagAnimator for the flag that shows the local player has mail.
private Lever handleLeverThe lever whose TurnedOn event starts popping items.
private Pickup handlePickupThe handle pickup; its last player interactor is who receives their mail.
private float intervalSeconds between popped items.
private bool isRotationRandomWhen true, popped items get a random rotation instead of the spawn point's.
private bool isSpawningTrue while Opened is popping items, so a second pull doesn't start another run.
private static Logger loggerNLog logger for this class.
private Vector3 positionSpawn position captured when the lever is pulled.
private Quaternion rotationSpawn rotation captured when the lever is pulled.
private Transform spawnPointWhere popped items appear and the frame velocityRelativeToSpawnPoint is measured in.
private MethodSyncStruct<bool> syncPer-player message carrying whether that player has mail.
private Vector3 velocityWorld-space launch velocity captured when the lever is pulled.
private Vector3 velocityRelativeToSpawnPointLaunch velocity for popped items, in the spawn point's local space.

Methods​

MemberWhat it is
override void Initialize()Creates the sync message used to tell a player whether they have mail.
override void InitializeAsServer(SpawnData spawnData)Server: hooks Opened to the lever turning on.
override void OnConnected(Player player)Server: runs InitializeForPlayer for each player who connects to the entity.
override void OnDisconnected(Player player)Server: unsubscribes from the leaving player's storage events, if it's loaded.
6 private and internal methods
MemberWhat it is
private bool HandleNew(NetworkEntity spawned)Server: places one popped entity at the spawn point with the launch velocity and fires its IPostboxPopped handlers. Recurses into children of a SetPiece; destroys other entities without a rigidbody.
private async void InitializeForPlayer(Player player)Server: loads the player's postbox storage, sends them the current has-mail state and subscribes to its item added and removed events.
private void ItemAdded(PlayerPostboxStorage storage, int count)Server: when a player's storage goes from empty to one item, tells that player to raise the flag.
private void ItemRemoved(PlayerPostboxStorage storage, int count)Server: when a player's storage becomes empty, tells that player to lower the flag.
private async void Opened()Server: while the lever stays on and the same player holds the handle, pops their items one at a time, waiting interval seconds between them.
private void SyncContent(IPlayer player, Stream stream, bool hasContent)Serializes the has-mail bool; on a client it sets the flag animator.