PickupDock
A class in Root.Township, Alta.Inventory.
A slot that holds pickups: backpack and belt slots, pouches, racks, crafting station inputs. A stack is one real docked Pickup plus a count in QuantityStored; the server spawns a fresh copy when one is taken out. Both sides; the server owns the count and syncs it.
- Listed in Items, inventory and logic
- Inherits or implements
Interactable,ISavableFull<PickupDockSaveData>,ISavable<PickupDockSaveData>,ISavableSave<PickupDockSaveData>,ISavableSaveBase,ISavableFull,IDockable,IBlockGenericDecrafting,IInitializeAsLocalPlayer,IInitializeAsRemotePlayer,IBuildRendererBakeable,IBuildBakeable - Derived types
DockStore,AdditionalOwnedDock,PickupDockSaveData,PickupDockedEvent,PickupDockedUnityEvent,PickupDockGroup,PickupDockPedestalSpawn - Nested types
AllowedResult - Attributes
SavingInfo - Documented in Other systems, Player inventory
Constructors
| Member | What it is |
|---|---|
PickupDock() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
Item dockedType | The Item type stored in the dock. Saved, and used to respawn the docked pickup on load. |
16 private and internal fields
| Member | What it is |
|---|---|
private List<Pickup> clientDocked | Client: pickups predicted as docked here before the server confirms, added to the shown count. |
private DockVisual dockVisual | Visual that shows the stored count text. |
private Coroutine hapticCoroutine | The running WaitForAnimation coroutine, restarted on each pass-through haptic. |
private List<Collider> hasContentsRange | Colliders enabled only while the dock holds something. |
private int hoverCount | Backing field for HoverCount. |
private bool isHapticAnimating | True while the pass-through haptic plays, so hover haptics are skipped. |
private int lastOfficialQuantity | The last quantity set through QuantityStored, which clients add their predicted items to. |
private static Logger logger | NLog logger for this class. |
private Collider pickupRange | Backing field for PickupRange. Disabled on headless servers. |
private Pickup previouslyDocked | The last pickup undocked from this dock. |
private int quantityStored | Backing field for QuantityStored. Saved with the dock. |
private ScaleAnimator scaleAnimator | Scales the dock up while a hand hovers over it. |
private NearbyPlayerScaler scaler | Optional NearbyPlayerScaler; docking forces it to scale for items the dock doesn't shrink. |
private SavedDynamicObject serializedData | Server: saved state of the docked item that new copies are spawned from when the stack is taken from. |
private PickupDockSettings settings | Backing field for Settings: what the dock accepts, stacking, scaling and haptics. |
private Transform snapPoint | Backing field for SnapPoint, the transform docked items are parented to. Defaults to the dock's own transform. |
Properties
| Member | What it is |
|---|---|
virtual bool AllowContainerInteraction { get; } | Whether the dock lets you interact through it to a container, taken from its settings. |
Pickup DockedPickup { get; private set; } | The one real pickup shown in the dock, standing in for the whole stack. Null when empty. |
bool HasDockedPickup { get; } | True if there is a docked pickup that is not being destroyed. |
int HoverCount { get; set; } | How many hands are hovering over the dock. Drives the hover scale animation and raises HoverCountChanged. |
bool IsOwnedByPlayer { get; protected set; } | True for docks on a player body (backpack, belt and so on). Set when the player controller initialises. |
int MaxQuantityCurrentlyPossible { get; } | Most the dock can hold right now: the docked item's stack size times the max stacks setting, or unlimited when empty or uncapped. |
DockPositioning OverridePositioning { get; set; } | Optional callback that replaces the default docked position, rotation and scale. |
Collider PickupRange { get; } | Collider for the area where pickups can be dropped into the dock. Disabled on headless servers. |
PlayerController PlayerController { get; protected set; } | The player that owns this dock, if IsOwnedByPlayer. |
int QuantityStored { get; set; } | How many items are in the stack. Setting it clamps at zero and runs OnQuantityChanged. Only the server's value is authoritative. |
PickupDockSettings Settings { get; } | The PickupDockSettings asset with this dock's rules (what it accepts, stacking, sizes, haptics, sounds). |
Transform SnapPoint { get; } | Transform docked pickups are parented to. |
MethodSync SyncQuantity { get; private set; } | The network sync that sends the stored count to clients. |
float TotalWeight { get; } | Weight of the docked pickup times the stored count. |
2 private and internal properties
Events
| Member | What it is |
|---|---|
event DockFilter DockFilter | Event for extra rules. Handlers can set the result to false to refuse a pickup, giving FilterFail. |
event PickupDockHoverHandler HoverCountChanged | Raised when HoverCount changes, with the old count. |
event PickupDockInteractionHandler ItemDocked | Raised after a pickup is docked. |
event PickupDockInteractionHandler ItemUndocked | Raised after a pickup is undocked. |
event SubDockHandler OnSubDocked | Raised when something docks into a dock on the pickup this dock belongs to. |
event SubDockHandler OnSubUndocked | Raised when something undocks from a dock on the pickup this dock belongs to. |
event PickupDockInteractionHandler PreItemDocked | Raised during docking, after the pickup is parented to the snap point but before it is counted. |
event QuantityChangeHandler QuantityChanged | Raised after the stored count changes and the text updates. |
event Action UpdateContent | Raised by UpdateChangedContent. |
event PickupDockHandler UpdatedPlayerOwnership | Raised when the dock is linked to its owning player. |
event Action WeightChanged | Raised when the docked weight changes (docking, undocking, or the docked pickup's weight changing). |
Methods
| Member | What it is |
|---|---|
override bool AssessScore(Interactor interactor, out float score) | Hand scoring for grabbing from the dock. A local hand without a hard grab is refused; otherwise the base score times ten. |
bool CanAccept(Pickup pickup) | True if the pickup is the same item type as what is docked and passes the transient check. |
bool CanAcceptUntyped(Pickup pickup) | True unless the pickup is transient and the dock's settings refuse transient pickups. |
bool CanDockAmount(int amount) | Whether adding that many would stay within MaxQuantityCurrentlyPossible. |
PickupDock.AllowedResult CheckAllowed(Interactor interactor, Pickup pickup) | Checks if a pickup or item may go in this dock and returns an AllowedResult reason. Covers pouches, filters, tags, crafting size and sub docks. |
PickupDock.AllowedResult CheckAllowed(Interactor interactor, Pickup pickup, int quantity, out PickupDock finalDock) | Checks if a pickup or item may go in this dock and returns an AllowedResult reason. Covers pouches, filters, tags, crafting size and sub docks. |
PickupDock.AllowedResult CheckAllowed(Item item) | Checks if a pickup or item may go in this dock and returns an AllowedResult reason. Covers pouches, filters, tags, crafting size and sub docks. |
override Interactable CheckForward(Interactor interactor, out bool isForced) | Grabbing the dock forwards to the docked pickup. A dock owned by a player refuses other players. |
void ClearDocked() | Forgets the docked pickup without undocking it or changing the count. |
void DestroyAmount(int count) | Server: removes that many from the stack, destroying the docked pickup if the count runs out. |
void DestroyAmountToEmpty() | Server: destroys the whole stored stack. |
bool DestroyPickupIfStackedInDock(Pickup pickup) | Server: destroys a pickup that was stacked into this dock (count above one and not the docked pickup). Returns true if it did. |
void GetPositioning(Item item, Pickup pickup, bool isScaling, out Vector3 position, out Quaternion rotation, out Vector3 scale) | Works out the local position, rotation and scale a pickup should have in the dock, using OverridePositioning if set and the item's positioning otherwise. |
override void Initialize() | Creates the quantity sync, hooks cleanup when the parent is destroyed and forwards sub dock events from the parent pickup. |
bool IsScaling(Pickup pickup) | Whether a pickup shrinks when docked here, based on the settings' scaling tags. |
static IEnumerator MoveToDock(PickupDock dock, Transform target, Item item, Pickup pickup = null, bool isScaling = true, bool isScaleInstant = true) (iterator) | Coroutine that moves a transform smoothly to its docked position, rotation and scale. Stops if it gets undocked meanwhile. |
override void OnConnected(Player player) | Server: sends the stored count to a player who just loaded the dock. |
void OnQuantityChanged() | Updates the contents colliders and count text, raises QuantityChanged, and on the server syncs the count to the chunk. |
void TriggerHaptic(Controller controller) | Client: plays the pass-through haptic on a controller, unless toggle-holding haptics are off. |
void TriggerHoverHaptic(Controller controller) | Client: plays the hover haptic on a controller if the settings have one. |
Pickup UndockAll(Interactor interactor = null, Transform target = null) | Takes everything out. One item comes out as itself; on the server more than one is moved into a new pouch, which is returned. |
void UndockAllUnityEvent() | UndockAll with no arguments, for wiring from Unity events. |
bool UndockMaximum(out Pickup pickup, int max = 2147483647) | Takes out as much as one stack allows (up to the given max) via UndockQuantity. |
bool UndockQuantity(int quantity, out Pickup pickup) | Takes out that many. One comes out as the docked pickup itself; more are moved into a new pouch. |
void UndockTo(Transform target) | Server: undocks everything to the given transform and forces a position sync. |
bool UndockUnlimitedPouches(int quantity, out List<Pickup> pickups) | Splits that quantity into as many pickups or pouches as needed, one stack each. False if there isn't enough. |
void UpdateChangedContent() | Re-places the docked pickup, refreshes the count text and raises UpdateContent. |
void UpdateQuantityStoredText() | Client: refreshes the count shown on the dock, hiding it for empty, non-stackable or unique crafted items. |
protected virtual void Awake() | Clears a stored count that has no item, sets up the hover scale animation and turns off the pickup range collider on a headless server. |
protected override void OnValidate() | Defaults the snap point to the dock's own transform. |
34 private and internal methods
| Member | What it is |
|---|---|
private void AddSoundListeners() | Client: hooks the dock, undock and hover sounds to this dock's events. |
private void IBuildRendererBakeable.Bake(bool isSaving) | Build step that makes the dock not interactable until something docks into it. |
private void ChangePickupsSaveMode(Pickup pickup, bool isSavingNormaly) | Sets a pickup's prefab save mode to Child while docked, or back to its base save mode when undocked. |
private static Quaternion CheckCraftingFlip(Pickup pickup, Quaternion rotation) | Turns a crafted, non-stackable item 180 degrees in the dock if its crafting part says it is stored flipped. |
private void IBuildRendererBakeable.Clean() | Explicit IBuildRendererBakeable build step. Does nothing. |
private void CleanDestroy() | Removes the sound listeners and stops watching the parent entity's destruction. |
private void CleanupDocked(NetworkEntity parent, bool isUnload) | Server: destroys the docked pickup when the dock's parent entity is destroyed by the scene. |
private void CreateNewImage(Pickup takenOutPickup) | Server: after the shown item is taken out of a stack, spawns a copy from the saved data and docks it as the new shown item. |
private void IDockable.Dock(Interactor interactor, Pickup pickup, int dockingQuantity, bool isInstantMovementForced) | Explicit IDockable dock: parents the pickup to the snap point, moves it into place and adds the quantity (server) or tracks it (client). |
private void DockedDestroyed(NetworkEntity entity, bool isUnload) | Undocks everything when the docked pickup is destroyed for a reason other than unloading. |
private void DockHoverSound(PickupDock dock, int oldCount) | Client: plays the hover sound when the first hand starts hovering, if the settings allow it. |
private void GenerateSerializedData(Pickup takenOutPickup) | Server: saves the docked pickup's state so CreateNewImage can spawn identical copies of it. |
private void IInitializeAsLocalPlayer.InitializeAsLocalPlayer(PlayerController playerController) | Marks this dock as owned by the local player's controller. |
private void IInitializeAsRemotePlayer.InitializeAsRemotePlayer(PlayerController playerController) | Marks this dock as owned by a remote player's controller (also used on the server). |
private void ItemDockedSound(Interactor interactor, Pickup pickup, PickupDock dock) | Client: plays the dock added-to sound if the settings allow it. |
private void ItemUnDockedSound(Interactor interactor, Pickup pickup, PickupDock dock) | Client: plays the dock removed-from sound if the settings allow it. |
private void LoadDockPickup(NetworkPrefab pickupPrefab, NetworkEntity parent, int childIndex) | Server load: initialises a saved child pickup and docks it, clamping the quantity to 1 if the item can't stack. |
private void Alta.Chunks.ISavableFull.LoadSetup() | Server load: if the dock should hold items but has none, docks a matching child pickup or spawns a new one of the saved type. |
private void MoveToDockInstant(Pickup pickup, bool isScaling) | Puts the pickup at its dock position, rotation and scale straight away. |
private void OnDestroy() | Undocks a leftover pickup if the dock was empty and cleans up listeners when destroyed outside entity destruction. |
private void OnDisable() | Stops the hover scale animation. |
private void OnDocked(Interactor interactor, Pickup pickup) | After docking: switches the pickup to child save mode, watches it for destruction and raises ItemDocked and WeightChanged. |
private void OnUndocked(Interactor interactor, Pickup pickup) | After undocking: restores the pickup's save mode, stops watching it and raises ItemUndocked and WeightChanged. |
private void OnWeightChanged() | Raises WeightChanged. Hooked to the docked pickup's own weight changes. |
private void RemoveSoundListeners() | Unhooks the dock sound handlers. |
private void SceneDestroy(NetworkEntity entity, bool isUnload) | Cleans up listeners when the dock's entity is destroyed by the scene. |
private void SerializeQuantity(IPlayer player, Stream stream) | Synced message with the stored quantity; clients apply it through QuantityStored. |
private void SoundHookInitializeDelay() | Client: adds the sound listeners half a second after initialising, so loading docks stay quiet. |
private void SubDockedEvent(Interactor interactor, Pickup pickup, PickupDock pickupDock) | Raises OnSubDocked when something docks into a dock on the item this dock belongs to. |
private void SubUndockedEvent(Interactor interactor, Pickup pickup, PickupDock pickupDock) | Raises OnSubUndocked when something undocks from a dock on the item this dock belongs to. |
private void IDockable.Undock(Interactor interactor, Pickup pickup, int quantity) | Explicit IDockable undock: frees the pickup, lowers the quantity and on the server docks a fresh copy if any remain. |
private void UpdatePlayerOwnership(PlayerController playerController) | Sets the owning player controller, marks the dock as player owned and raises UpdatedPlayerOwnership. |
private IEnumerator UpdateQuantity() (iterator) | Coroutine run on quantity change: the server sends the quantity to chunks, clients recount predicted items, then the count text updates. |
private IEnumerator WaitForAnimation() (iterator) | Coroutine that blocks hover haptics until the pass-through haptic curve has finished. |
Used in
Members of other types that take, return or hold a PickupDock:
Recycler.fueldDock, RecyclerOutputSlot.displayDock, RecyclerOutputSlot.targetDock, Smelter.CheckSmelt, Smelter.CheckSpriteZero, Smelter.fuelDocks, Smelter.MouldAdded, Smelter.mouldDock, Smelter.MouldRemoved, Smelter.oreDocks, BuilderDock.dock, RecipePlacer.AddDefinition, RecipePlacer.ClearDefinition, RecipePlacer.pageDock, CaveTeleporter.fuelDock, DockedDissolver.DissolveItem, DockedDissolver.targetDock, DockStore.DockStore, DockStore.Source, Inventory.BackDock, Inventory.LeftBeltDock, Inventory.LeftHipDock, Inventory.RightBeltDock, Inventory.RightHipDock, AdditionalOwnedDock.DeregisterDock, AdditionalOwnedDock.RegisterDock, AdditionalOwnedDock.UpdateOwnership, DisableLightOnDock.CheckEnabledEnable, DisableLightOnDock.ForceEnable, GenericAssemblyStation.dock, GenericAssemblyStation.InsertPiece, GenericAssemblyStation.RemovePiece, GenericCraftingStation.DockingFilter, GenericCraftingStation.OnPageDocked, GenericCraftingStation.OnPageUndocked, GenericCraftingStation.recipeDock, MainMenuShopInterface.depositDock, MainMenuShopInterface.DestroyDocked, MainMenuShopInterface.withdrawDock, MainMenuShopItem.depositDock, QuickDrawApplication.Charge, Fire.AllowLighting, Fire.CheckExtinguish, Fire.fuelDock, Fire.StopExtinguish, Fire.Subdocked, EmbeddableManager.HandleDock, ImpactTool.UndockWakeUp, PickupAgent.DockedChanged, AbstractDockEvents.dock, AbstractDockEvents.ItemDocked, AbstractDockEvents.ItemUndocked, AutomaticDockArea.docks, AutomaticDockArea.Docks, BoundsDockPositioning.dock, BoundsDockPositioning.Position, CommunalStorage.filterDock, CommunalStorage.internalDock, CommunalStorage.Refund, CraftedDocks.DisableDocks and 215 more.