Class RegionMembership<T>
Pure, engine-free bookkeeping for which characters a Region considers "inside". Separates the two truths a region has to reconcile:
- Raw presence: what the underlying NetworkCollider has told us via Enter/Exit callbacks. This is updated on every callback, including during prediction reconcile replay and while a character is teleporting.
- Effective membership: characters for which the region has actually raised an Enter (and no Exit yet). Gameplay/visual triggers key off this set.
Callbacks that arrive while suppressed (reconciling or teleporting) update raw
presence only; Flush(Func<T, bool>, Func<T, bool>, Func<T, bool>, List<T>, List<T>) later diffs raw against effective and yields the
Enter/Exit decisions that were deferred, each exactly once. Because
Flush(Func<T, bool>, Func<T, bool>, Func<T, bool>, List<T>, List<T>) is a pure diff it also repairs any drift between the two sets
(e.g. a child region releasing a character back to its parent).
public sealed class RegionMembership<T> where T : class
Type Parameters
TCharacter key type. Must be a reference type with stable hash/equality.
- Inheritance
-
RegionMembership<T>
- Inherited Members
Properties
EffectiveCount
Number of characters for which an Enter has been raised and no Exit yet.
public int EffectiveCount { get; }
Property Value
RawCount
Number of characters the collider currently reports as overlapping.
public int RawCount { get; }
Property Value
Methods
Clear(Func<T, bool>, List<T>)
Empties effective membership and reports every character that must receive a final Exit. Raw presence is cleared as well. Use when the region is disabled or destroyed.
public void Clear(Func<T, bool> isDestroyed, List<T> exits)
Parameters
isDestroyedFunc<T, bool>Characters matching this predicate are dropped without an Exit.
exitsList<T>Receives characters to raise Exit for (appended).
Flush(Func<T, bool>, Func<T, bool>, Func<T, bool>, List<T>, List<T>)
Diffs raw presence against effective membership and reports the Enter/Exit events
that must be raised to bring them into agreement. Call once per non-reconciling tick.
Characters for which isSuppressed returns true (still teleporting)
are skipped and will be reconsidered on a later flush. Characters for which
isDestroyed returns true are forgotten silently.
public void Flush(Func<T, bool> isSuppressed, Func<T, bool> isDestroyed, Func<T, bool> canEnter, List<T> enters, List<T> exits)
Parameters
isSuppressedFunc<T, bool>Per-character defer predicate; null means never deferred.
isDestroyedFunc<T, bool>Per-character prune predicate; null means never pruned.
canEnterFunc<T, bool>Per-character predicate; false blocks an Enter (child owns the character). Null means always allowed.
entersList<T>Receives characters to raise Enter for (appended).
exitsList<T>Receives characters to raise Exit for (appended).
ForceExit(T)
Logically exits a character without touching raw presence. Used when a child region takes ownership of a character standing inside this (parent) region.
public bool ForceExit(T character)
Parameters
characterT
Returns
- bool
True when an Enter had previously fired, so the caller must raise the paired Exit. False when no Enter ever fired (unpaired exits are never produced).
Forget(T)
Forgets a character entirely (both sets) without producing events. Use for destroyed characters where there is nobody left to notify.
public void Forget(T character)
Parameters
characterT
IsInside(T)
True when an Enter has been raised for character and no Exit yet.
public bool IsInside(T character)
Parameters
characterT
Returns
IsRawInside(T)
True when the collider currently reports character overlapping.
public bool IsRawInside(T character)
Parameters
characterT
Returns
RecordEnter(T, bool, bool)
Records a collider Enter callback.
public bool RecordEnter(T character, bool suppressed, bool canEnter = true)
Parameters
characterTThe character that entered the collider.
suppressedboolTrue while reconciling or teleporting: record only, do not fire.
canEnterboolWhen false the character is physically inside but a child region owns it; raw presence is recorded but no Enter fires (the parent stays "exited").
Returns
- bool
True when the caller should raise an Enter now.
RecordExit(T, bool)
Records a collider Exit callback.
public bool RecordExit(T character, bool suppressed)
Parameters
characterTThe character that left the collider.
suppressedboolTrue while reconciling or teleporting: record only, do not fire.
Returns
- bool
True when the caller should raise an Exit now (an Enter had been raised earlier).
ShouldStay(T, bool)
Decides whether a collider Stay callback should be forwarded. Stay only fires for characters that are effectively inside and never while suppressed, so replay ticks produce no Stay events and a parent does not "stay" while a child owns the character.
public bool ShouldStay(T character, bool suppressed)
Parameters
characterTsuppressedbool
Returns
TryEnter(T, bool, bool)
Logically enters a character that is still physically inside (raw) but not effectively inside. Used when a child region releases a character back to this (parent) region.
public bool TryEnter(T character, bool suppressed, bool canEnter = true)
Parameters
Returns
- bool
True when the caller should raise an Enter now.