public void TestCellLocalPosition()
        {
            var testGo = new GameObject("test");

            testGo.transform.position = Vector3.zero;
            var boxOverlapSquare = TestBoxOverlapChecker.CreateChecker(gridSizeX: 10, gridSizeZ: 10, rotateWithAgent: false, rootReference: testGo);

            var localPos = boxOverlapSquare.CellLocalPositions;

            Assert.AreEqual(new Vector3(-4.5f, 0, -4.5f), localPos[0]);
            Assert.AreEqual(new Vector3(-4.5f, 0, 4.5f), localPos[9]);
            Assert.AreEqual(new Vector3(4.5f, 0, -4.5f), localPos[90]);
            Assert.AreEqual(new Vector3(4.5f, 0, 4.5f), localPos[99]);
            Object.DestroyImmediate(testGo);

            var testGo2 = new GameObject("test");

            testGo2.transform.position = new Vector3(3.5f, 8f, 17f); // random, should have no effect on local positions
            var boxOverlapRect = TestBoxOverlapChecker.CreateChecker(gridSizeX: 5, gridSizeZ: 15, rotateWithAgent: true, rootReference: testGo);

            localPos = boxOverlapRect.CellLocalPositions;
            Assert.AreEqual(new Vector3(-2f, 0, -7f), localPos[0]);
            Assert.AreEqual(new Vector3(-2f, 0, 7f), localPos[14]);
            Assert.AreEqual(new Vector3(2f, 0, -7f), localPos[60]);
            Assert.AreEqual(new Vector3(2f, 0, 7f), localPos[74]);
            Object.DestroyImmediate(testGo2);
        }
        public void TestCellGlobalPositionNoRotate()
        {
            var testGo   = new GameObject("test");
            var position = new Vector3(3.5f, 8f, 17f);

            testGo.transform.position = position;
            var boxOverlap = TestBoxOverlapChecker.CreateChecker(gridSizeX: 10, gridSizeZ: 10, rotateWithAgent: false, rootReference: testGo);

            Assert.AreEqual(new Vector3(-4.5f, 0, -4.5f) + position, boxOverlap.GetCellGlobalPosition(0));
            Assert.AreEqual(new Vector3(-4.5f, 0, 4.5f) + position, boxOverlap.GetCellGlobalPosition(9));
            Assert.AreEqual(new Vector3(4.5f, 0, -4.5f) + position, boxOverlap.GetCellGlobalPosition(90));
            Assert.AreEqual(new Vector3(4.5f, 0, 4.5f) + position, boxOverlap.GetCellGlobalPosition(99));

            testGo.transform.Rotate(0, 90, 0); // should have no effect on positions
            Assert.AreEqual(new Vector3(-4.5f, 0, -4.5f) + position, boxOverlap.GetCellGlobalPosition(0));
            Assert.AreEqual(new Vector3(-4.5f, 0, 4.5f) + position, boxOverlap.GetCellGlobalPosition(9));
            Assert.AreEqual(new Vector3(4.5f, 0, -4.5f) + position, boxOverlap.GetCellGlobalPosition(90));
            Assert.AreEqual(new Vector3(4.5f, 0, 4.5f) + position, boxOverlap.GetCellGlobalPosition(99));

            Object.DestroyImmediate(testGo);
        }
        public void TestCellGlobalPositionRotate()
        {
            var testGo   = new GameObject("test");
            var position = new Vector3(15f, 6f, 13f);

            testGo.transform.position = position;
            var boxOverlap = TestBoxOverlapChecker.CreateChecker(gridSizeX: 5, gridSizeZ: 15, rotateWithAgent: true, rootReference: testGo);

            Assert.AreEqual(new Vector3(-2f, 0, -7f) + position, boxOverlap.GetCellGlobalPosition(0));
            Assert.AreEqual(new Vector3(-2f, 0, 7f) + position, boxOverlap.GetCellGlobalPosition(14));
            Assert.AreEqual(new Vector3(2f, 0, -7f) + position, boxOverlap.GetCellGlobalPosition(60));
            Assert.AreEqual(new Vector3(2f, 0, 7f) + position, boxOverlap.GetCellGlobalPosition(74));

            testGo.transform.Rotate(0, 90, 0);
            // round to int to ignore numeric errors
            Assert.AreEqual(Vector3Int.RoundToInt(new Vector3(-7f, 0, 2f) + position), Vector3Int.RoundToInt(boxOverlap.GetCellGlobalPosition(0)));
            Assert.AreEqual(Vector3Int.RoundToInt(new Vector3(7f, 0, 2f) + position), Vector3Int.RoundToInt(boxOverlap.GetCellGlobalPosition(14)));
            Assert.AreEqual(Vector3Int.RoundToInt(new Vector3(-7f, 0, -2f) + position), Vector3Int.RoundToInt(boxOverlap.GetCellGlobalPosition(60)));
            Assert.AreEqual(Vector3Int.RoundToInt(new Vector3(7f, 0, -2f) + position), Vector3Int.RoundToInt(boxOverlap.GetCellGlobalPosition(74)));

            Object.DestroyImmediate(testGo);
        }
        public void TestParseCollidersClosest()
        {
            var tag1 = "Player";
            List <GameObject> testObjects = new List <GameObject>();
            var testGo = new GameObject("test");

            testGo.transform.position = Vector3.zero;
            var boxOverlap = TestBoxOverlapChecker.CreateChecker(
                cellScaleX: 10f,
                cellScaleZ: 10f,
                gridSizeX: 2,
                gridSizeZ: 2,
                rootReference: testGo,
                detectableTags: new string[] { tag1 });
            var helper = new VerifyParseCollidersHelper();

            boxOverlap.GridOverlapDetectedClosest += helper.DetectedAction;

            for (var i = 0; i < 3; i++)
            {
                var boxGo = new GameObject("test");
                boxGo.transform.position = new Vector3(i + 1, 0, 1);
                boxGo.AddComponent <BoxCollider>();
                boxGo.tag = tag1;
                testObjects.Add(boxGo);
            }

            boxOverlap.Update();
            helper.Verify(1, new List <GameObject> {
                testObjects[0]
            });

            Object.DestroyImmediate(testGo);
            foreach (var go in testObjects)
            {
                Object.DestroyImmediate(go);
            }
        }
        public void TestBufferResize()
        {
            List <GameObject> testObjects = new List <GameObject>();
            var testGo = new GameObject("test");

            testGo.transform.position = Vector3.zero;
            testObjects.Add(testGo);
            var boxOverlap = TestBoxOverlapChecker.CreateChecker(rootReference: testGo, initialColliderBufferSize: 2, maxColliderBufferSize: 5);

            boxOverlap.Update();
            Assert.AreEqual(2, boxOverlap.ColliderBuffer.Length);

            for (var i = 0; i < 3; i++)
            {
                var boxGo = new GameObject("test");
                boxGo.transform.position = Vector3.zero;
                boxGo.AddComponent <BoxCollider>();
                testObjects.Add(boxGo);
            }
            boxOverlap.Update();
            Assert.AreEqual(4, boxOverlap.ColliderBuffer.Length);

            for (var i = 0; i < 2; i++)
            {
                var boxGo = new GameObject("test");
                boxGo.transform.position = Vector3.zero;
                boxGo.AddComponent <BoxCollider>();
                testObjects.Add(boxGo);
            }
            boxOverlap.Update();
            Assert.AreEqual(5, boxOverlap.ColliderBuffer.Length);

            Object.DestroyImmediate(testGo);
            foreach (var go in testObjects)
            {
                Object.DestroyImmediate(go);
            }
        }