Skip to main content

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.

Constructors​

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

Fields​

15 private and internal fields
MemberWhat it is
private BuildupChild[] buildupChildrenThe child slots.
private int childCountNumber of slots, kept in step with buildupChildren.
private MonoBehaviour[] disableWithChildrenComponents turned off while children are attached.
private BuildupPickupEvent finishedEvent fired on the server once the last child is gone.
private int grabPointWhileActiveIndex of the only grab point usable while children are attached; -1 leaves grab points alone.
private bool hasChildrenWhether buildup is active.
private ImpactDetector impactDetectorDetector whose slash hits knock children off.
private bool isFinishedSet once all children are gone, so finished fires once.
private uint maxChildrenUpper bound for the rolled child count on first spawn.
private uint minChildrenLower bound for the rolled child count on first spawn.
private AnimationCurve probabilityCurveShapes the random roll between min and max children.
private Dictionary<int, int> serializedChildrenIndexDuring load, maps saved child indexes to slots.
private MethodSync syncChildrenNetwork sync for the child list.
private MethodSync syncEnabledNetwork sync for the active state.
private MethodSyncStruct<BuildupPickup.DisposeData> syncLoseChildNetwork sync for losing a child.

Methods​

MemberWhat 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
MemberWhat 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.