Skip to main content

PickupContainer

A class in Root.Township, the global namespace.

Makes a dock act as a stack container players can grab from, such as a pouch or a fixed stack. Handles a quick grab of one item, a held grab that takes the whole stack or half as a new pouch, moving items one at a time between two held containers, and pouches breaking when nearly empty. The server applies all quantity changes.

Constructors​

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

Fields​

13 private and internal fields
MemberWhat it is
private float distanceTriggerSquaredSquared hand movement during a grip that counts as pulling a single item out.
private PickupDock dockThe dock that holds the contents.
private bool isBreakableIf set, the pouch breaks when nearly empty and can't be emptied below 3 by moving.
private bool isGrabHalvedIf set, a held grab takes half the stack instead of all of it.
private static readonly Logger loggerNLog logger for this class.
private MethodSyncStruct<uint> moveQuantityMethod sync that moves one item to another dock.
private MemoizeOne<uint, PickupDock> moveToDockCached lookup of the target dock by entity id.
private Coroutine movingThe running CheckMove coroutine.
private Pickup pickupBacking field for Pickup.
private float pickupDurationSeconds to hold a grab before it takes the stack (0.5 by default).
private AnimationCurve sendSpeedCurve of items per second against how long the move button has been held.
private MethodSyncStruct<RequestPouchArguments> spawnPouchMethod sync for client pouch requests.
private bool startActiveWhether the container starts active.

Properties​

MemberWhat it is
bool IsActive { get; private set; }True when the container's grab behaviour is on. Changed with SetActive.
Pickup Pickup { get; }Optional pickup that carries this container, such as a pouch. Null for fixed containers.
protected override MultipleNotAllowedAction DefaultMultipleBlockedAction { get; }Blocks extra interactions that aren't allowed.
protected override MultipleInteractionAllowance DefaultMultipleInteractionAllowance { get; }Allows several hands and several players at once.

Methods​

MemberWhat it is
override Interactable CheckForward(Interactor interactor, out bool isForced)Decides what a grab really takes: an explicit forward target, the pouch pickup itself, the single item when only one is left, or this container.
override void Initialize()Creates the move quantity and spawn pouch method syncs.
override void Interact(Interactor interactor)Local: starts the matching grip timer when an active container is grabbed, unless it sits in another player's inventory dock.
void SetActive(bool isActive)Turns the container behaviour on or off, hooking or unhooking its events.
void UndockAll(Interactor interactor)Asks the server to give the player the whole stack as one pickup.
protected void Awake()Sets IsActive from startActive, hooks events if active and makes the dock forward to this.
23 private and internal methods
MemberWhat it is
private void CheckBreak(Interactor interactor, Pickup takenOut, PickupDock dock)Server: when a breakable pouch drops below 2 items, frees the last item (into the holder's hand if held) and destroys the pouch.
private bool CheckCompatibility(Pickup pickupTemp, PickupContainer container)True if the item could go in the container's dock, counting a full dock as compatible.
private IEnumerator CheckMove(Interactor hand1, Interactor hand2, IEnumerable<PickupContainer> inHand1, IEnumerable<PickupContainer> inHand2) (iterator)Local coroutine while holding two containers: blocks walking and moves one item per step in the direction the move-item buttons give, faster the longer they're held.
private void DestroyPickup(Interactor interactor, Pickup pickup, PickupDock droppedInto)When a pouch is docked into a stacking dock, moves its contents into that dock and removes the pouch.
private void DisplayMovement(PickupDock dock, Pickup pickup)Client: shows a ghost of the item flying into the target dock.
private void DropContainer(Interactable interactable, Interactor interactor)Unblocks walking and unhooks the other hand when the pouch is let go.
private void FilterInteraction(Interactor interactor, Interactable interactable, ref bool result)For an unbreakable container: blocks grabbing from it while docked somewhere that doesn't allow container use.
private void FinalizeGrab(Interactor interactor)After a full hold: grabs the pouch if it's docked, otherwise asks the server for a pouch of the stack (or half), or grabs a single item.
private void GetDirection(Interactor hand, float speedTime, ref int direction)Reads the hand's move item right or left buttons as 1, -1 or 0.
private void Grab(Interactor interactor, Interactable interactable)Swaps the hand to the given interactable, skipping this container in its forward list.
private IEnumerator GripTimer(Interactor interactor, BooleanInput hardInteractProxy) (iterator)Local coroutine for a hard grab: a short grab or moving the hand takes one item; holding for pickupDuration runs FinalizeGrab.
private IEnumerator GripTimerPouch(Interactor interactor, BooleanInput hardInteractProxy) (iterator)Local coroutine for a soft grab that then squeezes: holding the squeeze for pickupDuration runs FinalizeGrab, letting go early takes one item.
private void HandlePouchRequest(Controller controller, bool isFull)Server: hands the player one item if the stack is small, otherwise splits off the full stack or half into a new pickup in their hand.
private void MoveQuantity(IPlayer player, Stream stream, uint otherDockIdentifier)Moves one item from this dock to another dock by entity id. Server checks and applies it, then syncs. Clients show the movement.
private void MoveQuantity(IPlayer player, uint otherDockIdentifier)Moves one item from this dock to another dock by entity id. Server checks and applies it, then syncs. Clients show the movement.
private void NetworkSpawnPouch(IPlayer player, Stream stream, RequestPouchArguments args)Server: handles a client's pouch request after checking the hand belongs to that player.
private void OtherHandPickup(Interactor interactor, Interactable interactable)Re-runs the two-container check when the other hand grabs something.
private void PreventSelfDock(Interactor interactor, PickupDock dock, ref bool result)Stops the pouch docking into its own dock.
private void RemoveEvents()Unhooks the events SetupEvents added.
private void SetupEvents()Hooks the pouch's dock, break, grab and release events, or just the self-dock filter for a fixed container.
private void SpillOut(Pickup pickup)Server: undocks everything when the pouch breaks.
private void StartCheckMove(Interactable interactable, Interactor interactor)Local: if the other hand holds an active container, starts CheckMove between them.
private void StopMoving(Interactor interactor, Interactable interactable)Stops CheckMove and unblocks walking on both hands.