示例#1
0
        static public void _DebugRays([ReadOnly] ref NativeArray <Entity> na_collisionChecksEntities, [ReadOnly] ref ComponentDataFromEntity <RayData> a_rayData, [ReadOnly] ref ComponentDataFromEntity <RayMaxDistanceData> a_rayMaxDistanceData, [ReadOnly] ref ComponentDataFromEntity <IsCollidingData> a_isCollidingData, [ReadOnly] ref ComponentDataFromEntity <RayEntityPair4CollisionData> a_rayEntityPair4CollisionData, bool canDebugAllChecks, bool canDebugAllrays)
        {
            // Debug all, or only one check
            int i_debugCollisionChecksCount = canDebugAllChecks ? na_collisionChecksEntities.Length : 1;


            // Debug
            // ! Ensure test this only with single, or at most few ray entiities.
            for (int i_collisionChecksIndex = 0; i_collisionChecksIndex < i_debugCollisionChecksCount; i_collisionChecksIndex++)
            {
                Entity octreeRayEntity = na_collisionChecksEntities [i_collisionChecksIndex];
                Entity octreeRayEntity2;

                if (!a_rayData.Exists(octreeRayEntity))
                {
                    RayEntityPair4CollisionData rayEntityPair4CollisionData = a_rayEntityPair4CollisionData [octreeRayEntity];
                    octreeRayEntity2 = rayEntityPair4CollisionData.ray2CheckEntity;
                }
                else
                {
                    octreeRayEntity2 = octreeRayEntity;
                }

                // Draw all available rays, or signle ray
                if (canDebugAllrays)
                {
                    RayData            rayData            = a_rayData [octreeRayEntity2];
                    RayMaxDistanceData rayMaxDistanceData = a_rayMaxDistanceData [octreeRayEntity2];

                    Debug.DrawLine(rayData.ray.origin, rayData.ray.origin + rayData.ray.direction * rayMaxDistanceData.f, Color.red);
                }
                else if (i_collisionChecksIndex == 0)
                {
                    RayData            rayData            = a_rayData [octreeRayEntity2];
                    RayMaxDistanceData rayMaxDistanceData = a_rayMaxDistanceData [octreeRayEntity2];

                    Debug.DrawLine(rayData.ray.origin, rayData.ray.origin + rayData.ray.direction * rayMaxDistanceData.f, Color.red);
                }


                IsCollidingData isCollidingData = a_isCollidingData [octreeRayEntity];

                if (isCollidingData.i_collisionsCount > 0)
                {
                    Debug.Log("Is colliding.");
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="na_collisionChecksEntities"></param>
        /// <param name="a_rayData"></param>
        /// <param name="a_rayMaxDistanceData"></param>
        /// <param name="a_isCollidingData"></param>
        /// <param name="collisionInstancesBufferElement"></param>
        /// <param name="canDebugAllChecks">Debug Log all checks, or only one (first one)</param>
        /// <param name="canDebugAllrays">Draw all, or only single ray (first one).</param>
        static public void _DebugRays(ref EntityCommandBuffer ecb, [ReadOnly] ref NativeArray <Entity> na_collisionChecksEntities, [ReadOnly] ref ComponentDataFromEntity <RayData> a_rayData, [ReadOnly] ref ComponentDataFromEntity <RayMaxDistanceData> a_rayMaxDistanceData, [ReadOnly] ref ComponentDataFromEntity <IsCollidingData> a_isCollidingData, [ReadOnly] ref BufferFromEntity <CollisionInstancesBufferElement> collisionInstancesBufferElement, [ReadOnly] ref ComponentDataFromEntity <RayEntityPair4CollisionData> a_rayEntityPair4CollisionData, bool canDebugAllChecks, bool canDebugAllrays)
        {
            // Debug
            // ! Ensure test this only with single, or at most few ray entiities.


            // if ( !canDebugAllrays )

            // Debug all, or only one check
            int i_debugCollisionChecksCount = canDebugAllChecks ? na_collisionChecksEntities.Length : 1;

            for (int i_collisionChecksIndex = 0; i_collisionChecksIndex < i_debugCollisionChecksCount; i_collisionChecksIndex++)
            {
                Entity octreeRayEntity = na_collisionChecksEntities [i_collisionChecksIndex];
                Entity octreeRayEntity2;

                if (!a_rayData.Exists(octreeRayEntity))
                {
                    RayEntityPair4CollisionData rayEntityPair4CollisionData = a_rayEntityPair4CollisionData [octreeRayEntity];
                    octreeRayEntity2 = rayEntityPair4CollisionData.ray2CheckEntity;
                }
                else
                {
                    octreeRayEntity2 = octreeRayEntity;
                }

                // Draw all available rays, or signle ray
                if (canDebugAllrays)
                {
                    RayData            rayData            = a_rayData [octreeRayEntity2];
                    RayMaxDistanceData rayMaxDistanceData = a_rayMaxDistanceData [octreeRayEntity2];

                    Debug.DrawLine(rayData.ray.origin, rayData.ray.origin + rayData.ray.direction * rayMaxDistanceData.f, Color.red);
                }
                else if (i_collisionChecksIndex == 0)
                {
                    RayData            rayData            = a_rayData [octreeRayEntity2];
                    RayMaxDistanceData rayMaxDistanceData = a_rayMaxDistanceData [octreeRayEntity2];

                    Debug.DrawLine(rayData.ray.origin, rayData.ray.origin + rayData.ray.direction * rayMaxDistanceData.f, Color.red);
                }
                //}


                // Last known instances collisions count.
                IsCollidingData isCollidingData = a_isCollidingData [octreeRayEntity];

                if (isCollidingData.i_collisionsCount > 0)
                {
                    // Debug.Log ( "Octree: Last known instances collisions count #" + isCollidingData.i_collisionsCount ) ;

                    // Stores reference to detected colliding instance.
                    DynamicBuffer <CollisionInstancesBufferElement> a_collisionInstancesBuffer = collisionInstancesBufferElement [octreeRayEntity];


                    string s_collidingIDs = "";

                    CollisionInstancesBufferElement collisionInstancesBuffer;

                    for (int i = 0; i < isCollidingData.i_collisionsCount; i++)
                    {
                        collisionInstancesBuffer = a_collisionInstancesBuffer [i];
                        s_collidingIDs          += collisionInstancesBuffer.i_ID + ", ";
                    }

                    CollisionInstancesBufferElement closestCollisionInstance = a_collisionInstancesBuffer [isCollidingData.i_nearestInstanceCollisionIndex];
                    Entity closestInstanceEntity = new Entity()
                    {
                        Index   = closestCollisionInstance.i_ID,
                        Version = closestCollisionInstance.i_version
                    };

                    // Test highlight
                    Highlight.SwitchMethods._Switch(ref ecb, closestInstanceEntity);

//                    Debug.Log ( "Is colliding with #" + isCollidingData.i_collisionsCount + " instances of IDs: " + s_collidingIDs + "; Nearest collided instance is at " + isCollidingData.f_nearestDistance + "m, with ID #" + a_collisionInstancesBuffer [isCollidingData.i_nearestInstanceCollisionIndex].i_ID ) ;
                }
            } // for
        }