public virtual void OnDisable() { foreach (Collider entry in exiting) { if (!entry) { continue; } Rigidbody r = entry.attachedRigidbody; if (!r) { continue; } OnRigidbodyTriggerExit?.Invoke(r); } Overlapping.Clear(); }
protected virtual void FixedUpdate() { if (!isSimulating || !SimPhysics) { entering.Clear(); staying.Clear(); exiting.Clear(); Overlapping.Clear(); return; } HashSet <Rigidbody> enteringBodies = new HashSet <Rigidbody>(); foreach (Collider entry in entering) { if (!entry) { continue; } Rigidbody r = entry.attachedRigidbody; if (!r || enteringBodies.Contains(r)) { continue; } enteringBodies.Add(r); if (!Overlapping.Contains(r)) { Overlapping.Add(r); } OnRigidbodyTriggerEnter?.Invoke(r); } HashSet <Rigidbody> stayingBodies = new HashSet <Rigidbody>(); foreach (Collider entry in staying) { if (!entry) { continue; } Rigidbody r = entry.attachedRigidbody; if (!r || stayingBodies.Contains(r)) { continue; } stayingBodies.Add(r); if (!Overlapping.Contains(r)) { Overlapping.Add(r); } OnRigidbodyTriggerStay?.Invoke(r); } HashSet <Rigidbody> exitingBodies = new HashSet <Rigidbody>(); foreach (Collider entry in exiting) { if (!entry) { continue; } Rigidbody r = entry.attachedRigidbody; if (!r || exitingBodies.Contains(r) || enteringBodies.Contains(r) || stayingBodies.Contains(r)) { continue; } exitingBodies.Add(r); if (Overlapping.Contains(r)) { Overlapping.Remove(r); } OnRigidbodyTriggerExit?.Invoke(r); } entering.Clear(); staying.Clear(); exiting.Clear(); }