Beispiel #1
0
    public bool Build(GridBrushBase Brush, int x, int y)
    {
        var pos = new Vector3Int(x, y, 0);

        if (!AstarPath.active.graphs[0].GetNearest(pos).node.Walkable)
        {
            return(false);
        }

        Brush.Paint(GridObject.GetComponent <Grid>(), Obstacles.gameObject, pos);
        //AstarPath.active.graphs[0].GetNearest(new Vector3(x, y)).node.Walkable = false;
        return(true);
    }
Beispiel #2
0
    public void Awake()
    {
        if (mapManager == null)
        {
            mapManager = this;
        }
        //Generate the map itself
        if (GridObject == null)
        {
            //Setup the grid
            GridObject                  = new GameObject();
            GridObject.name             = "Grid";
            GridObject.transform.parent = gameObject.transform;
            GridObject.AddComponent <Grid>();
            GridObject.transform.position = Vector3.zero;

            //Setup the Obstacle layer
            var ObstaclesObject = new GameObject();
            ObstaclesObject.transform.parent = GridObject.transform;
            ObstaclesObject.name             = "Obstacles";
            ObstaclesObject.layer            = 13;
            Obstacles = ObstaclesObject.AddComponent <Tilemap>();
            ObstaclesObject.AddComponent <TilemapRenderer>();
            ObstaclesObject.AddComponent <TilemapCollider2D>();

            //Setup the Ground layer
            var GroundObject = new GameObject();
            GroundObject.transform.parent = GridObject.transform;
            GroundObject.name             = "Ground";
            GroundObject.layer            = 0;
            Ground = GroundObject.AddComponent <Tilemap>();
            GroundObject.AddComponent <TilemapRenderer>().sortingOrder = -1;

            //Make the ground layer
            for (int x = -SizeX / 2; x < SizeX / 2; x++)
            {
                for (int y = -SizeY / 2; y < SizeY / 2; y++)
                {
                    Ground.SetTile(new Vector3Int(x, y, 0), Tiles[0]);
                }
            }

            //Add Resource Nodes
            for (var n = 0; n < NumResourceSpawn; n++)
            {
                var Pos = new Vector3Int(Random.Range(-SizeX / 2, SizeX / 2), Random.Range(-SizeY / 2, SizeY / 2), 0);
                ResourceBrush.Paint(GridObject.GetComponent <Grid>(), Obstacles.gameObject, Pos);
            }
        }
    }