// 장애물 생성 private void CreateObstacle(int count, int horizontal, int vertical) { List <DecoTileData> decoTileData = currentTileSet.DecoTileData; for (int i = 0; i < count; i++) { int randX = Random.Range(0, horizontal); int randZ = Random.Range(0, vertical); string randDecoTile = decoTileData[Random.Range(0, decoTileData.Count)].PrefabPath; PoolManager.Instance.CreateObjectPoolFromPath <DecorationTile>(randDecoTile, randDecoTile); DecorationTile decoTile = PoolManager.Instance.Create <DecorationTile>(randDecoTile); if (CheckDecoTileCollision(decoTile, randX, randZ)) { decoTile.init(new Vector3Int(randX, 1, randZ)); decoTileList.Add(new DecoTileListData(randDecoTile, decoTile)); for (int j = 0; j < decoTile.gameObject.transform.childCount; j++) { Vector3 pos = decoTile.gameObject.transform.GetChild(j).transform.localPosition; tileList[(int)pos.x + randX][(int)pos.z + randZ].SetState(TileState.Obstacle); } } else { PoolManager.Instance.Release <DecorationTile>(randDecoTile, decoTile); } } }
// 데코 타일의 충돌 체크 / 게임오브젝트의 자식 = 각 타일 포지션 타일의 상태를 비교 private bool CheckDecoTileCollision(DecorationTile decoTile, int x, int z) { Transform tileTransform = decoTile.gameObject.transform; for (int i = 0; i < tileTransform.childCount; i++) { int checkX = (int)tileTransform.GetChild(i).transform.localPosition.x + x; int checkZ = (int)tileTransform.GetChild(i).transform.localPosition.z + z; if (tileList.Count <= checkX || tileList[0].Count <= checkZ || tileList[(int)checkX][(int)checkZ].CheckBuildable() == false) { return(false); } } return(true); }
// 물 and 다리 생성 private void CreateWaterAndBridge(int x, int z) { if (tileList[x][z].GetState() == TileState.Obstacle) { PoolManager.Instance.CreateObjectPoolFromPath <DecorationTile>("Bridge", currentTileSet.BridgeData.PrefabPath); DecorationTile bridge = PoolManager.Instance.Create <DecorationTile>("Bridge"); bridge.init(new Vector3Int(x, 0, z)); decoTileList.Add(new DecoTileListData("Bridge", bridge)); tileList[x][z].Init(TileState.Bridge, new Vector3(x, (float)-0.5, z), currentWaterMaterial[0], currentWaterMaterial[1], false); } else { tileList[x][z].Init(TileState.Water, new Vector3(x, (float)-0.5, z), currentWaterMaterial[0], currentWaterMaterial[1], false); } }
// 성 생성 private void CreateCastle(int vertical, int horizontal) { monsterCastlePos = new Vector3Int(Random.Range(0, CASTLE_MAX_TILE_RANGE), 0, Random.Range(0, vertical)); tileList[monsterCastlePos.x][monsterCastlePos.z].SetState(TileState.Castle); PoolManager.Instance.CreateObjectPoolFromPath <DecorationTile>("MonsterCastle", "Prefabs/Monster_Castle", 1); DecorationTile monsterCastle = PoolManager.Instance.Create <DecorationTile>("MonsterCastle"); monsterCastle.init(new Vector3Int(monsterCastlePos.x, 0, monsterCastlePos.z)); decoTileList.Add(new DecoTileListData("MonsterCastle", monsterCastle)); playerCastlePos = new Vector3Int(Random.Range(horizontal - CASTLE_MAX_TILE_RANGE, horizontal), 0, Random.Range(0, vertical)); tileList[playerCastlePos.x][playerCastlePos.z].SetState(TileState.Castle); PoolManager.Instance.CreateObjectPoolFromPath <DecorationTile>("PlayerCastle", "Prefabs/Player_Castle", 1); DecorationTile playerCastle = PoolManager.Instance.Create <DecorationTile>("PlayerCastle"); playerCastle.init(new Vector3Int(playerCastlePos.x, 0, playerCastlePos.z)); decoTileList.Add(new DecoTileListData("PlayerCastle", playerCastle)); }
public DecoTileListData(string key, DecorationTile decoTile) { this.key = key; this.decoTile = decoTile; }