Skip to main content

PullPickupGroup

A class in Root.Township, the global namespace.

A group of pickups parented to one holder that players pull off one at a time by grabbing and drawing the hand away (used by PotatoSapling). Both sides; the server decides when a pull succeeds and syncs adds and removes.

Constructors​

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

Fields​

17 private and internal fields
MemberWhat it is
private Transform cachedTransformThe group's transform, cached in Initialize. Grouped pickups are parented to it.
private float directionWeighting0 to 1. How much the pull is measured along pullDirection rather than wherever the hand moves.
private float hapticStrengthStrength of the hand vibration while pulling, scaled by how close the pull is to done.
private Interactable interactableThe interactable on this object that grouped pickups forward their grabs to.
private Dictionary<Pickup, Interactor> interactorsWhich hand is holding each grouped pickup, so Remove can hand it over.
private bool isAddingWhether the next SyncAdd is an add (true) or a remove.
private Interactor nextInteractionThe last remote hand that started an interaction, waiting for SyncSelection to say which pickup.
private uint nextSelectionIdentifier of the pickup to send or just received in SyncSelection (0 for none).
private uint nextSpawnIdentifier of the pickup to send or just received in SyncAdd.
private Pickup pickupOptional parent pickup found on the prefab root. When set, grabs only work while the other hand holds it.
private List<Pickup> pickupsThe pickups currently in the group.
private Dictionary<Interactor, Coroutine> pullCoroutinesRunning CheckPull coroutine for each hand.
private Vector3 pullDirectionLocal direction the hand has to move to pull a pickup off. Defaults to up.
private float pullDistanceHow far (minimum 0.05) the hand must move along the pull direction before the server removes the pickup.
private MethodSync syncAddMessage (SyncA) for SyncAdd.
private MethodSync syncAddAllMessage (SyncB) for SyncAddAll.
private MethodSync syncSelectionMessage (SyncC) for SyncSelection.

Properties​

MemberWhat it is
int Count { get; }Number of pickups still in the group.

Events​

MemberWhat it is
event Action<Pickup> OnPulledFires with the pickup each time one leaves the group, on both sides.

Methods​

MemberWhat it is
void Add(Pickup child)Parents a pickup to the group, makes it kinematic and forwards its grabs here. On the server also saves it as a child and syncs the add.
override void Initialize()Sets up the three sync messages and hooks the interactable's start and end events.
override void OnConnected(Player player)Resends the full pickup list. Note it sends to all chunks, not only the new player.
void Remove(Pickup child)Unparents a pickup, turns its physics back on and fires OnPulled. On the server syncs it and hands it to the pulling hand.
void RemoveRandom()Server: removes one pickup at random, if any are left.
8 private and internal methods
MemberWhat it is
private IEnumerator CheckPull(Interactor interactor, Pickup pickup) (iterator)Coroutine while a hand holds a grouped pickup: slides it along the pull direction with haptics. Server removes it past pullDistance.
private void IfHeld(Interactor interactor, Interactable interactable, ref bool result)Interaction filter, set when pickup is set: only allows a grab if the other hand is holding that pickup.
private void InteractionEnded(Interactable interactable, Interactor interactor)Stops the pull coroutine for that hand and detaches the hand from the pickup.
private void InteractionStarted(Interactable interactable, Interactor interactor)On the local hand, sends which pickup was grabbed and starts the pull. For remote hands, waits for SyncSelection.
private void SyncAdd(IPlayer player, Stream stream)Sends one pickup identifier and whether it was added or removed. Remote clients apply it.
private void SyncAddAll(IPlayer player, Stream stream)Sends every grouped pickup identifier (count in 8 bits, so at most 255). Remote clients add them all.
private void SyncSelection(IPlayer player, Stream stream)Sends which pickup a hand grabbed. The server relays it to the others, who start the grab for that remote hand.
private void TryGrab(Interactor interactor, Pickup pickup)Puts the pickup in the hand without a joint and starts CheckPull for that hand.

Used in​

Members of other types that take, return or hold a PullPickupGroup: