private void PlaceObjectOfTypeAt(int objectType, TileLoc loc) { ConnectedTileObject cto = connectedTileMap.GetConnectedTileAt(loc); bool shouldPlace = true; if (cto != null) { Debug.Log("Removing underlying tile of type " + objectType + " at " + loc + "."); connectedTileMap.RemoveConnectedTileAt(cto.tileLoc); if (cto.objectType == pathObjectTypeToBuild) { // Do not place new path. shouldPlace = false; } } if (shouldPlace) { Debug.Log("Placing a new tile of type " + objectType + " at " + loc + "."); connectedTileMap.CreateConnectedTileObject(loc, pathObjectTypeToBuild); } // Update the surrounding tiles UpdateNeigboursOf(loc); }
public TileLoc RelativeTo(TileLoc tileLoc) { if (tileLoc == null) { throw new ArgumentNullException(); } return(new TileLoc(tileLoc.x + x, tileLoc.y + y)); }
/** * Utility method used by both ConnectedTileObjects (paths) and TileObjects (other) to create a basic tile. */ public GameObject CreateTileAt(TileLoc loc, Transform parent) { GameObject tile = GameObject.CreatePrimitive(PrimitiveType.Plane); tile.name = "Ground Tile (" + loc.x + ", " + loc.y + ")"; tile.transform.parent = parent; tile.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); tile.transform.localPosition = new Vector3(loc.x, 0, loc.y); return(tile); }
private void UpdateNeigboursOf(TileLoc tileLoc) { // Update neighbours foreach (TileLoc pos in TilesUtils.Cardinal) { ConnectedTileObject c = GameMap.Instance.connectedTileMap.GetConnectedTileAt(pos.RelativeTo(tileLoc)); if (c != null) { Debug.Log("Updating " + tileLoc + "..."); c.UpdateConnection(); } } }
public TileLoc(TileLoc tileLoc) { this.x = tileLoc.x; this.y = tileLoc.y; }
private void GenerateFakeObjectAtRandomPost() { TileLoc loc = new TileLoc(Random.Range(0, SquaredMapSize), Random.Range(0, SquaredMapSize)); //GameObject donut = Resources.I TODO }