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.
- Listed in Global namespace: P
- Inherits or implements
NetworkEntityBehaviour - Documented in Trading
Constructors
| Member | What it is |
|---|---|
Postbox() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
14 private and internal fields
| Member | What it is |
|---|---|
private static int Active | Animator hash for the flag's Active bool. |
private Animator flag | Animator for the flag that shows the local player has mail. |
private Lever handleLever | The lever whose TurnedOn event starts popping items. |
private Pickup handlePickup | The handle pickup; its last player interactor is who receives their mail. |
private float interval | Seconds between popped items. |
private bool isRotationRandom | When true, popped items get a random rotation instead of the spawn point's. |
private bool isSpawning | True while Opened is popping items, so a second pull doesn't start another run. |
private static Logger logger | NLog logger for this class. |
private Vector3 position | Spawn position captured when the lever is pulled. |
private Quaternion rotation | Spawn rotation captured when the lever is pulled. |
private Transform spawnPoint | Where popped items appear and the frame velocityRelativeToSpawnPoint is measured in. |
private MethodSyncStruct<bool> sync | Per-player message carrying whether that player has mail. |
private Vector3 velocity | World-space launch velocity captured when the lever is pulled. |
private Vector3 velocityRelativeToSpawnPoint | Launch velocity for popped items, in the spawn point's local space. |
Methods
| Member | What 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
| Member | What 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. |