/// <summary> /// Returns a <see cref="CollisionNotifier"/> collection for the given <see cref="CollisionEventData"/> containing <see cref="Transform"/>. /// </summary> /// <param name="data">The <see cref="CollisionEventData"/> that holds the containing <see cref="Transform"/></param> /// <returns>A <see cref="CollisionNotifier"/> collection for items found on the containing <see cref="Transform"/> component.</returns> protected virtual List <CollisionNotifierNew> GetNotifiers(CollisionEventData data, List <CollisionNotifierNew> collisionNotifiers) { Transform reference = data.ColliderData.GetContainingTransform(); if (transform.IsChildOf(reference)) { collisionNotifiers.Clear(); } else { reference.GetComponentsInChildren(collisionNotifiers); } return(collisionNotifiers); }
/// <summary> /// Processes any collision stop events on the given data and propagates it to any linked <see cref="CollisionNotifier"/>. /// </summary> /// <param name="data">The collision data.</param> protected virtual void OnCollisionStopped(CollisionEventData data) { if ((StatesToProcess & CollisionStates.Exit) == 0 || !CanEmit(data)) { return; } CollisionStopped?.Invoke(data); if (isProcessingStopNotifierCollection) { return; } isProcessingStopNotifierCollection = true; foreach (CollisionNotifierNew notifier in GetNotifiers(data, stopCollisionNotifiers)) { notifier.OnCollisionStopped(data); } isProcessingStopNotifierCollection = false; }
/// <summary> /// Determines whether events should be emitted. /// </summary> /// <param name="data">The data to check.</param> /// <returns><see langword="true"/> if events should be emitted.</returns> protected virtual bool CanEmit(CollisionEventData data) { return((data.IsTrigger && (EmittedTypes & CollisionTypes.Trigger) != 0 || !data.IsTrigger && (EmittedTypes & CollisionTypes.Collision) != 0) && (data.ForwardSource == null || true /*ForwardingSourceValidity.Accepts(data.ForwardSource.gameObject)*/)); //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Validity }