예제 #1
0
        public void GetWalkableNeighbours(int cellIndex, List <int> resultNeighbours)
        {
            resultNeighbours.Clear();
            Vector2Int cellCoords = MapUtils.IndexToCoords(cellIndex, sizeX);

            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    if (i == 0 && j == 0)
                    {
                        continue;
                    }

                    int checkX = cellCoords.X + i;
                    int checkY = cellCoords.Y + j;

                    if (checkX >= 0 && checkX < sizeX && checkY >= 0 && checkY < sizeY)
                    {
                        int neighbourIndex = MapUtils.CoordsToIndex(checkX, checkY, sizeX);

                        if (isWalkable[neighbourIndex])
                        {
                            resultNeighbours.Add(neighbourIndex);
                        }
                    }
                }
            }
        }
예제 #2
0
        public Graph GenerateGraph()
        {
            List <Graph.Node> nodes = new List <Graph.Node>();
            List <Graph.Edge> edges = new List <Graph.Edge>();

            Graph.Node[,] nodeMap = new Graph.Node[Width, Height];

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    Graph.Node node = new Graph.Node(new Vector3(x, y));
                    nodes.Add(node);
                    nodeMap[x, y] = node;

                    foreach (Vector2Int neighbour in _nodeNeighbours)
                    {
                        int xx = x + neighbour.x;
                        int yy = y + neighbour.y;

                        if (MapUtils.IsInsideMap(xx, yy, Width, Height))
                        {
                            edges.Add(new Graph.Edge(MapUtils.CoordsToIndex(x, y, Width), MapUtils.CoordsToIndex(xx, yy, Width)));
                        }
                    }
                }
            }

            return(new Graph(nodes.ToArray(), edges.ToArray(), new TileGraphMap(Width, Height, nodeMap)));
        }
        private void GenerateQuad(int x, int y, Vector3[] verts, Vector2[] uvs, int[] tris, int width, int bitmask)
        {
            int quadIndex = MapUtils.CoordsToIndex(x, y, width);
            int vertIndex = quadIndex * 4;
            int triIndex  = quadIndex * 6;

            int vertWidth = width * 2;

            // Generate verts
            verts[vertIndex]     = new Vector3(x, y) + Vector3.forward;
            verts[vertIndex + 1] = new Vector3(x + 1, y) + Vector3.forward;
            verts[vertIndex + 2] = new Vector3(x, y + 1) + Vector3.forward;
            verts[vertIndex + 3] = new Vector3(x + 1, y + 1) + Vector3.forward;

            // Generate UVs
            Vector2[] uv = GetUVProvider().GetUVs(bitmask);
            uvs[vertIndex]     = uv[0];
            uvs[vertIndex + 1] = uv[1];
            uvs[vertIndex + 2] = uv[2];
            uvs[vertIndex + 3] = uv[3];

            // Generate tris
            tris[triIndex + 2] = vertIndex;
            tris[triIndex + 1] = vertIndex + 1;
            tris[triIndex + 0] = vertIndex + 2;

            tris[triIndex + 5] = vertIndex + 1;
            tris[triIndex + 4] = vertIndex + 3;
            tris[triIndex + 3] = vertIndex + 2;
        }
예제 #4
0
 private TileTypeReference[] EnflattenTiles(TileTypeReference[,] walls)
 {
     TileTypeReference[] flattened = new TileTypeReference[Width * Height];
     for (int y = 0; y < Height; y++)
     {
         for (int x = 0; x < Width; x++)
         {
             flattened[MapUtils.CoordsToIndex(x, y, Width)] = walls[x, y];
         }
     }
     return(flattened);
 }
예제 #5
0
 public bool IsWalkable(int x, int y)
 {
     return(isWalkable[MapUtils.CoordsToIndex(x, y, sizeX)]);
 }
예제 #6
0
 public void SetWalkable(int x, int y, bool walkable)
 {
     isWalkable[MapUtils.CoordsToIndex(x, y, sizeX)] = walkable;
 }
예제 #7
0
 int CoordsToIndex(int x, int y)
 {
     return(MapUtils.CoordsToIndex(x, y, mapSizeX));
 }