namespace Zinnia.Extension { using System.Collections.Generic; using UnityEngine; /// /// Extended methods for the Type. /// public static class ColliderExtensions { /// /// Gets the of the container of the collider. /// /// The to check against. /// The container. public static Transform GetContainingTransform(this Collider collider) { if (collider == null) { return null; } Rigidbody attachedRigidbody = collider.GetAttachedRigidbody(); return attachedRigidbody == null ? collider.transform : attachedRigidbody.transform; } /// /// Gets the parent for the given even if the is disabled. /// /// The to check against. /// The parent . public static Rigidbody GetAttachedRigidbody(this Collider collider) { Rigidbody attachedRigidbody = collider.attachedRigidbody; if (!collider.gameObject.activeInHierarchy) { collider.GetComponentsInParent(true, foundRigidbodies); foreach (Rigidbody foundRigidbody in foundRigidbodies) { attachedRigidbody = foundRigidbody; break; } } return attachedRigidbody; } /// /// A collection to store found s in. /// private static List foundRigidbodies = new List(); } }