public void SendGetChunk(string Cid, int x, int y) //connection id { ChunkModel SyncChunk = new ChunkModel(); SyncChunk.x = x / 32; SyncChunk.y = y / 32; byte[,] chunk = new byte[32, 32]; for (int xc = 0; xc < 32; xc++) { for (int yc = 0; yc < 32; yc++) { if (WorldMap[SyncChunk.x * 32 + xc, SyncChunk.y * 32 + yc] < 6) { chunk[xc, yc] = roadMap[SyncChunk.x * 32 + xc, SyncChunk.y * 32 + yc]; } else { chunk[xc, yc] = WorldMap[SyncChunk.x * 32 + xc, SyncChunk.y * 32 + yc]; } } } SyncChunk.data = new List <byte[]>(32); for (int yc = 0; yc < 32; yc++) { byte[] bufferchunk = new byte[32]; for (int xc = 0; xc < 32; xc++) { bufferchunk[xc] = chunk[xc, yc]; } SyncChunk.data.Add(bufferchunk); } //SyncChunk.data = new List<string>(32); //for (int k = 0; k < 32; k++) //{ // string result = null; // for (int i = 0; i < 32; i++) // { // if (i == 0) // result = JsonConvert.SerializeObject(chunk[k, i]); // else // result += "," + JsonConvert.SerializeObject(chunk[k, i]); // // SyncChunk.data.Add(JsonConvert.SerializeObject(chankMap[x / 32, y / 32][0, i])); // } // SyncChunk.data.Add(result); //SyncChunk.chunks = JsonConvert.SerializeObject(chunk); // //chankMapCopy[SyncChunk.x, SyncChunk.y] = chankMap[SyncChunk.x, SyncChunk.y]; //} //SyncChunk.chunk = new byte[32, 32]; //SyncChunk.chunk = chunk; hubContext.Clients.Client(Cid).debug(SyncChunk); }
private void DeleteDrawables(ChunkModel targetedChunk) { int childCount = gameObject.transform.childCount; for (int childIndex = 0; childIndex < childCount; childIndex++) { if (this.gameObject.transform.GetChild(childIndex).name == targetedChunk.ChunkIdentifier) { // Debug.Log("Deleted the chunk in question!"); Destroy(this.gameObject.transform.GetChild(childIndex).gameObject); } } }
//public void SendChunk1(string Cid, int x, int y)//connection id 1 убрать добавил для тестов версии 2 0 //{ // ChunkModel SyncChunk = new ChunkModel(); // SyncChunk.x = x / 32; // SyncChunk.y = y / 32; // SyncChunk.data = new List<string>(32); // for (int k = 0; k < 32; k++) // { // string result = null; // for (int i = 0; i < 32; i++) // { // if (i == 0) // result = JsonConvert.SerializeObject(chankMap[SyncChunk.x, chanks_Y - SyncChunk.y - 1][k, i]); // else // result += "," + JsonConvert.SerializeObject(chankMap[SyncChunk.x, chanks_Y - SyncChunk.y - 1][k, i]); // // SyncChunk.data.Add(JsonConvert.SerializeObject(chankMap[x / 32, y / 32][0, i])); // } // SyncChunk.data.Add(result); // //chankMapCopy[SyncChunk.x, SyncChunk.y] = chankMap[SyncChunk.x, SyncChunk.y]; // } // hubContext.Clients.Client(Cid).debug(SyncChunk); //} #endregion #region отправка обновленного чанка версия два ноль public void SendChunk(string Cid, int x, int y) //connection id { ChunkModel SyncChunk = new ChunkModel(); SyncChunk.x = x / 32; SyncChunk.y = y / 32; byte[,] chunk = new byte[32, 32]; for (int xc = 0; xc < 32; xc++) { for (int yc = 0; yc < 32; yc++) { if (WorldMap[SyncChunk.x * 32 + xc, SyncChunk.y * 32 + yc] < 6) { chunk[xc, yc] = roadMap[SyncChunk.x * 32 + xc, SyncChunk.y * 32 + yc]; } else { chunk[xc, yc] = WorldMap[SyncChunk.x * 32 + xc, SyncChunk.y * 32 + yc]; } } } SyncChunk.data = new List <byte[]>(32); for (int yc = 0; yc < 32; yc++) { byte[] bufferchunk = new byte[32]; for (int xc = 0; xc < 32; xc++) { bufferchunk[xc] = chunk[xc, yc]; } SyncChunk.data.Add(bufferchunk); } //chankMapCopy[SyncChunk.x, SyncChunk.y] = chankMap[SyncChunk.x, SyncChunk.y]; hubContext.Clients.Client(Cid).debug(SyncChunk); }
public ChunkData(Chunk chunk, ChunkModel model) { this.chunk = chunk; this.model = model; }
public void SetUp() { this.chunkModel = new ChunkModel(); }
public void TearDown() { this.chunkModel = null; }
// Constructor public Chunk(ChunkCoord _coord, World _world) { model = new ChunkModel(_coord, _world); world = _world; }
private void CreateDrawables(ChunkModel targetedChunk) { //Debug.Log("When you see this, I will be updating the chunk in question!"); #region InitChunk GameObject thisChunk = GameObject.CreatePrimitive(PrimitiveType.Plane); thisChunk.transform.localScale = new Vector3(1, 5, 1); thisChunk.name = targetedChunk.ChunkIdentifier; thisChunk.tag = "chunk"; thisChunk.transform.position = new Vector3(targetedChunk.Position.x * CHUNK_LENGTH, targetedChunk.Position.y, targetedChunk.Position.z * CHUNK_LENGTH); thisChunk.transform.parent = this.gameObject.transform; #endregion #region MaterialOfChunk Material groundMat; if (targetedChunk.IsUnlocked == true) { groundMat = materials.Where(x => x.name == "grassyGroundMaterial").FirstOrDefault(); } else { groundMat = materials.Where(x => x.name == "lockedGroundMaterial").FirstOrDefault(); } if (targetedChunk.isEndChunk == true) { GameObject nextLevel = Instantiate(prefabs.Where(x => x.name == "staircase").FirstOrDefault(), targetedChunk.Position * CHUNK_LENGTH, Quaternion.identity); nextLevel.transform.parent = thisChunk.transform; } thisChunk.GetComponent <MeshRenderer>().material = groundMat; #endregion #region PopulateChunkWithObjects if (targetedChunk.IsUnlocked == true) { int objectIndex = 0; foreach (ChunkObjectModel nextObject in targetedChunk.ChunkObjects) { Vector3 objectPosition = new Vector3(targetedChunk.Position.x * CHUNK_LENGTH + nextObject.Position.x, targetedChunk.Position.y, targetedChunk.Position.z * CHUNK_LENGTH + nextObject.Position.z); string objectNamePrefix = "object_"; string nextobjectName = ""; string prefabName = ""; switch (nextObject.ObjectType) { case ChunkObjectType.TREE: prefabName = "Tree2"; nextobjectName = objectNamePrefix + "tree_" + objectIndex; break; case ChunkObjectType.STONE: prefabName = "Rock1"; nextobjectName = objectNamePrefix + "stone_" + objectIndex; break; } GameObject nextChunkObject = Instantiate(prefabs.Where(x => x.name == prefabName).FirstOrDefault(), objectPosition, Quaternion.identity); nextChunkObject.GetComponent <DestroyableBehaviour>().SetObjectData(nextObject); nextChunkObject.transform.parent = thisChunk.transform; objectIndex++; } } #endregion }
private void CreateDrawables(ChunkModel targetedChunk, int index) { targetedChunk.ChunkIdentifier = "chunk_" + index; CreateDrawables(targetedChunk); }
private void RefreshDrawables(ChunkModel targetedChunk) { DeleteDrawables(targetedChunk); CreateDrawables(targetedChunk); }
//ПОЛУЧЕНИЕ #region Прием чанка private void Sub_debug_Data(object[] obj) { chank = new byte[32, 32];//объявляем буферный чанк //string[] cols = new string[32]; уже ненужная хуета // Debug.Log(obj[0].ToString()); оказывается этот дебаг нехуево так тормозит //pos = JsonConvert.DeserializeObject<MoveModel>(obj[1].ToString()); ChunkModel chunk = JsonConvert.DeserializeObject <ChunkModel>(obj[0].ToString()); #region OLD //Debug.Log(JsonConvert.SerializeObject(chunk.chunk).ToString()); // int i = 0; //chunk.data.Reverse(); //foreach (var item in chunk.data) //{ // cols[i] = item; // // Debug.Log(cols[i]); // i++; //} //chunk.data.Clear(); //for (int x = 0; x < 32; x++) //{ // string[] bufer = new string[32];//массив символов // bufer = cols[x].Split(',');//режем // for (int y = 0; y < 32; y++) // { // //Debug.Log(bufer[y]); // chank[x, 31 - y] = byte.Parse(bufer[y]);//заполняем // // Debug.Log(JsonConvert.SerializeObject(chank)); // } //} //Debug.Log(chunk.chunks); //byte[,] chnk = new byte[32,32]; //chnk= JsonConvert.DeserializeObject<byte[,]>(chunk.chunks); #endregion #region NEW int l = 32; foreach (var item in chunk.data) { l--; for (int x = 0; x < 32; x++) { chank[x, 31 - l] = item[x]; //ПОКА КОСТЫЛЬ ПОКА НЕТ НОРМАЛЬНОЙ ПОДГРУЗКИ НА СЕРВЕРЕ } } #endregion #region SET chankx = chunk.x; chanky = chunk.y; // updatechank = true; chankBufer[chankx, chanky] = 1; chunkload.chankMap[chankx, chanky] = new byte[32, 32]; chunkload.chankMap[chankx, chanky] = chank; //JsonConvert.DeserializeObject<byte[,]>(chunk.chunks); //chunkload.chankMap[0, 0] = chank; // ChunkSpawner.SetActive(true); Debug.Log("x: " + chankx + " y: " + chanky); //Debug.Log(JsonConvert.SerializeObject(chank)); // chunkload.chankMap[chunk.x, chunk.y] = chunk.data; //chunk = obj[0].ToString(); //Debug.Log("x:"+pos.X+" y:"+pos.Y); //Debug.Log(JsonConvert.SerializeObject(chunk.data)); //Debug.Log(JsonConvert.SerializeObject(chunkload.chankMap[pos.X, pos.Y])); //debugtext.text = mapstring; #endregion }
/// <summary> /// Constructor of the DungeonGenerator, will create a new dungeon each time a new instance of this class is created /// </summary> public DungeonGenerator() { DungeonPointer generatorPointer = DungeonPointer.Left; int rooms = 15; Vector3 pointerPosition = new Vector3(0, 0, 0); dungeon.Add(new ChunkModel(true, pointerPosition)); for (int roomIndex = 0; roomIndex < rooms; roomIndex++) { switch (generatorPointer) { case DungeonPointer.Left: pointerPosition = new Vector3(pointerPosition.x + 1, pointerPosition.y, pointerPosition.z); break; case DungeonPointer.Right: pointerPosition = new Vector3(pointerPosition.x - 1, pointerPosition.y, pointerPosition.z); break; case DungeonPointer.Up: pointerPosition = new Vector3(pointerPosition.x, pointerPosition.y, pointerPosition.z + 1); break; case DungeonPointer.Down: pointerPosition = new Vector3(pointerPosition.x, pointerPosition.y, pointerPosition.z - 1); break; } if (CheckNextPosition(pointerPosition) == true) { ChunkModel nextChunk = new ChunkModel(false, pointerPosition); if (roomIndex >= rooms - 1) { nextChunk.isEndChunk = true; } dungeon.Add(nextChunk); } else { roomIndex--; } int nextDirection = UnityEngine.Random.Range(1, 5); // exclusive, means max of 4 switch (nextDirection) { case 1: generatorPointer = DungeonPointer.Left; break; case 2: generatorPointer = DungeonPointer.Right; break; case 3: generatorPointer = DungeonPointer.Up; break; case 4: generatorPointer = DungeonPointer.Down; break; } } }