CollisionCheck.Box_Box(UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Quaternion, UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Quaternion)

Here are the examples of the csharp api CollisionCheck.Box_Box(UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Quaternion, UnityEngine.Vector3, UnityEngine.Vector3, UnityEngine.Quaternion) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

19 View Source File : CollisionCheck.cs
License : Apache License 2.0
Project Creator : 365082218

public static int OverlapBox(Vector3 center, Vector3 halfExtents, Quaternion rotation, Collider[] colliderStorage, LayerMask killLayer) {
        var radius = new Vector3(halfExtents.x * 2.0f, halfExtents.y * 2.0f, halfExtents.z * 2.0f).magnitude;
        int numOverlaps = Physics.OverlapSphereNonAlloc(center, radius, sphere_cast_collider_storage, killLayer.value);
        int numBoxOverlaps = 0;
        for (int i = 0; i < numOverlaps; i++) {
            var nearbyCollider = sphere_cast_collider_storage[i];
            //Debug.Log("Testing against " + nearbyCollider.gameObject.name);
            var nearbyBoxCollider = nearbyCollider as BoxCollider;
            if (nearbyBoxCollider != null) {
                var nearbyColliderHalfExtents = nearbyBoxCollider != null ? HalfExtentsFromBoxCollider(nearbyBoxCollider) : nearbyCollider.transform.localScale * 0.5f;
                var nearbyColliderPosition = nearbyBoxCollider != null ? PositionFromCollider(nearbyBoxCollider) : nearbyCollider.transform.position;
                //Debug.Log("Position: " + nearbyCollider.transform.position);
                //Debug.Log("Rotation: " + nearbyCollider.transform.rotation);
                //Debug.Log("Half Extents: " + nearbyColliderHalfExtents);
                //Debug.Log("Has box: " + (nearbyBoxCollider != null).ToString());
                if (CollisionCheck.Box_Box(center, halfExtents, rotation, nearbyColliderPosition, nearbyColliderHalfExtents, nearbyCollider.transform.rotation)) {
                    colliderStorage[numBoxOverlaps++] = sphere_cast_collider_storage[i];
                }
            } else {
                var nearbyMeshCollider = nearbyCollider as MeshCollider;
                if (nearbyMeshCollider != null) {
                    //计算这个盒子的obb,转换为obb-obb的相交测试
                    Vector3 centerMesh = nearbyMeshCollider.transform.TransformPoint(nearbyMeshCollider.sharedMesh.bounds.center);
                    Vector3 halfMesh = Vector3.Scale(nearbyMeshCollider.sharedMesh.bounds.size, nearbyMeshCollider.transform.localScale) / 2;
                    if (CollisionCheck.Box_Box(center, halfExtents, rotation, centerMesh, halfMesh, nearbyCollider.transform.rotation)) {
                        colliderStorage[numBoxOverlaps++] = sphere_cast_collider_storage[i];
                    }
                }
            }
        }
        return numBoxOverlaps;
    }