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.
- Listed in Global namespace: T to X
- Inherits or implements
MonoBehaviour - Derived types
EffectVolumeTrigger,LocomotionModifierVolumeTrigger,MovingPlatform
Constructors
| Member | What it is |
|---|---|
protected VolumeTrigger() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
| Member | What it is |
|---|---|
protected readonly List<EffectHandler> ActiveEffectTargets | Effect handlers a subclass has applied effects to. EffectHandlerLeft is called on each when the volume is disabled. |
6 private and internal fields
| Member | What it is |
|---|---|
private readonly HashSet<Collider> colliders | Colliders inside the trigger right now. |
private MemoizeHashsetCountTracker<Rigidbody, EffectHandler> effectHandlers | Counts effect handlers in the volume so each enters and leaves once. Made on first use. |
private MemoizeHashsetCountTracker<Rigidbody, Pickup> pickups | Counts pickups in the volume so each enters and leaves once. Made on first use. |
private MemoizeHashsetCountTracker<Collider, SmoothLocomotionPlayerController> players | Counts players by collider, so a player enters and leaves once. Made on first use. |
private MemoizeHashsetCountTracker<Collider, Rigidbody> rigidbodies | Counts colliders per rigidbody, so a body with several colliders enters and leaves once. |
private static readonly List<Collider> staticTempRemovalList | Shared scratch list for removing disabled colliders in OnTriggerExit. |
Properties
Methods
| Member | What 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
| Member | What 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. |