/// <summary> /// Assigns a cell to a chunk Dependant on its location and the chunk size. /// </summary> /// <param name="x"> int x location of cell </param> /// <param name="y"> int y location of cell </param> /// <param name="cell"> Cell cell being assigned</param> void AddCellToChunk(int x, int y, Cell cell) { int chunkX = x / GlobalDataBase.chunckSizeX; int chunkZ = y / GlobalDataBase.chunckSizeY; GridChunk chunk = chunks[chunkX + chunkZ * chunkCountX]; int localX = x - chunkX * GlobalDataBase.chunckSizeX; //localX coordinate based on chunk size int localY = y - chunkZ * GlobalDataBase.chunckSizeY; //localY coordinate based on chunk size chunk.AddCell(localX + localY * GlobalDataBase.chunckSizeX, cell); }
void AddCellToChunk(int x, int z, GridCell cell) { int chunkX = x / GridMetrics.chunkSizeX; int chunkZ = z / GridMetrics.chunkSizeZ; GridChunk chunk = chunks[chunkX + chunkZ * chunkCountX]; int localX = x - chunkX * GridMetrics.chunkSizeX; int localZ = z - chunkZ * GridMetrics.chunkSizeZ; chunk.AddCell(localX + localZ * GridMetrics.chunkSizeX, cell); }
void CreateCell(int x, int z, int i) { Vector3 position = new Vector3(x * Metrics.radius * 2f, 0f, z * Metrics.radius * 2f); Cell cell = Instantiate(cellPrefab); // cell.transform.SetParent(transform, false); cell.transform.localPosition = position; cell.coordinates = Coordinates.FromOffsetCoordinates(x, z); if (x > 0) { cell.SetNeighbor(Direction.W, cells[i - 1]); } if (z > 0) { cell.SetNeighbor(Direction.S, cells[i - cellCountX]); } cells[i] = cell; Text label = Instantiate <Text>(cellLabelPrefab); // label.rectTransform.SetParent(gridCanvas.transform, false); label.rectTransform.anchoredPosition = new Vector2(position.x, position.z); label.text = cell.coordinates.ToString(); cell.uiRect = label.rectTransform; // add cell to chunk int chunkX = x / Metrics.chunkSizeX; int chunkZ = z / Metrics.chunkSizeZ; GridChunk chunk = chunks[chunkX + chunkZ * chunkCountX]; int localX = x - chunkX * Metrics.chunkSizeX; int localZ = z - chunkZ * Metrics.chunkSizeZ; chunk.AddCell(localX, localZ, cell); cell.Elevation = 0; // Refresh }