/// <summary> /// マップ内のオブジェクト生成 /// </summary> /// <param name="stageNum">生成するマップのステージ番号</param> private void MakeMap(Define.StageNum stageNum) { // ステージ親オブジェクト作成・各階層のTransform取得 stageParent = Instantiate(stagePrefab) as GameObject; wallParent = stageParent.transform.Find("Wall"); invisibleParent = stageParent.transform.Find("Invisible"); enemyParent = stageParent.transform.Find("Enemy"); // 連なった壁の最初の座標と最後の座標のリスト List <int[, ]> wallSequencePositions = new List <int[, ]>(); // 既にチェックした壁の座標リスト List <int[]> alreadyCheckedWidthWalls = new List <int[]>(); List <int[]> alreadyCheckedHeightWalls = new List <int[]>(); for (int z = 0; z < Define.mapSizeHeight; z++) { for (int x = 0; x < Define.mapSizeWidth; x++) { if (stages[stageNum].mapStatus[z, x] != StageData.MapType.Pole && stages[stageNum].mapStatus[z, x] != StageData.MapType.Wall) { continue; } //壁作成 int[] wallPos = new int[2] { z, x }; MakeWall(wallPos); StockWallSequenceFirstLastPos(stageNum, wallSequencePositions, wallPos, alreadyCheckedWidthWalls, true); StockWallSequenceFirstLastPos(stageNum, wallSequencePositions, wallPos, alreadyCheckedHeightWalls, false); if (Utility.IsContainedInPosList(wallPos, alreadyCheckedWidthWalls) || Utility.IsContainedInPosList(wallPos, alreadyCheckedHeightWalls)) { continue; } // 縦横どちらにも連なっていない孤立した壁をリストに追加 int[,] isolatedWallPositions = new int[, ] { { wallPos[0], wallPos[1] }, { wallPos[0], wallPos[1] } }; wallSequencePositions.Add(isolatedWallPositions); } } MakeInvisibleWalls(wallSequencePositions); }
/// <summary> /// 一方向に連なった壁の最初と最後の壁の位置をリストにストック /// </summary> /// <param name="stageNum">対象となるマップのステージ番号</param> /// <param name="wallSequencePositions">連なった壁の最初の座標と最後の座標のリスト</param> /// <param name="wallPosition">調べる壁の座標</param> /// <param name="alreadyCheckedWallPositions">既に調べた壁の座標リスト</param> /// <param name="isWidthCheck">横方向のチェックかどうか</param> private void StockWallSequenceFirstLastPos(Define.StageNum stageNum, List <int[, ]> wallSequencePositions, int[] wallPosition, List <int[]> alreadyCheckedWallPositions, bool isWidthCheck) { // チェックする方向(縦横)を確認 int dIndex = isWidthCheck ? 0 : 1; int[] dz = { 0, 1 }; int[] dx = { 1, 0 }; if (Utility.IsContainedInPosList(wallPosition, alreadyCheckedWallPositions)) { return; } int wallPosZ = wallPosition[0]; int wallPosX = wallPosition[1]; int wallCount = 0; // wallCountなくしてもちゃんと不可視壁作成できるかチェック while (true) { wallPosZ += dz[dIndex]; wallPosX += dx[dIndex]; if (stages[stageNum].mapStatus[wallPosZ, wallPosX] != StageData.MapType.Pole && stages[stageNum].mapStatus[wallPosZ, wallPosX] != StageData.MapType.Wall) { wallPosZ -= dz[dIndex]; wallPosX -= dx[dIndex]; if (wallCount > 0) { int[,] wallPositions = new int[2, 2] { { wallPosition[0], wallPosition[1] }, { wallPosZ, wallPosX } }; wallSequencePositions.Add(wallPositions); } wallCount = 0; break; } int[] nextWallPos = new int[2] { wallPosZ, wallPosX }; alreadyCheckedWallPositions.Add(nextWallPos); wallCount++; } }