Ejemplo n.º 1
0
    public static bool isObjectColliding(
        GameObject go,
        List <GameObject> ignoreGameObjects = null,
        float expandBy = 0.0f,
        bool useBoundingBoxInChecks = false
        )
    {
        if (ignoreGameObjects == null)
        {
            ignoreGameObjects = new List <GameObject>();
        }
        ignoreGameObjects.Add(go);
        HashSet <Collider> ignoreColliders = new HashSet <Collider>();

        foreach (GameObject toIgnoreGo in ignoreGameObjects)
        {
            foreach (Collider c in toIgnoreGo.GetComponentsInChildren <Collider>())
            {
                ignoreColliders.Add(c);
            }
        }

        int layerMask = 1 << 8 | 1 << 10;

        foreach (CapsuleCollider cc in go.GetComponentsInChildren <CapsuleCollider>())
        {
            foreach (Collider c in PhysicsExtensions.OverlapCapsule(cc, layerMask, QueryTriggerInteraction.Ignore, expandBy))
            {
                if (!ignoreColliders.Contains(c))
                {
                    return(true);
                }
            }
        }
        foreach (BoxCollider bc in go.GetComponentsInChildren <BoxCollider>())
        {
            if ("BoundingBox" == bc.gameObject.name && (!useBoundingBoxInChecks))
            {
                continue;
            }
            foreach (Collider c in PhysicsExtensions.OverlapBox(bc, layerMask, QueryTriggerInteraction.Ignore, expandBy))
            {
                if (!ignoreColliders.Contains(c))
                {
                    return(true);
                }
            }
        }
        foreach (SphereCollider sc in go.GetComponentsInChildren <SphereCollider>())
        {
            foreach (Collider c in PhysicsExtensions.OverlapSphere(sc, layerMask, QueryTriggerInteraction.Ignore, expandBy))
            {
                if (!ignoreColliders.Contains(c))
                {
                    return(true);
                }
            }
        }
        return(false);
    }
Ejemplo n.º 2
0
    public static Collider[] collidersObjectCollidingWith(GameObject go, List <GameObject> ignoreGameObjects = null, float expandBy = 0.0f)
    {
        if (ignoreGameObjects == null)
        {
            ignoreGameObjects = new List <GameObject>();
        }
        ignoreGameObjects.Add(go);
        HashSet <Collider> ignoreColliders = new HashSet <Collider>();

        foreach (GameObject toIgnoreGo in ignoreGameObjects)
        {
            foreach (Collider c in toIgnoreGo.GetComponentsInChildren <Collider>())
            {
                ignoreColliders.Add(c);
            }
        }

        HashSet <Collider> collidersSet = new HashSet <Collider>();
        int layerMask = 1 << 8 | 1 << 10;

        foreach (CapsuleCollider cc in go.GetComponentsInChildren <CapsuleCollider>())
        {
            foreach (Collider c in PhysicsExtensions.OverlapCapsule(cc, layerMask, QueryTriggerInteraction.Ignore, expandBy))
            {
                if (!ignoreColliders.Contains(c))
                {
                    collidersSet.Add(c);
                }
            }
        }
        foreach (BoxCollider bc in go.GetComponentsInChildren <BoxCollider>())
        {
            foreach (Collider c in PhysicsExtensions.OverlapBox(bc, layerMask, QueryTriggerInteraction.Ignore, expandBy))
            {
                if (!ignoreColliders.Contains(c))
                {
                    collidersSet.Add(c);
                }
            }
        }
        foreach (SphereCollider sc in go.GetComponentsInChildren <SphereCollider>())
        {
            foreach (Collider c in PhysicsExtensions.OverlapSphere(sc, layerMask, QueryTriggerInteraction.Ignore, expandBy))
            {
                if (!ignoreColliders.Contains(c))
                {
                    collidersSet.Add(c);
                }
            }
        }
        return(collidersSet.ToArray());
    }