Skip to main content

ActionItemHandler

A class in Root.Township, Alta.QuickAccessActions.

Tracks one quick-access action item spawned for a player: fades it in and out, and despawns it when the player walks away, leaves or the item lands in the global chunk.

Constructors​

MemberWhat it is
ActionItemHandler(IPlayer player, int itemIndex, ActionItemData data, Action<int, IPlayer> destroyItem)Creates an ActionItemHandler from player, itemIndex, data and destroyItem.

Fields​

8 private and internal fields
MemberWhat it is
private readonly Action<int, IPlayer> destroyItemCallback that destroys the item, given its index and player.
private ActionItem ItemThe spawned action item, or null before it spawns.
private readonly int ItemIndexIndex of this item in the action item list, passed back to the destroy callback.
private readonly float maxDistanceSquaredSquared distance from the head beyond which the despawn timer runs.
private readonly float outOfRangeHapticHaptic strength used while the item is out of range.
private float timerSeconds left before an out-of-range item is destroyed; reset while in range.
private readonly float timeToDespawnSeconds the item may stay out of range before it is destroyed.
private IUnityUpdateMethod updateDistanceHandle for the registered late-update distance check.

Properties​

MemberWhat it is
bool ItemIsActive { get; }True while an item is attached.
Vector3 ItemPosition { get; }The item's world position, or zero when there is no item.
1 private and internal property
MemberWhat it is
private IPlayer Player { get; }The player the item belongs to.

Methods​

MemberWhat it is
void Dispose()Fades the item out and stops the distance check. Note it unhooks PlayerDestroyed from the item rather than ItemDestroyed.
void SetupSpawnedActionItem(ActionItem item)Attaches a freshly spawned item, hooks its destroy and chunk events, and fades it in. Starts the distance check for the local player.
4 private and internal methods
MemberWhat it is
private void ItemDestroyed(NetworkEntity _, bool __)When the item entity is destroyed, calls Dispose.
private void OnAddedToChunk(Chunk chunk)Destroys the item if it is moved into the global chunk.
private void PlayerDestroyed(NetworkEntity entity, bool isUnload)Destroys the item when the owning player's entity is destroyed.
private void UpdateDistance()Client: each late update, buzzes both controllers while the item is too far from the head and destroys it once the timer runs out.

Used in​

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