public void ReCreate(TroutData data) { troutID = data.ID; transform.position = data.Position; isPass = data.IsPass; troutCategory = data.Category; transform.rotation = data.Rotation; troutObj = Instantiate(troutList[data.Type], data.Position, data.Rotation) as GameObject; SetColor(data.Color); _top = (int)data.Position.z; _left = (int)data.Position.x; }
void SaveFish() { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + FISH_SUB + SceneManager.GetActiveScene().buildIndex; string countPath = Application.persistentDataPath + FISH_COUNT_SUB + SceneManager.GetActiveScene().buildIndex; FileStream countStream = new FileStream(countPath, FileMode.Create); formatter.Serialize(countStream, fishesTrout.Count); countStream.Close(); for (int i = 0; i < fishesTrout.Count; i++) { FileStream stream = new FileStream(path + i, FileMode.Create); TroutData data = new TroutData(fishesTrout[i]); formatter.Serialize(stream, data); stream.Close(); } }
void LoadFish() { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + FISH_SUB + SceneManager.GetActiveScene().buildIndex; string countPath = Application.persistentDataPath + FISH_COUNT_SUB + SceneManager.GetActiveScene().buildIndex; int fishCount = 0; if (File.Exists(countPath)) { FileStream countStream = new FileStream(countPath, FileMode.Open); fishCount = (int)formatter.Deserialize(countStream); countStream.Close(); } else { Debug.LogError("Path not found in " + countPath); } for (int i = 0; i < fishCount; i++) { if (File.Exists(path + i)) { FileStream stream = new FileStream(path + i, FileMode.Open); TroutData data = formatter.Deserialize(stream) as TroutData; stream.Close(); Vector3 position = new Vector3(data.position[0], data.position[1], data.position[2]); AITrout fish = Instantiate(fishPrefab, position, Quaternion.identity); } else { Debug.LogError("Path not found in " + path + i); } } }
// 部屋の作成 public void Create(int room_num) { for (int z = 0; z < roomSize.Height; z++) { for (int x = 0; x < roomSize.Widht; x++) { int type = -1; int dir_type = -1; if (z == 0) { if (x == 0) { type = (int)TROUT_TYPE.COUNERWALL; dir_type = TOP_LEFT; } else if (x == roomSize.Widht - 1) { type = (int)TROUT_TYPE.COUNERWALL; dir_type = TOP_RIGHT; } else { type = (int)TROUT_TYPE.WALL; dir_type = TOP; } } else if (z == roomSize.Height - 1) { if (x == 0) { type = (int)TROUT_TYPE.COUNERWALL; dir_type = BOTTOM_LEFT; } else if (x == roomSize.Widht - 1) { type = (int)TROUT_TYPE.COUNERWALL; dir_type = BOTTOM_RIGHT; } else { type = (int)TROUT_TYPE.WALL; dir_type = BOTTOM; } } else { if (x == 0) { type = (int)TROUT_TYPE.WALL; dir_type = LEFT; } else if (x == roomSize.Widht - 1) { type = (int)TROUT_TYPE.WALL; dir_type = RIGHT; } else { type = (int)TROUT_TYPE.FLOOR; dir_type = CENTER; } } string category = "ROOM" + room_num.ToString(); Color color = new Color(0.1f, 0.1f, 0.1f); Vector3 position = new Vector3(_left - x, 0, _top + z); TroutData trout = new TroutData() { ID = 0, // ここでは未だIDを振らない Type = type, IsPass = false, Category = category, Color = color, Position = position, Rotation = GetDirectionRotation(dir_type), }; troutDataList.Add(trout); } } }
// 道の生成 public void Create() { int loop = 0; int type = (int)TROUT_TYPE.FLOOR; int dir_type = CENTER; string category = "ROAD"; Color color = new Color(0.1f, 0.3f, 0.1f); Vector3 position = new Vector3(nowPoint[POS_X], 0, nowPoint[POS_Z]); Quaternion rotation = Quaternion.Euler(0, 0, 0); TroutData strout = new TroutData() { ID = 0, // ここでは未だIDを振らない Type = type, IsPass = false, Category = category, Color = color, Position = position, Rotation = rotation, }; troutDataList.Add(strout); // 道のルート作成 while (true) { List <int> road_dir = NextRoadDir(); if (road_dir.Count == 0) { break; } int rand = Random.Range(0, road_dir.Count); int dir = road_dir[rand]; switch (dir) { case TOP: nowPoint[POS_Z] -= 1; _bottom -= 1; break; case LEFT: nowPoint[POS_X] += 1; _right += 1; break; case BOTTOM: nowPoint[POS_Z] += 1; _top += 1; break; case RIGHT: nowPoint[POS_X] -= 1; _left -= 1; break; default: break; } TroutData trout = new TroutData() { ID = 0, // ここでは未だIDを振らない Type = type, IsPass = false, Category = category, Color = color, Position = new Vector3(nowPoint[POS_X], 0, nowPoint[POS_Z]), Rotation = rotation, }; troutDataList.Add(trout); loop++; if (loop > 1000) { break; } } if (troutDataList.Count < 3) { return; // 短い場合は生成やめます } // 道の向きとグラフィックタイプの指定 for (int i = 0; i < troutDataList.Count; i++) { float now_top = troutDataList[i].Position.z; float now_left = troutDataList[i].Position.x; if (i == 0) {// 最初の道 float after_top = troutDataList[i + 1].Position.z; float after_left = troutDataList[i + 1].Position.x; if (outDoor.Dir == TOP) { if (now_top == after_top) { if (now_left > after_left) { type = (int)TROUT_TYPE.L; dir_type = RIGHT_BOTTOM; } else { type = (int)TROUT_TYPE.L; dir_type = LEFT_BOTTOM; } } else { type = (int)TROUT_TYPE.I; dir_type = TOP_BOTTOM; } } else if (outDoor.Dir == LEFT) { if (now_left == after_left) { if (now_top > after_top) { type = (int)TROUT_TYPE.L; dir_type = RIGHT_TOP; } else { type = (int)TROUT_TYPE.L; dir_type = RIGHT_BOTTOM; } } else { type = (int)TROUT_TYPE.I; dir_type = LEFT_RIGHT; } } else if (outDoor.Dir == BOTTOM) { if (now_top == after_top) { if (now_left > after_left) { type = (int)TROUT_TYPE.L; dir_type = RIGHT_TOP; } else { type = (int)TROUT_TYPE.L; dir_type = LEFT_TOP; } } else { type = (int)TROUT_TYPE.I; dir_type = TOP_BOTTOM; } } else if (outDoor.Dir == RIGHT) { if (now_left == after_left) { if (now_top > after_top) { type = (int)TROUT_TYPE.L; dir_type = LEFT_TOP; } else { type = (int)TROUT_TYPE.L; dir_type = LEFT_BOTTOM; } } else { type = (int)TROUT_TYPE.I; dir_type = LEFT_RIGHT; } } } else if (i == troutDataList.Count - 1) {// 最後の道 float before_top = troutDataList[i - 1].Position.z; float before_left = troutDataList[i - 1].Position.x; if (inDoor.Dir == TOP) { if (now_top == before_top) { if (now_left > before_left) { type = (int)TROUT_TYPE.L; dir_type = RIGHT_BOTTOM; } else { type = (int)TROUT_TYPE.L; dir_type = LEFT_BOTTOM; } } else { type = (int)TROUT_TYPE.I; dir_type = TOP_BOTTOM; } } else if (inDoor.Dir == LEFT) { if (now_left == before_left) { if (now_top > before_top) { type = (int)TROUT_TYPE.L; dir_type = RIGHT_TOP; } else { type = (int)TROUT_TYPE.L; dir_type = RIGHT_BOTTOM; } } else { type = (int)TROUT_TYPE.I; dir_type = LEFT_RIGHT; } } else if (inDoor.Dir == BOTTOM) { if (now_top == before_top) { if (now_left > before_left) { type = (int)TROUT_TYPE.L; dir_type = RIGHT_TOP; } else { type = (int)TROUT_TYPE.L; dir_type = LEFT_TOP; } } else { type = (int)TROUT_TYPE.I; dir_type = TOP_BOTTOM; } } else if (inDoor.Dir == RIGHT) { if (now_left == before_left) { if (now_top > before_top) { type = (int)TROUT_TYPE.L; dir_type = LEFT_TOP; } else { type = (int)TROUT_TYPE.L; dir_type = LEFT_BOTTOM; } } else { type = (int)TROUT_TYPE.I; dir_type = LEFT_RIGHT; } } else if (inDoor.Dir == DEADEND) { if (now_left == before_left) { if (now_top > before_top) { type = (int)TROUT_TYPE.U; dir_type = LEFT_BOTTOM; } else { type = (int)TROUT_TYPE.U; dir_type = RIGHT_TOP; } } else { if (now_left > before_left) { type = (int)TROUT_TYPE.U; dir_type = LEFT_TOP; } else { type = (int)TROUT_TYPE.U; dir_type = RIGHT_BOTTOM; } } } } else {// 最初と最後ではない道 float after_top = troutDataList[i + 1].Position.z; float after_left = troutDataList[i + 1].Position.x; float before_top = troutDataList[i - 1].Position.z; float before_left = troutDataList[i - 1].Position.x; if (now_top == before_top && now_top == after_top) { type = (int)TROUT_TYPE.I; dir_type = LEFT_RIGHT; } else if (now_left == before_left && now_left == after_left) { type = (int)TROUT_TYPE.I; dir_type = TOP_BOTTOM; } else { if (now_top == before_top) { if (now_left > before_left) { if (now_top > after_top) { type = (int)TROUT_TYPE.L; dir_type = RIGHT_TOP; } else { type = (int)TROUT_TYPE.L; dir_type = RIGHT_BOTTOM; } } else { if (now_top > after_top) { type = (int)TROUT_TYPE.L; dir_type = LEFT_TOP; } else { type = (int)TROUT_TYPE.L; dir_type = LEFT_BOTTOM; } } } else { if (now_top > before_top) { if (now_left > after_left) { type = (int)TROUT_TYPE.L; dir_type = RIGHT_TOP; } else { type = (int)TROUT_TYPE.L; dir_type = LEFT_TOP; } } else { if (now_left > after_left) { type = (int)TROUT_TYPE.L; dir_type = RIGHT_BOTTOM; } else { type = (int)TROUT_TYPE.L; dir_type = LEFT_BOTTOM; } } } } } troutDataList[i].Type = type; troutDataList[i].Rotation = GetDirectionRotation(dir_type); } }
public void SaveTroutData(TroutData data) { troutDataList.Add(data); }