private void Update() { if (Input.GetMouseButton(0)) { floorLayer.ClearAllTiles(); collisionLayer.ClearAllTiles(); generateRandomMap(); drawTiles(); } if (Input.GetMouseButton(1)) { floorLayer.ClearAllTiles(); collisionLayer.ClearAllTiles(); map = dynamicSmoothMap(map); drawDynamicTiles(map); } if (Input.GetKeyDown(KeyCode.KeypadEnter)) { int[,] freeSpots = getFreeTiles(map); spawnItem(freeSpots); } }
void Update() { if (buildingBeingPlaced) { overlayTilemap.ClearAllTiles(); Vector3 mousePos = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10f); Vector3Int terrainPosition = terrainTilemap.WorldToCell(cam.ScreenToWorldPoint(mousePos)); Vector3Int buildingPosition = buildingsTilemap.WorldToCell(cam.ScreenToWorldPoint(mousePos)) + new Vector3Int(0, 0, -1); Vector3Int gridPosition = overlayTilemap.WorldToCell(cam.ScreenToWorldPoint(mousePos)); Vector3Int overlayPosition = gridPosition + new Vector3Int(0, 0, -2); if (terrainTilemap.HasTile(terrainPosition)) { Debug.Log(terrainTilemap.GetTile(gridPosition)); if (terrainTilemap.GetTile(terrainPosition) != unbuildableTile && !buildingsTilemap.HasTile(buildingPosition)) { overlayTilemap.SetTile(overlayPosition, availableTile); if (Input.GetMouseButtonDown(0)) { buildingsTilemap.SetTile(buildingPosition, buildingTile); GameEvents.current.DisableTileCursor(); buildingBeingPlaced = false; } } else { overlayTilemap.SetTile(overlayPosition, unavailableTile); } } if (Input.GetMouseButtonDown(1)) { buildingBeingPlaced = false; GameEvents.current.DisableTileCursor(); } } }
public void HighlightTurnShotsOnOpponentMap(IEnumerable <int> cells) { layer.ClearAllTiles(); foreach (int cell in cells) { layer.SetTile(GridUtils.CellIndexToCoordinate(cell, rules.areaSize.x), tile); } }
public void SetGameMapForEditorPlay() { GameMap.ClearAllTiles(); PlaceAllUserBlocks(); UserLayer.gameObject.SetActive(false); BaseLayer.gameObject.SetActive(false); GenerateBlockInstances(); }
public void setGhostPreview(bool newGhostPreview) { ghostPreview = newGhostPreview; if (!ghostPreview) { ghostTilemap.ClearAllTiles(); } }
public void PutOverlayTilesAt(List <Vector3Int> places) { overlayMap.ClearAllTiles(); foreach (var pos in places) { overlayMap.SetTile(pos, overlayTile); } }
public void ClearLevel() { tilemap.ClearAllTiles(); emptySpaceLists.Clear(); currentGeneratorIndexIdForEmptySpaceTracking = 0; SetupEmptyGrid(); System.GC.Collect(); }
private void Overlay(Vector3Int PlayerPos) { overlayMap.ClearAllTiles(); overlayMap.SetTile(PlayerPos, overlayTile); for (int i = 1; i < numberOfSteps; i++) { if (tilemap.GetTile(PlayerPos + Vector3Int.up * i) != tileRemover.wallTile && tilemap.GetTile(PlayerPos + Vector3Int.up * i) != tileRemover.destructibleTile) { overlayMap.SetTile(PlayerPos + Vector3Int.up * i, overlayTile); } else { i = numberOfSteps; } } for (int j = 1; j < numberOfSteps; j++) { if (tilemap.GetTile(PlayerPos + Vector3Int.down * j) != tileRemover.wallTile && tilemap.GetTile(PlayerPos + Vector3Int.down * j) != tileRemover.destructibleTile) { overlayMap.SetTile(PlayerPos + Vector3Int.down * j, overlayTile); } else { j = numberOfSteps; } } for (int k = 1; k < numberOfSteps; k++) { if (tilemap.GetTile(PlayerPos + Vector3Int.left * k) != tileRemover.wallTile && tilemap.GetTile(PlayerPos + Vector3Int.left * k) != tileRemover.destructibleTile) { overlayMap.SetTile(PlayerPos + Vector3Int.left * k, overlayTile); } else { k = numberOfSteps; } } for (int l = 1; l < numberOfSteps; l++) { if (tilemap.GetTile(PlayerPos + Vector3Int.right * l) != tileRemover.wallTile && tilemap.GetTile(PlayerPos + Vector3Int.right * l) != tileRemover.destructibleTile) { overlayMap.SetTile(PlayerPos + Vector3Int.right * l, overlayTile); } else { l = numberOfSteps; } } }
/* void Update() * { * * if (Input.GetMouseButtonDown(0)) * { * doSim(numR); * } * * * if (Input.GetMouseButtonDown(1)) * { * clearMap(true); * } * * * * * }*/ public void Refresh() { topMap.ClearAllTiles(); botMap.ClearAllTiles(); topMapBeautify.ClearAllTiles(); botMapBeautify.ClearAllTiles(); this.GetComponent <ObjectAutomata>().Clear(); terrainMap = null; StartCoroutine(doSimCorutine(genStatistics.groundNumR)); }
private void OnNewNode(Grid.Grid.Node node) { switch (_mode) { case MouseMode.Moving: highlightedUiTilemap.ClearAllTiles(); _path = _pathfinding.CalculatePath(_player.transform.position, node.WorldPosition); if (_path != null && _path.Count > 0) { foreach (var n in _path) { var pos = grid.Value.Position00.ToVector2Int() + n.Position; highlightedUiTilemap.SetTile((Vector3Int)pos, up); } } else { var pos = grid.Value.Position00.ToVector2Int() + node.Position; if (uiTilemap.HasTile((Vector3Int)pos)) { highlightedUiTilemap.SetTile((Vector3Int)pos, attackTile); } } break; case MouseMode.RangedWeaponMode: var diff = node.Position - _player.CurrentNodeIdx; highlightedUiTilemap.ClearAllTiles(); if (diff.IsCardinal()) { HighlightCardinal(diff, highlightedUiTilemap); } break; case MouseMode.OtherWeapon: var effected = _item.FindAllPossibleEffectedNodes(_player.Occupant, grid.Value); if (effected.Contains(node)) { var pos = grid.Value.Position00.ToVector2Int() + node.Position; if (uiTilemap.HasTile((Vector3Int)pos)) { highlightedUiTilemap.SetTile((Vector3Int)pos, highlighted); } } break; default: break; } }
public void Highlight(Vector3 _Position) { Vector3Int position = m_Nodes.WorldToCell(_Position); Color color = m_Nodes.HasTile(position) ? Color.red : Color.green; m_Highlight.ClearAllTiles(); m_Highlight.SetTile(position, m_HighlightTile); m_Highlight.SetColor(position, color); }
/// <summary> /// 初始化网格地图 /// </summary> /// <param name="mapSize">地图大小</param> /// <param name="tileAsset">Tile资源</param> public void InitHexMeshTileMap(Vector3Int mapSize, TileBase tileAsset) { m_meshTilemap.ClearAllTiles(); if (m_meshTilemap == null) { Debug.LogError("marginMeshTilemap is null"); return; } SetTileOfSize(new Vector2Int(mapSize.x, mapSize.y), tileAsset); m_meshTilemap.RefreshAllTiles(); }
private void MoveCurrentSlime(Vector3Int tileLocation) { movementOverlay.ClearAllTiles(); cursorOverlay.ClearAllTiles(); if (slimeFromTileLocation.ContainsKey(tileLocation) && slimeFromTileLocation[tileLocation].TileLocation == tileLocation) { mergeTarget = slimeFromTileLocation[tileLocation]; } CurrentSlime.Move(tileLocation); moveCount++; }
public void PaintTiles(Vector3Int[] cells) { //Stack <Vector3Int> cellPath = Pathfinder.GetCellPath(path); TileBase[] tiles = new TileBase[cells.Length]; tilemap.ClearAllTiles(); for (int i = 0; i < tiles.Length; i++) { tiles[i] = defaultTile; } tilemap.SetTiles(cells, tiles); }
private void Update() { if (_mode == MapMode.Disabled) { return; } var pos = _mainCamera.ScreenToWorldPoint(new Vector3(Mouse.current.position.ReadValue().x, Mouse.current.position.ReadValue().y, _mainCamera.transform.position.z * -1)); var coordinate = _grid.WorldToCell(pos); coordinate.Clamp(_minCoordinate, _maxCoordinate); cursorLayer.ClearAllTiles(); cursorLayer.SetTile(coordinate, _cursorTile); }
void Update() { if (mode == "disabled") { return; } Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3Int coordinate = grid.WorldToCell(pos); coordinate.Clamp(minCoordinate, maxCoordinate); cursorLayer.ClearAllTiles(); cursorLayer.SetTile(coordinate, cursorTile); }
// Draws the path from the player character to the targetPos (targetPos should be raycasted mouse position) public void DrawPath(Vector3 characterPos, Vector3 targetPos, int range, int max_range) { Node endNode = GetMapNode(targetPos); if (endNode == lastSelectedNode) { return; } else { lastSelectedNode = endNode; } pathMap.ClearAllTiles(); //Node startNode = GetMapNode(characterPos); List <Node> path = GetPathToFollow(characterPos, targetPos); //List<Node> path = AStar.FindPath(startNode, endNode, 1000); GenerateCursorMessage(path); if (path == null) { return; } // Draw new path for (int i = 0; i < path.Count; i++) { Node node = path[i]; pathMap.SetTile(node.Vec3Int, PathTile); pathMap.SetTileFlags(node.Vec3Int, TileFlags.None); if (i >= path.Count - range) { pathMap.SetColor(node.Vec3Int, pathReachColor); } else if (i >= (path.Count - (range + max_range))) { pathMap.SetColor(node.Vec3Int, pathNextReachColor); } else { pathMap.SetColor(node.Vec3Int, pathOutOfReachColor); } } }
protected void LoadFromArray(byte[,] arr, Tilemap targetMap) { Vector3Int pos = new Vector3Int(); int yLen = arr.GetUpperBound(0); int xLen = arr.GetUpperBound(1); targetMap.ClearAllTiles(); for (int y = yLen - 1; y >= 0; y--) { for (int x = 0; x < xLen; x++) { pos.Set(x - xLen / 2, y - yLen / 2, 0); byte b = arr[y, x]; targetMap.SetTile(pos, ByteToTile(b)); if (b != 255) { GameObject tileLogicObjectPrefab = tileObjects[b]; if (tileLogicObjectPrefab != null) { GameObject tileLogicObject = Instantiate(tileLogicObjectPrefab); tileLogicObject.transform.SetParent(targetMap.transform); Vector3 tileMiddlePos = new Vector3( targetMap.transform.position.x + pos.x + 0.5f, targetMap.transform.position.y + pos.y + 0.5f, 0); tileLogicObject.transform.position = tileMiddlePos; } } } } }
void clearMap() { groundMap.ClearAllTiles(); colliderMap.ClearAllTiles(); terrainMap = null; }
public static void RenderMap(int[,] map, Tilemap tilemap, TileBase grass, TileBase dirt, GameObject coin) { //Clear the map (ensures we dont overlap) tilemap.ClearAllTiles(); //Loop through the width of the map for (int x = 0; x < map.GetUpperBound(0); x++) { //Loop through the height of the map for (int y = 0; y < map.GetUpperBound(1); y++) { // 1 = tile, 0 = no tile if (map[x, y] == 0) { tilemap.SetTile(new Vector3Int(x, y, 0), dirt); } if (map[x, y] == 1) { tilemap.SetTile(new Vector3Int(x, y, 0), grass); if (Random.Range(0, 3) == 0) { Instantiate(coin, new Vector3(x + 0.5f, y + 0.5f, 0), Quaternion.identity); } } } } }
public Vector3 BuildFloor(bool nextisboss, bool thisisboss) { if (colorTiles == null) //double check that we have our tiles { colorTiles = GameObject.FindWithTag("Tiles").GetComponent <Tilemap>(); } //Debug.Log(colorTiles); int tilescovered; int attempts = 0; float coverage; do //if a certian number of tiles aren't covered, run again { colorTiles.ClearAllTiles(); SetupTilesArray(); CreateRoomsAndCorridors(); tilescovered = SetTilesValuesForRooms(); coverage = ((float)tilescovered / (float)(columns * rows)); Debug.Log("tiles covered: " + tilescovered + " / " + columns * rows + " = " + coverage); attempts++; } while (coverage < .15 && attempts < 10); SetTilesValuesForCorridors(); InstantiateTiles(); AddObjects(nextisboss, thisisboss); //TODO Instantiate walls and roofs //Instantaiate entance and exit doors //Remove unneded walls return(Spawn); }
public void Load(string saveName = "0") { var loadedTiles = SaveManager.Load(saveName); if (loadedTiles == null || loadedTiles.tiles == null) { return; } FrontTilemap.ClearAllTiles(); var Tile = PlacingTile; var Square = PlacingTile; tiles.TryGetValue("Tile", out Tile); tiles.TryGetValue("Square", out Square); foreach (var tile in loadedTiles.tiles) { var pos = new Vector3Int((int)tile.x, (int)tile.y, 0); FrontTilemap.SetTile(pos, Tile); } foreach (var tile in loadedTiles.squares) { var pos = new Vector3Int((int)tile.x, (int)tile.y, 0); FrontTilemap.SetTile(pos, Square); } }
void CreateWorld() { Debug.Log("SCClient.CreateWorld - All data received! Creating world."); Ground = Instantiate(GroundPrefab); Tilemap tilemap = Ground.GetComponentInChildren <Tilemap>(); tilemap.ClearAllTiles(); TileStore tileStore = GameObject.Find("Tile Registry").GetComponent <TileStore>(); foreach (SCTileData data in tileDataBuffer) { tilemap.SetTile(new Vector3Int { x = data.X, y = data.Y, z = data.Z }, tileStore.Get(data.TileID)); } tilemap.CompressBounds(); Vector3 center = tilemap.cellBounds.center; Vector3 camPos = tilemap.CellToWorld(new Vector3Int((int)center.x, (int)center.y, 0)); camPos.z = -10; Camera.main.transform.position = camPos; loadingWorld = false; //GameObject.Find("Loading Screen").SetActive(false); }
void paintTheFloor(int floorWidth, int floorHeight) { //Generates Background based upon tile type groundMap.ClearAllTiles(); wallMap.ClearAllTiles(); for (int xx = 0; xx < floorWidth; xx++) { for (int yy = 0; yy < floorHeight; yy++) { if (floorArray [xx, yy] == tileType.ROOM) { //Instantiate (bgRoom, new Vector3 (xx, yy, 0), Quaternion.identity).transform.SetParent(this.transform.root); groundMap.SetTile(new Vector3Int(xx, yy, 0), floor); } if (floorArray [xx, yy] == tileType.FLOOR) { //Instantiate (bgFloor, new Vector3 (xx, yy, 0), Quaternion.identity).transform.SetParent(this.transform.root); groundMap.SetTile(new Vector3Int(xx, yy, 0), floor); } if (floorArray [xx, yy] == tileType.CONNECTION) { Instantiate(bgConnection, new Vector3(xx, yy, 0), Quaternion.identity).transform.SetParent(this.transform.root); } if (floorArray[xx, yy] == tileType.VOID) { wallMap.SetTile(new Vector3Int(xx, yy, 0), wall); } if (floorArray[xx, yy] == tileType.SHOPROOM) //Generate Item Room { groundMap.SetTile(new Vector3Int(xx, yy, 0), carpet); } } } }
void SetUpFreakoutGrid() { tilemapSeen.GetComponent <TilemapRenderer>().enabled = true; tilemapSeen.ClearAllTiles(); tilemapSeen.transform.position = transform.position; int boxReach = (int)(freakOutRadius / tilemapSeen.layoutGrid.cellSize.x); Vector3Int tempTile; for (int i = -boxReach; i <= boxReach; i++) { for (int j = -boxReach; j <= boxReach; j++) { bool clear = true; tempTile = new Vector3Int(i, j, 0); if (Vector3.Distance(transform.position, tilemapSeen.GetCellCenterWorld(tempTile)) > freakOutRadius) { tilemapSeen.SetTile(tempTile, occludedTile); clear = false; } Vector2 dir = tilemapSeen.GetCellCenterWorld(tempTile) - transform.position; if (clear && Physics2D.Raycast(transform.position, dir, dir.magnitude, wallLayer).transform != null) { tilemapSeen.SetTile(tempTile, occludedTile); clear = false; } } } }
void SearchForSpawners(Tilemap tileMap, SpawnableObjectBehaviour[] spawnableObjects) { if (spawnableGameBojects.Length > 0) { foreach (SpawnableObjectBehaviour spawner in spawnableObjects) { Debug.Log("Objekte vom Typ " + spawner.nameOfEntity + " werden gesucht ..."); if (spawnMap.ContainsTile(spawner.spawnerTile)) { Debug.Log("Objekte vom Typ " + spawner.nameOfEntity + " wurden gefunden!"); BoundsInt bounds = tileMap.cellBounds; TileBase[] allTiles = tileMap.GetTilesBlock(bounds); for (int x = 0; x < bounds.size.x; x++) { for (int y = 0; y < bounds.size.y; y++) { TileBase tile = allTiles[x + y * bounds.size.x]; if (tile != null) { if (tile == spawner.spawnerTile) { Debug.Log("x:" + x + " y:" + y + " Objekt: " + spawner.nameOfEntity); Instantiate(spawner.spawnableGameObject, new Vector3(tileMap.origin.x + x + 0.5f, tileMap.origin.y + y + 0.5f, 0f), Quaternion.identity); } } } } } } spawnMap.ClearAllTiles(); } }
public static void RenderMap(int[,] map, Tilemap tilemap, TileBase tile, TileBase up_tile, GameObject[] items, float item_spwn) { bool is_item; //マップをクリアする(重複しないようにする) tilemap.ClearAllTiles(); //マップの幅の分、周回する for (int x = 0; x < map.GetUpperBound(0); x++) { is_item = false; //マップの高さの分、周回する for (int y = 0; y < map.GetUpperBound(1); y++) { // 1 = タイルあり、0 = タイルなし if (map[x, y] == 1) { tilemap.SetTile(new Vector3Int(x, y, 0), tile); } else if (map[x, y] == 2) { tilemap.SetTile(new Vector3Int(x, y, 0), up_tile); } else { if (x > 0 && x % item_spwn == 0 && !is_item) { GameObject go = Instantiate(items[Random.Range(0, items.GetUpperBound(0))], new Vector3Int(x, y, 0), Quaternion.identity); go.transform.position = tilemap.transform.position + new Vector3(x * 0.4f, y * 0.4f + 0.2f, 0); is_item = true; } } } } }
public void GenerateLevel() { TileMap.ClearAllTiles(); var map = MapGenerator.GenerateRandomMap(Size.x, Size.y); var center = new Vector3Int(Size.y / 2, Size.y / 2, 0); var pos = TilesGrid.CellToWorld(center); pos.z = -10f; Camera.transform.position = pos; Camera.orthographicSize = Mathf.Sqrt(Size.x * Size.y); for (int x = 0; x < map.Count; x++) { for (int y = 0; y < map[x].Count; y++) { var prefabs = GetCurrentTilePrefabs(x, y, map); for (int i = 0; i < prefabs.Count; i++) { ApplyTilePrefab(prefabs[i].GetTile(), new Vector3Int(x, y, 0), TileMap, i); } } } }
void drawMaze() { canMove = false; tiles.ClearAllTiles(); for (int row = -1; row < curMaze.Count + 1; row++) { for (int col = -1; col < curMaze[0].Length + 1; col++) { if (row < 0 || col < 0 || row == curMaze.Count || col == curMaze[0].Length) { tiles.SetTile(new Vector3Int(col + 1, curMaze.Count - row, 0), wall); } else if (row % 2 == 1 && col % 2 == 1) { tiles.SetTile(new Vector3Int(col + 1, curMaze.Count - row, 0), wall); } else if (curMaze[row][col] == '*') { tiles.SetTile(new Vector3Int(col + 1, curMaze.Count - row, 0), wall); } else if (curMaze[row][col] == '#') { tiles.SetTile(new Vector3Int(col + 1, curMaze.Count - row, 0), goal); } else if (curMaze[row][col] == '@') { tiles.SetTile(new Vector3Int(col + 1, curMaze.Count - row, 0), player); playerPos = new MazeGenerator.Point(row, col, rows, columns); } } } }
private void CopyTilemapContent(Tilemap original, Tilemap toCopy) { //Empty tilemap to copy in toCopy.ClearAllTiles(); //Get Bounds and Resize Tilemaps BoundsInt bounds = original.cellBounds; TileBase[] allTiles = original.GetTilesBlock(bounds); toCopy.origin = bounds.position; toCopy.size = bounds.size; toCopy.ResizeBounds(); toCopy.transform.position = bounds.position; //Copy all content for (int x = 0; x < bounds.size.x; x++) { for (int y = 0; y < bounds.size.y; y++) { TileBase tile = allTiles[x + y * bounds.size.x]; Vector3Int cellPos = new Vector3Int(x, y, 0); toCopy.SetTile(cellPos, tile); } } toCopy.RefreshAllTiles(); }