示例#1
0
        public void NeedForMinStepTest(bool shouldFail)
        {
            var maxHits           = 4;
            var rayStart          = new Vector3(0f, 4f, 0f);
            var meshConvexCommand = new RaycastCommand(meshConvexCollider.transform.position + rayStart, Vector3.down, 8f);

            var commandsArray = new RaycastCommand[] { meshConvexCommand };
            var commands      = new NativeArray <RaycastCommand>(commandsArray, Allocator.TempJob);
            var commandHits   = new NativeArray <RaycastHit>(commands.Length * maxHits, Allocator.TempJob);

            //setting minStep to 0f
            var raycastAllCommand = new RaycastAllCommand(commands, commandHits, maxHits, shouldFail ? 0f : 0.0001f);

            raycastAllCommand.Schedule(default(JobHandle)).Complete();

            Assert.AreEqual(meshConvexCollider, commandHits[0].collider);

            var collider = commandHits[1].collider;

            if (shouldFail)
            {
                Assert.IsNotNull(collider, "RaycastHit in corner point behaviour changed, minStep may be no longer required");
            }
            else
            {
                Assert.IsNull(collider);
            }

            commandHits.Dispose();
            commands.Dispose();
            raycastAllCommand.Dispose();
        }
示例#2
0
        public void CommonHitsTest([Values(2, 3, 4)] int maxHits)
        {
            var rayStart          = new Vector3(0f, 4f, 0f);
            var cubeCommand       = new RaycastCommand(cubeCollider.transform.position + rayStart, Vector3.down);
            var meshCubeCommand   = new RaycastCommand(meshCubeCollider.transform.position + rayStart, Vector3.down);
            var meshConvexCommand = new RaycastCommand(meshConvexCollider.transform.position + rayStart, Vector3.down);
            var emptyCommand      = new RaycastCommand(new Vector3(30f, 0f, 0f) + rayStart, Vector3.down);

            var commandsArray = new RaycastCommand[] { cubeCommand, meshCubeCommand, emptyCommand, meshConvexCommand };
            var commands      = new NativeArray <RaycastCommand>(commandsArray, Allocator.TempJob);
            var commandHits   = new NativeArray <RaycastHit>(commands.Length * maxHits, Allocator.TempJob);

            var raycastAllCommand = new RaycastAllCommand(commands, commandHits, maxHits);

            raycastAllCommand.Schedule(default(JobHandle)).Complete();

            Assert.AreEqual(cubeCollider, commandHits[maxHits * 0].collider);
            Assert.AreEqual(meshCubeCollider, commandHits[maxHits * 1].collider);
            Assert.AreEqual(null, commandHits[maxHits * 2].collider);
            Assert.AreEqual(meshConvexCollider, commandHits[maxHits * 3].collider);

            var physicsHits = new RaycastHit[maxHits];

            for (int i = 0; i < commands.Length; i++)
            {
                var physicsHitsCount = Physics.RaycastNonAlloc(commands[i].from, commands[i].direction, physicsHits);

                SortHits(physicsHits, physicsHitsCount);

                for (int j = 0; j < physicsHitsCount; j++)
                {
                    var physicsHit = physicsHits[j];
                    var commandHit = commandHits[i * maxHits + j];
                    RaycastHitEquality.AssertEqual(physicsHit, commandHit);
                }
                if (physicsHitsCount < maxHits)
                {
                    Assert.AreEqual(null, commandHits[i * maxHits + physicsHitsCount].collider);
                }
            }

            commandHits.Dispose();
            commands.Dispose();
            raycastAllCommand.Dispose();
        }