Created
April 12, 2022 02:55
-
-
Save Tunied/90c3f7d832f84a506c37020fbc5c9857 to your computer and use it in GitHub Desktop.
遍历给定Tilemap下的所有非空Tile,根据Tile的Name做相应的操作
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tileMap = _t; | |
var bounds = tileMap.cellBounds; | |
var allTiles = tileMap.GetTilesBlock(bounds); | |
for (var x = 0; x < bounds.size.x; x++) | |
{ | |
for (var y = 0; y < bounds.size.y; y++) | |
{ | |
var tile = allTiles[x + y * bounds.size.x]; | |
if (tile == null) continue; | |
var tileLocalIndex = new Vector2Int(x + bounds.xMin, y + bounds.yMin); | |
var tileCenterWorldPosV3 = tileMap.GetCellCenterWorld(new Vector3Int(tileLocalIndex.x, tileLocalIndex.y, 0)); | |
var tileIndex = GameLogicUtils.WorldPos_To_TileIndex(tileCenterWorldPosV3); | |
//主基地 | |
if (tile.name == "ABC") | |
{ | |
//TODO: do logic here | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment