Example #1
0
        public bool LineOfSight(Tile node1, Tile node2)
        {
            var nodes = BresenhamsLine.Intersect((Vector2Int)node1, (Vector2Int)node2);

            foreach (var n in nodes)
            {
                if (GetTile(n.x, n.y).cost > CostScale * 0.5f)
                {
                    return(false);
                }
            }

            return(true);
        }
        public void MatchesSource(
            [Random(Start, End, C)] int x1,
            [Random(Start, End, C)] int y1,
            [Random(Start, End, C)] int x2,
            [Random(Start, End, C)] int y2)
        {
            Vector2Int point1 = new Vector2Int(x1, y1);
            Vector2Int point2 = new Vector2Int(x2, y2);

            var expected = SourceImplementation(point1, point2);
            var actual   = BresenhamsLine.Intersect(point1, point2);

            Assert.That(actual, Is.EquivalentTo(expected));
        }
Example #3
0
        private static ConcurrentDictionary <Vector2Int, Chunk> GenerateChunks(NavMeshTriangulation navMeshTriangulation)
        {
            var dict = new ConcurrentDictionary <Vector2Int, Chunk>();

            IList <Wall> walls = NavmeshProcessor.GetNavmeshBoundaryEdges(navMeshTriangulation);

            //Add walls
            foreach (Wall wall in walls)
            {
                var chunkIndices = BresenhamsLine.Intersect(
                    IndexFunction(wall.StartPoint),
                    IndexFunction(wall.EndPoint)
                    );

                foreach (var point in chunkIndices)
                {
                    AddWall(wall, point);
                }
            }

            #if UNITY_EDITOR
            var parent = new GameObject("DEBUG Chunks");
            foreach (var c in dict)
            {
                var go = new GameObject($"Chunk {c.Key}");
                go.transform.parent = parent.transform;
                var vis = go.AddComponent <ChunkVisualiser>();
                vis.Initialise(c.Value, c.Key);
            }
            #endif

            return(dict);

            void AddWall(Wall wall, Vector2Int key)
            {
                if (!dict.TryAdd(key, new Chunk(wall)))
                {
                    dict[key].walls.Add(wall);
                }
            }
        }