private void PlaceObjectOfTypeAt(string id, TileLoc loc) { ConnectedTileObject cto = connectedGenericTileMap.GetConnectedTileAt(loc); bool shouldPlace = true; if (cto != null) { Debug.Log("Removing underlying tile of type " + id + " at " + loc + "."); connectedGenericTileMap.RemoveConnectedTileAt(cto.tileLoc); if (cto.GetObjectType() == pathObjectTypeToBuild) { // Do not place new path. shouldPlace = false; } } if (shouldPlace) { Debug.Log("Placing a new tile of type " + id + " at " + loc + "."); connectedGenericTileMap.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)); }
public T GetTileObjectAt(TileLoc tileLoc) { if (tileLoc == null) { Debug.LogError("Fatal : TileLoc should not be null."); return(null); } return(!Tiles.ContainsKey(tileLoc) ? null : Tiles[tileLoc]); }
/** * 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); }
public void RemoveTileObjectAt(TileLoc tileLoc) { if (tileLoc == null) { Debug.LogError("Fatal : TileLoc should not be null."); return; } if (Tiles.ContainsKey(tileLoc)) { Tiles.Remove(tileLoc); } }
// Converts a TileLoc to a Vector3 public Vector3 GetWorldPosFromTileLoc(TileLoc tileLoc) { TileObject tileAt = tileMap.GetTileObjectAt(tileLoc); if (tileAt != null) { return(new Vector3(tileAt.transform.position.x, 0, tileAt.transform.position.z)); } Debug.Log("tileMapTiles : " + tileMap.Tiles.Count); Debug.LogError("Fatal error : Could not find tile at '" + tileLoc + "'."); return(new Vector3()); }
private void UpdateNeigboursOf(TileLoc tileLoc) { // Update neighbours foreach (TileLoc pos in ConnectedTileUtils.Cardinal) { ConnectedTileObject c = GameMap.Instance.connectedGenericTileMap.GetConnectedTileAt(pos.RelativeTo(tileLoc)); if (c != null) { Debug.Log("Updating " + tileLoc + "..."); c.UpdateConnection(); } } }
public TileObject CreateTileObject(TileLoc loc, string type = UITileObjectTypes.DEFAULT) { if (GetTileObjectAt(loc) != null) { Debug.Log("Fatal : Tile already at '" + loc + "'."); return(null); } GameObject tile = GameMap.Instance.CreateTileAt(loc, transform); TileObject c = tile.AddComponent <TileObject>(); c.SetObjectType(type); c.tileLoc = loc; Tiles.Add(loc, c); return(c); }
public TileLoc(TileLoc tileLoc) { x = tileLoc.x; y = tileLoc.y; }