TradeStateManager
A class in Root.Township, Alta.Trading.
Syncs a trade vendor's status (unoccupied, out of stock, open for sale) to clients and fires an event per status for visuals. The server reads the status from the TradeVendor.
- Listed in Crafting and making
- Inherits or implements
NetworkEntityBehaviour
Constructors
| Member | What it is |
|---|---|
TradeStateManager() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
8 private and internal fields
| Member | What it is |
|---|---|
private TradeStatus index | The current TradeStatus, or -1 before the first one. |
private BoolEvent[] indexedEvents | Client: the status events, indexed by TradeStatus value. |
private static Logger logger | Logger for this class; unused. |
private BoolEvent onOpenForSale | Event set true while the vendor is open for sale, false otherwise. |
private BoolEvent onOutOfStock | Event set true while the vendor is out of stock. |
private BoolEvent onUnnocupied | Event set true while the vendor has no owner. |
private MethodSync sync | The status sync message. |
private TradeVendor vendor | The vendor whose status is shown. |
Methods
| Member | What it is |
|---|---|
override void Initialize() | Server: listens to the vendor's status changes. Client: sets all status events to false. Both: sets up the sync message. |
override void InitializeAsServer(SpawnData spawnData) | Server: applies the vendor's current status. |
override void OnConnected(Player player) | Sends the current status to a player who just connected. |
2 private and internal methods
| Member | What it is |
|---|---|
private void StatusChanged(TradeStatus index) | Switches the previous status event off and the new one on. On the server it then sends the status to nearby players. |
private void Sync(IPlayer player, Stream stream) | Writes the status as an integer; clients apply what they read. |