Skip to main content

VolumeTrigger

An abstract class in Root.Township, the global namespace.

Base for a trigger volume that tracks what is inside it: rigidbodies, players, pickups and effect handlers, each reported once on first enter and last leave. Subclasses turn on the kinds they need.

Constructors​

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

Fields​

MemberWhat it is
protected readonly List<EffectHandler> ActiveEffectTargetsEffect handlers a subclass has applied effects to. EffectHandlerLeft is called on each when the volume is disabled.
6 private and internal fields
MemberWhat it is
private readonly HashSet<Collider> collidersColliders inside the trigger right now.
private MemoizeHashsetCountTracker<Rigidbody, EffectHandler> effectHandlersCounts effect handlers in the volume so each enters and leaves once. Made on first use.
private MemoizeHashsetCountTracker<Rigidbody, Pickup> pickupsCounts pickups in the volume so each enters and leaves once. Made on first use.
private MemoizeHashsetCountTracker<Collider, SmoothLocomotionPlayerController> playersCounts players by collider, so a player enters and leaves once. Made on first use.
private MemoizeHashsetCountTracker<Collider, Rigidbody> rigidbodiesCounts colliders per rigidbody, so a body with several colliders enters and leaves once.
private static readonly List<Collider> staticTempRemovalListShared scratch list for removing disabled colliders in OnTriggerExit.

Properties​

MemberWhat it is
virtual bool IsCheckingForEffectHandler { get; }Override to true to track effect handlers. Also needs IsCheckingForRigidbody.
virtual bool IsCheckingForPickup { get; }Override to true to track pickups. Also needs IsCheckingForRigidbody.
virtual bool IsCheckingForPlayer { get; }Override to true to track players (by their character controller).
virtual bool IsCheckingForRigidbody { get; }Override to true to track rigidbodies. Pickup and effect handler tracking go through this.

Methods​

MemberWhat it is
protected virtual void EffectHandlerEntered(EffectHandler handler)Called when an effect handler's body first enters. Needs rigidbody and effect handler checking on.
protected virtual void EffectHandlerLeft(EffectHandler handler)Called when an effect handler's body leaves, or the volume is disabled.
protected virtual void OnDestroy()Clears everything tracked.
protected virtual void OnDisable()Clears everything tracked and calls the leave hooks.
protected virtual void PickupEntered(Pickup pickup)Called when a pickup first enters.
protected virtual void PickupLeft(Pickup pickup)Called when a pickup leaves.
protected virtual void PlayerEntered(SmoothLocomotionPlayerController player)Called when a player's character first enters.
protected virtual void PlayerLeft(SmoothLocomotionPlayerController player)Called when a player's character leaves.
protected virtual void RigidbodyEntered(Rigidbody rigidbody)Called when a rigidbody's first collider enters. The base passes it on to pickup and effect handler tracking.
protected virtual void RigidbodyLeft(Rigidbody rigidbody)Called when a rigidbody's last collider leaves.
9 private and internal methods
MemberWhat it is
private void Clear()Drops all tracked colliders, bodies, players, pickups and effect handlers and calls EffectHandlerLeft for each ActiveEffectTargets entry. Runs on disable and destroy.
private bool GetEffectHandler(Rigidbody rigidbody, out EffectHandler result)Finds a rigidbody's effect handler through its ImpactDetector health target.
private bool GetPlayer(Collider collider, out SmoothLocomotionPlayerController result)Maps a CharacterController collider with SmoothLocomotion to its player controller.
private bool GetRigidbody(Collider collider, out Rigidbody result)Maps a collider to its attached rigidbody.
private void OnTriggerEnter(Collider other)Tracks a new collider and, if the subclass asks, its rigidbody and player, firing the entered callbacks on first contact.
private void OnTriggerExit(Collider other)Stops tracking the collider. If it wasn't tracked, also drops any tracked colliders that have been disabled.
private bool RemoveInternal(Collider other)Removes a collider and its rigidbody and player counts. Returns false if it wasn't tracked.
private void TriggerEffectHandlerLeftOnAllActiveTargets()Calls EffectHandlerLeft for every entry in ActiveEffectTargets, then empties the list.
private bool TryGetPickup(Rigidbody rigidbody, out Pickup result)Gets the Pickup on a rigidbody.