BuildupPickup
A class in Root.Township, the global namespace.
A pickup with child items attached in slots, which slash hits knock off. While it has children it can't be docked and some components are disabled. Server controlled and saved.
- Listed in Global namespace: A to B
- Inherits or implements
NetworkEntityBehaviour,ISavable<BuildupPickupSaveData>,ISavableSave<BuildupPickupSaveData>,ISavableSaveBase - Derived types
BuildupPickupEvent,BuildupPickupHandler,BuildupPickupSaveData - Nested types
DisposeData - Attributes
RequireComponent
Constructors
| Member | What it is |
|---|---|
BuildupPickup() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
15 private and internal fields
| Member | What it is |
|---|---|
private BuildupChild[] buildupChildren | The child slots. |
private int childCount | Number of slots, kept in step with buildupChildren. |
private MonoBehaviour[] disableWithChildren | Components turned off while children are attached. |
private BuildupPickupEvent finished | Event fired on the server once the last child is gone. |
private int grabPointWhileActive | Index of the only grab point usable while children are attached; -1 leaves grab points alone. |
private bool hasChildren | Whether buildup is active. |
private ImpactDetector impactDetector | Detector whose slash hits knock children off. |
private bool isFinished | Set once all children are gone, so finished fires once. |
private uint maxChildren | Upper bound for the rolled child count on first spawn. |
private uint minChildren | Lower bound for the rolled child count on first spawn. |
private AnimationCurve probabilityCurve | Shapes the random roll between min and max children. |
private Dictionary<int, int> serializedChildrenIndex | During load, maps saved child indexes to slots. |
private MethodSync syncChildren | Network sync for the child list. |
private MethodSync syncEnabled | Network sync for the active state. |
private MethodSyncStruct<BuildupPickup.DisposeData> syncLoseChild | Network sync for losing a child. |
Methods
| Member | What it is |
|---|---|
override void Initialize() | Sets up the sync messages for children, enabled state and losing a child. |
override void InitializeAsServer(SpawnData spawnData) | Server: on first generation fills the child slots (all of them, whatever the min and max counts say) and destroys stray children. |
void LoseRandomChild() | Server: knocks off one random attached child, if any. |
override void OnConnected(Player player) | Server: sends a joining player the attached children and enabled state. |
13 private and internal methods
| Member | What it is |
|---|---|
private void CutChild(ImpactHit impact) | Server: on a slash hit (when not forwarded), knocks off the child closest to the hit point. |
private void DockFilter(Interactor interactor, PickupDock dock, ref bool result) | Stops the pickup docking while any child is still attached. |
private void LoseChild(int index, bool isForced = false) | Detaches the child in a slot, syncs it, and when none are left disables buildup and fires finished. |
private void NetworkLoseChild(IPlayer player, Stream stream, BuildupPickup.DisposeData disposeData) | Message handler that sends or applies a child being lost. |
private void OnValidate() | Empty. |
private void RegisterChild(NetworkPrefab prefab, NetworkEntity parent, int childIndex) | Load callback: links a saved child entity back to its slot. |
private void SetEnable(bool enabled) | Turns the buildup state on or off: toggles disableWithChildren, the dock filter, grab points and the slash handler, and syncs it. |
private BuildupChild SetupChild(NetworkEntity child, int index) | Registers an entity as the child of a slot and returns the slot. |
private bool SetupChildCount() | Editor: keeps childCount equal to the number of slots. |
private void SpawnChildren(int quantity) | Server: spawns a child in every slot, starting at a random one. The quantity only picks the start, so min and max don't limit the count. |
private void SyncChildren(IPlayer player, Stream stream) | Sends or reads which slots have a child and its entity id; clients wait for each to spawn and link it. |
private void SyncEnabled(IPlayer player, Stream stream) | Sends or reads whether buildup is active. |
private void ValidateHit(ImpactHit hit, ref bool isValid) | Marks a hit invalid while any child is attached. Not hooked up in this class. |