private void GenerateMap(Island island) { string pos = RandomPosition(); if (pos != null) { int posX = int.Parse(pos.Split(',')[0]); int posY = int.Parse(pos.Split(',')[1]); RectAngle islandRc = new RectAngle(posX, posY, island.mapItemRealRow, island.mapItemRealColumn); IslandPlaceInfo info = new IslandPlaceInfo(); info.rc = islandRc; info.island = island; if (MapItemTool.JudgeBeyondBoundary(islandRc, mapInfo.mapRow, mapInfo.mapColumn)) { //当前获取到的随机地址不可存放物体(超过地图限制),重新获取地点 tempCellInfos.Add(pos); mapCells.Remove(pos); GenerateMap(island); return; } //查看是否与以放置的物体重叠 foreach (IslandPlaceInfo placeInfo in islandsPlaced) { //判断要放置的物体与以放置的物体是否重叠 if (MapItemTool.JudgeMapItemOverLay(info.rc, placeInfo.rc)) { //当前获取到的随机地址不可存放物体(存放物体范围内已被占用),重新获取地点 tempCellInfos.Add(pos); mapCells.Remove(pos); GenerateMap(island); return; } } //说明获取到的地址ok,放置物体 islandsPlaced.Add(info); ResetCellInfos(); RemoveRCItemCells(info); //放置海岛后,生成下一个海岛,继续放置 PlaceRandomIsland(); } else { //已经没有可以放置该物体的点了,去除该物体的预制体及可以存放个数 Debug.Log("已经没有可以放置该物体的点了" + currentIsland.name); if (isLandCount.ContainsKey(currentIsland.name)) { isLandCount.Remove(currentIsland.name); } islandCanPlace.Remove(currentIsland); ResetCellInfos(); PlaceRandomIsland(); } }
private void RemoveRCItemCells(IslandPlaceInfo info) { RectAngle rc = info.rc; int posX = rc.PosX; int posY = rc.PosY; for (int i = posX; i < posX + rc.Row; i++) { for (int j = posY; j < posY + rc.Column; j++) { mapCells.Remove(i + "," + j); } } }