Skip to main content

SentGift

A class in Root.Township, the global namespace.

A gift package from a postbox. PostboxSender spawns it on the server, fills it with the sent items and stores it in the receiver's postbox; spawning it out gives the receiver the items.

Constructors​

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

Fields​

9 private and internal fields
MemberWhat it is
private string receiversNameReceiver's username.
private TextRenderer receiversNameTextText showing the receiver's name.
private string sendersNameSender's username.
private TextRenderer sendersNameTextText showing the sender's name.
private SentGiftTag senderTagSender and receiver user IDs, used to track sent and retrieved gifts.
private Transform spawnPositionCentre point the items spawn around.
private float spawnRadiusRadius of the random spread for spawned items.
private MethodSync syncSetupMethod sync for the names.
private SavableSavedDynamicObject[] toSpawnThe saved items inside the gift.

Methods​

MemberWhat it is
override void Initialize()Creates the setup sync.
override void InitializeAsServer(SpawnData spawnData)Server: shows the names on the tag.
override void OnConnected(Player player)Server: sends the sender and receiver names to a joining player.
void Setup(string sendersName, string receiversName, SentGiftTag senderTag, SavedDynamicObject[] toSpawn)Server: sets the names, sender tag and the saved items to spawn. Called by PostboxSender.
void Spawn()Server: marks the gift as retrieved with PostBoxSenderManager, then spawns each item owned near spawnPosition in this chunk.
3 private and internal methods
MemberWhat it is
private void OnDrawGizmosSelected()Editor: draws the spawn radius.
private void SyncSetup(IPlayer player, Stream stream)Syncs the sender and receiver names and updates the tag on clients.
private void UpdateNameTag()Shows the sender and receiver names on the text renderers, except on headless.