Skip to main content

PostBoxSenderManager

A class in Root.Township, the global namespace.

Tracks how many gifts each player may still send to each other player through post boxes, with a cap of GiftsPerPlayer. The server keeps the counts and syncs each player their own; use the static instance.

Constructors​

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

Fields​

MemberWhat it is
static PostBoxSenderManager instanceThe scene's instance, set in Awake.
4 private and internal fields
MemberWhat it is
private int giftsPerPlayerBacking field for GiftsPerPlayer.
private Dictionary<int, PostBoxSenderManager.PerPlayerSendingCount> perPlayerCounterRemaining allowance by sender user id, then by receiver user id. Not saved in this file.
private MethodSync syncAllMethod sync for all counts.
private MethodSyncStruct<int> syncSingleMethod sync for one count.

Properties​

MemberWhat it is
int GiftsPerPlayer { get; }Gift allowance per sender and receiver pair (3 by default).

Methods​

MemberWhat it is
int GetAvailableQuantity(int fromIdentifier, int toIdentifier)How many gifts one player can still send another. Full allowance if none have been sent.
override void Initialize()Creates the full and single count syncs.
override void OnConnected(Player player)Sends a joining remote player all their counts.
void Retrieve(int fromIdentifier, int toIdentifier, int quantity)Gives back allowance when a sent gift is taken back, up to the cap, and syncs the sender.
void Send(int fromIdentifier, int toIdentifier, int quantity)Uses up allowance for a gift from one player to another and syncs the sender.
4 private and internal methods
MemberWhat it is
private void Awake()Sets the static instance.
private void SendToRemoteFromPlayer(int fromIdentifier, int toIdentifier)Sends the sender their updated count for one receiver, unless the sender is the local player.
private void SyncAll(IPlayer player, Stream stream)Sends a player all their counts. Client: stores them under the logged-in user.
private void SyncSingle(IPlayer player, Stream stream, int toIdentifier)Sends a player their count for one receiver. Client: stores it.