public static void ChunksEnterLeaveViewReq(List <Vector2Int> enterViewChunks, List <Vector2Int> leaveViewChunks = null) { CSChunksEnterLeaveViewReq req = new CSChunksEnterLeaveViewReq(); List <CSVector2Int> enter = new List <CSVector2Int>(); foreach (Vector2Int chunk in enterViewChunks) { CSVector2Int c = new CSVector2Int { x = chunk.x, y = chunk.y }; enter.Add(c); } req.EnterViewChunks.AddRange(enter); if (leaveViewChunks != null) { List <CSVector2Int> leave = new List <CSVector2Int>(); foreach (Vector2Int chunk in leaveViewChunks) { CSVector2Int c = new CSVector2Int { x = chunk.x, y = chunk.y }; leave.Add(c); } req.LeaveViewChunks.AddRange(leave); } //Debug.Log("CS_CHUNKS_ENTER_LEVAE_VIEW_REQ," + req.EnterViewChunks.Count + "," + req.LeaveViewChunks.Count); NetworkManager.SendPkgToServer(ENUM_CMD.CS_CHUNKS_ENTER_LEVAE_VIEW_REQ, req, ChunksEnterLeaveViewRes); }
public Vector2Int(CSVector2Int v) { x = v.x; y = v.y; }
public static Vector2Int ToVector2Int(this CSVector2Int csv) { return(new Vector2Int(csv.x, csv.y)); }
public static byte[] GenerateChunkData(CSVector2Int chunk, byte[] blocks) { Random.InitState(chunk.x * 1000 + chunk.y); for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { float x = 0.5f + i + chunk.x * 16; float z = 0.5f + j + chunk.y * 16; float noise = Mathf.PerlinNoise(x / scale, z / scale); int height = Mathf.RoundToInt(maxHeight * noise); for (int k = height; k >= 0; k--) { CSBlockType type = CSBlockType.None; if (k == 0) { type = CSBlockType.BedRock; } else { int distanceFromHighestBlock = height - k; switch (distanceFromHighestBlock) { case 0: //random surface block int dice = Random.Range(1, 200); if (dice <= 20) { int plantdice = Random.Range(1, 5); switch (plantdice) { case 1: case 2: type = CSBlockType.Grass; break; case 3: type = CSBlockType.Poppy; break; case 4: type = CSBlockType.Dandelion; break; } } else if (dice <= 199 && dice > 197) { int treedice = Random.Range(1, 10); if (treedice == 1) { GenerateTree(blocks, i, k, j, chunk.ToVector2Int()); } } break; case 1: type = CSBlockType.GrassBlock; break; case 2: case 3: case 4: case 5: type = CSBlockType.Dirt; break; default: type = CSBlockType.Stone; break; } } if (type != CSBlockType.None) { blocks[256 * k + 16 * i + j] = (byte)type; } } } } return(blocks); }