Skip to main content

PositionRestrictor

A class in Root.Township, Alta.Pages.

Server component that keeps pickups near a spot, such as tutorial items or moulds. Loose items outside the radius (or box) snap back or re-dock; held items outside it buzz, then snap back after a time.

Constructors​

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

Fields​

27 private and internal fields
MemberWhat it is
private ParticleSystem appearEffectChild particle system played where a reset pickup reappears, when no pooled effect is set.
private PooledObjectDefinition appearPooledEffectPooled effect played at both the old and new spot on reset. Takes priority over the particle systems.
private Vector3 autoJumpBackBoundSizeBox size (in the spawn location's local space) past which a loose pickup gets the haptic warning, in bounds mode.
private float autoJumpBackRadiusRadius past which even a loose pickup gets the haptic warning before reset, in radius mode.
private Vector3 boundSizeBox size (in the spawn location's local space) outside which a loose pickup is reset, in bounds mode.
private ParticleSystem disappearEffectChild particle system played where a pickup was before it reset.
private HashSet<PickupDock> docksAll docks of the registered dock groups. Tracked pickups may only dock into these.
private NetworkEntity[] entitiesToRestrictEntities to register when restrictSpecificEntities is on, instead of all children.
private HashSet<NetworkEntity> groupsServer: entities with a PickupDockGroup registered so far.
private Dictionary<uint, float> hapticStartedServer: when each pickup's haptic warning began, by entity id.
private float hapticStrengthStrength of the haptic pulse added to a pickup that's out of range.
private float heldLimitSeconds a pickup can stay out of range with the haptic warning before it resets.
private bool isRecursivelyAddingChildrenWhether children of children are registered too.
private bool isUsingBoundsUses boxes (boundSize) instead of radii to decide when to reset.
private bool isUsingDocksWhether child pickups and dock groups are registered at all, and resets try to dock pickups.
private bool isUsingLastDockWhether a reset tries the pickup's last dock first.
private Dictionary<uint, PickupDock> lastDocksServer: the dock each pickup last left, by entity id.
private float radiusBacking field for Radius: distance from the spawn location past which a loose pickup is reset. Saved.
private MethodSyncStruct<PositionRestrictor.SyncArgs> resetLocationNetwork sync that sends a reset (pickup, whether it docked, old position) to clients.
private TransformSave resetLocationSaveSaved transform of spawnLocation, loaded onto pickups that reset without docking.
private bool restrictSpecificEntitiesRegisters only entitiesToRestrict rather than every child.
private MethodSyncStruct<PositionRestrictor.SyncArgs> setHapticNetwork sync that turns the haptic warning on or off for a pickup on clients.
private Transform spawnLocationCentre of the area and where undocked pickups are put back.
private MethodSyncStruct<PositionRestrictor.SyncArgs> syncItemNetwork sync for one pickup or dock group being registered or deregistered.
private MethodSync syncItemsNetwork sync that sends the full tracked list to a player on connect.
private HashSet<Pickup> trackingServer: the pickups being kept in the area.
private IUnityUpdateMethod updateThe budgeted update method (CheckBounds or CheckDistances) while at least one pickup is tracked.

Properties​

MemberWhat it is
float Radius { get; }How far a loose item may go from the spawn spot before it's returned.

Methods​

MemberWhat it is
void ClientDeregister(Pickup pickup)Client: undoes ClientRegister.
void ClientDeregister(PickupDockGroup dockGroup)Client: undoes ClientRegister.
void ClientRegister(Pickup pickup)Client: limits where a tracked pickup may dock, or adds a dock group's docks to the allowed list.
void ClientRegister(PickupDockGroup dockGroup)Client: limits where a tracked pickup may dock, or adds a dock group's docks to the allowed list.
virtual void Deregister(Pickup pickup)Server: stops tracking a pickup and makes it a normal saved entity again.
void ForceReset()Returns every tracked pickup straight away.
override void Initialize()Remembers the reset spot and creates the syncs.
override void InitializeAsServer(SpawnData spawnData)Server: starts tracking child entities (or a chosen list) and their docks, if docks are used.
override void OnConnected(Player player)Sends the tracked items to a joining player.
virtual void Register(Pickup pickup)Server: starts tracking a pickup. It becomes a saved child of this entity and is checked each budgeted update.
protected void ResetLocation(Pickup pickup, Vector3 position, bool isPlayingEffect, bool isDocking)Drops a pickup and, on the server, docks it back or moves it to the reset spot, with effects.
20 private and internal methods
MemberWhat it is
private bool AttemptDock(Pickup pickup)Server: tries to dock a reset pickup into its last recorded dock, then into any tracked dock. Returns false when docks are off.
private void CheckBounds()Server update used when isUsingBounds is on: checks each tracked pickup against the box sizes and resets or warns it.
private void CheckDestroy(NetworkEntity entity, bool isUnload)When the entity is destroyed (not unloaded), deregisters every tracked pickup.
private void CheckDistances()Server update used for the radius mode: resets loose pickups outside radius, and held ones after heldLimit seconds of haptic warning.
private void ChildAdded(NetworkEntity entity)Server: registers a new child's dock group and pickup and sets its save mode to child. Recurses when isRecursivelyAddingChildren is on.
private void ChildRemoved(NetworkEntity entity)Logs an error when a child with a PickupDockGroup is removed. Nothing else.
private void Deregister(NetworkEntity groupEntity, PickupDockGroup group)Server: stops tracking a pickup and makes it a normal saved entity again.
private void DisableHaptic(Interactor interactor, Pickup pickup, PickupDock dock)Server: on dock, stops the haptic warning for that pickup and tells clients.
private void ItemDocked(Interactor interactor, Pickup pickup, PickupDock dock)Registers any pickup docked into one of the tracked docks.
private void LimitDocks(Interactor interactor, PickupDock dock, ref bool result)Dock filter that blocks docking a tracked pickup into any dock outside this restrictor's dock groups.
private void OnDestroy()Removes the update method.
private void OnDrawGizmosSelected()Draws the reset area (red) and auto jump back area (green) as spheres or boxes.
private void PickupDestroyed(NetworkEntity entity, bool isUnload)Deregisters a tracked pickup when its entity is destroyed.
private void RecordDock(Interactor interactor, Pickup pickup, PickupDock dock)On undock, remembers the dock the pickup came from when isUsingLastDock is on, so a reset can put it back.
private void Register(NetworkEntity groupEntity, PickupDockGroup group)Server: starts tracking a pickup. It becomes a saved child of this entity and is checked each budgeted update.
private void ResetSync(IPlayer player, Stream stream, PositionRestrictor.SyncArgs args)Network handler for the reset message. Clients run the reset (with effect) for the given pickup and position.
private void SetHaptic(IPlayer player, Stream stream, PositionRestrictor.SyncArgs args)Network handler that adds or removes a HapticWhileHeld on the pickup, using hapticStrength.
private void StopHaptic(Interactor interactor, Pickup pickup, PickupDock dock)Client: removes the HapticWhileHeld component when the pickup docks.
private void SyncItem(IPlayer player, Stream stream, PositionRestrictor.SyncArgs args)Network handler for one registered or deregistered pickup or dock group. Clients add or remove the dock filter for it.
private void SyncItems(IPlayer player, Stream stream)Sends every tracked dock group and pickup to a joining player so the client can register them.