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.
- Listed in Items, inventory and logic
- Inherits or implements
NetworkEntityBehaviour,ISavable<PositionRestrictorSaveData>,ISavableSave<PositionRestrictorSaveData>,ISavableSaveBase - Derived types
BookRestrictor,MouldRestrictor,PositionRestrictorSaveData - Nested types
SyncArgs - Documented in Pages and books
Constructors
| Member | What it is |
|---|---|
PositionRestrictor() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
27 private and internal fields
| Member | What it is |
|---|---|
private ParticleSystem appearEffect | Child particle system played where a reset pickup reappears, when no pooled effect is set. |
private PooledObjectDefinition appearPooledEffect | Pooled effect played at both the old and new spot on reset. Takes priority over the particle systems. |
private Vector3 autoJumpBackBoundSize | Box size (in the spawn location's local space) past which a loose pickup gets the haptic warning, in bounds mode. |
private float autoJumpBackRadius | Radius past which even a loose pickup gets the haptic warning before reset, in radius mode. |
private Vector3 boundSize | Box size (in the spawn location's local space) outside which a loose pickup is reset, in bounds mode. |
private ParticleSystem disappearEffect | Child particle system played where a pickup was before it reset. |
private HashSet<PickupDock> docks | All docks of the registered dock groups. Tracked pickups may only dock into these. |
private NetworkEntity[] entitiesToRestrict | Entities to register when restrictSpecificEntities is on, instead of all children. |
private HashSet<NetworkEntity> groups | Server: entities with a PickupDockGroup registered so far. |
private Dictionary<uint, float> hapticStarted | Server: when each pickup's haptic warning began, by entity id. |
private float hapticStrength | Strength of the haptic pulse added to a pickup that's out of range. |
private float heldLimit | Seconds a pickup can stay out of range with the haptic warning before it resets. |
private bool isRecursivelyAddingChildren | Whether children of children are registered too. |
private bool isUsingBounds | Uses boxes (boundSize) instead of radii to decide when to reset. |
private bool isUsingDocks | Whether child pickups and dock groups are registered at all, and resets try to dock pickups. |
private bool isUsingLastDock | Whether a reset tries the pickup's last dock first. |
private Dictionary<uint, PickupDock> lastDocks | Server: the dock each pickup last left, by entity id. |
private float radius | Backing field for Radius: distance from the spawn location past which a loose pickup is reset. Saved. |
private MethodSyncStruct<PositionRestrictor.SyncArgs> resetLocation | Network sync that sends a reset (pickup, whether it docked, old position) to clients. |
private TransformSave resetLocationSave | Saved transform of spawnLocation, loaded onto pickups that reset without docking. |
private bool restrictSpecificEntities | Registers only entitiesToRestrict rather than every child. |
private MethodSyncStruct<PositionRestrictor.SyncArgs> setHaptic | Network sync that turns the haptic warning on or off for a pickup on clients. |
private Transform spawnLocation | Centre of the area and where undocked pickups are put back. |
private MethodSyncStruct<PositionRestrictor.SyncArgs> syncItem | Network sync for one pickup or dock group being registered or deregistered. |
private MethodSync syncItems | Network sync that sends the full tracked list to a player on connect. |
private HashSet<Pickup> tracking | Server: the pickups being kept in the area. |
private IUnityUpdateMethod update | The budgeted update method (CheckBounds or CheckDistances) while at least one pickup is tracked. |
Properties
| Member | What it is |
|---|---|
float Radius { get; } | How far a loose item may go from the spawn spot before it's returned. |
Methods
| Member | What 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
| Member | What 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. |