/// <summary> /// Using list of registered pairs, removes any referencing given Collider. /// Can be given null, which will remove any pairs containing a null. /// </summary> private void UnregisterColliderPairs(Collider theCol) { for (int i = _colliderPairs.Count - 1; i >= 0; i--) { if (!ColliderPairContainsCollider(_colliderPairs[i], theCol)) { continue; } _colliderPairs.RemoveAt(i); } }
/// <summary> /// Adds theCol to the list of registered colliders and collider pairs. /// </summary> public void RegisterCollider(Collider theCol) { if (theCol == null) { return; } if (_colliders.Contains(theCol)) { return; } _colliders.Add(theCol); RegisterColliderPairs(theCol); }
/// <summary> /// Removes all instances of theCol from the list of registered colliders and collider pairs. /// </summary> public void UnregisterCollider(Collider theCol) { if (!_colliders.Contains(theCol)) { return; } for (int i = _colliders.Count - 1; i >= 0; i--) { if (_colliders[i] != theCol) { continue; } _colliders.RemoveAt(i); } UnregisterColliderPairs(theCol); }
//TODO: This way of doing things is memory inefficient. High complexity. /// <summary> /// Using list of registered colliders, registers new pairs. /// </summary> public void RegisterColliderPairs(Collider theCol) { if (theCol == null) { return; } for (int i = 0; i < _colliders.Count; i++) { if (_colliders[i] == null) { continue; } if (_colliders[i] == theCol) { continue; } _colliderPairs.Add(new Pair <Collider, Collider> (theCol, _colliders[i])); } }
/// <summary> /// Returns true if either Collider in the given pair matches the given Collider. /// </summary> private bool ColliderPairContainsCollider(Pair <Collider, Collider> thePair, Collider theCol) { return((theCol == thePair.v1) || (theCol == thePair.v2)); }