Esempio n. 1
0
    public void regeneratePathGrid()
    {
        // just to keep it under control
        System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
        timer.Start();
        wallMask = LayerMask.NameToLayer("Walls");
        Walls.CompressBounds();
        Vector3Int dimensions = Walls.cellBounds.size;

        PathGrid newPathGrid = new PathGrid(dimensions.x, dimensions.y);

        for (int n = Walls.cellBounds.xMin; n < Walls.cellBounds.xMax; n++)
        {
            int x = n - Walls.cellBounds.xMin;
            for (int p = Walls.cellBounds.yMin; p < Walls.cellBounds.yMax; p++)
            {
                int        y          = p - Walls.cellBounds.yMin;
                Vector3Int localPlace = (new Vector3Int(n, p, (int)Walls.transform.position.y));
                Vector3    place      = Walls.CellToWorld(localPlace) + Vector3.one / 2f;


                PathGrid.Cell c = new PathGrid.Cell();
                newPathGrid.cells[x, y] = c;
                c.gridPos   = new Vector2Int(x, y);
                c.globalPos = place;

                //is it traversable?
                c.traversable = !Walls.HasTile(localPlace);
            }
        }

        for (int x = 0; x < dimensions.x; x++)
        {
            for (int y = 0; y < dimensions.y; y++)
            {
            }
        }
        timer.Stop();
        if (curr.debugPaths)
        {
            Debug.Log(string.Format(
                          "Regenerated Pathing Grid\n" +
                          "Took {0} ms\n" +
                          "Grid size is now {1} by {2} cells ({3} cells total)",
                          timer.Elapsed.TotalMilliseconds, newPathGrid.width, newPathGrid.height, newPathGrid.width * newPathGrid.height));
        }

        pathGrid = newPathGrid;
    }
Esempio n. 2
0
    public void OnDrawGizmosSelected()
    {
        if (pathGrid == null || pathGrid.cells == null || pathGrid.cells.GetLength(0) == 0 || pathGrid.cells.GetLength(1) == 0)
        {
            return;
        }
        for (int x = 0; x < pathGrid.cells.GetLength(0); x++)
        {
            for (int y = 0; y < pathGrid.cells.GetLength(1); y++)
            {
                PathGrid.Cell c = pathGrid.cells[x, y];
                Gizmos.color = c.traversable ? traverseColor : noTraverseColor;
                Gizmos.DrawCube(c.globalPos, Walls.cellSize);
            }
        }
        Gizmos.color = Color.red;
        Vector2Int gridPos = ClampToGrid(PlayerBaseClass.current.playerCenter.position);
        Vector3    pos     = HelperClass.V2toV3(pathGrid.cells[gridPos.x, gridPos.y].globalPos);

        Gizmos.DrawSphere(pos, 1f / 2f);
    }
Esempio n. 3
0
 public ActiveCell(PathGrid.Cell parent) : base(parent.gridPos, parent.globalPos, parent.traversable)
 {
 }