Exemple #1
0
        public void splitChildChunk()
        {
            List <MapCell>[] cellLists = new List <MapCell> [4];
            for (int i = 0; i < cellLists.Length; i++)
            {
                cellLists [i] = new List <MapCell> ();
            }

            for (int x = 0; x < countX; x++)
            {
                for (int y = 0; y < countY; y++)
                {
                    int i = x * (int)countY + y;
                    if (i < cells.Count)
                    {
                        if (x < countX / 2)
                        {
                            if (y < countY / 2)
                            {
                                cellLists[0].Add(cells [i]);                                    // bottomLeft
                            }
                            else
                            {
                                cellLists[1].Add(cells [i]);                                    // topLeft
                            }
                        }
                        else
                        {
                            if (y < countY / 2)
                            {
                                cellLists[3].Add(cells [i]);                                    // bottomRight
                            }
                            else
                            {
                                cellLists[2].Add(cells [i]);                                    // topRight
                            }
                        }
                    }
                }
            }

            for (int i = 0; i < 4; i++)
            {
                if (cellLists [i].Count > 0)
                {
                    GameObject newChunkObject = new GameObject("Cell Chunk Level " + (lod - 1));
                    newChunkObject.transform.SetParent(transform);
                    MapChunk newChunk = newChunkObject.AddComponent <MapChunk> ();
                    newChunk.init((lod - 1), cellLists [i], countX / 2, countY / 2);
                    newChunk.cellRenderer.material = cellRenderer.material;
                    newChunk.updateMesh();
                    childChunks [i] = newChunk;
                }
            }
        }
        public IEnumerator createChunks()
        {
            yield return(null);

            int countX = (int)maxGridSize.x;
            int countY = (int)maxGridSize.y;

            int numOfChunkX = countX / (int)Mathf.Pow(2, maxLOD - 1);
            int numOfChunkY = countY / (int)Mathf.Pow(2, maxLOD - 1);

            List <MapCell>[,] cellsForChunks = new List <MapCell> [numOfChunkX + 1, numOfChunkY + 1];

            for (int i = 0; i < numOfChunkX + 1; i++)
            {
                for (int j = 0; j < numOfChunkY + 1; j++)
                {
                    cellsForChunks [i, j] = new List <MapCell> ();
                }
            }
            for (int x = 0; x < countX; x++)
            {
                int chunkNumX = x / (int)Mathf.Pow(2, maxLOD - 1);
                for (int y = 0; y < countY; y++)
                {
                    int chunkNumY = y / (int)Mathf.Pow(2, maxLOD - 1);
                    cellsForChunks [chunkNumX, chunkNumY].Add(cells [x * countY + y]);
                }
            }
            for (int i = 0; i < numOfChunkX + 1; i++)
            {
                for (int j = 0; j < numOfChunkY + 1; j++)
                {
                    if (cellsForChunks [i, j].Count > 0)
                    {
                        GameObject newChunkObject = new GameObject("Cell Chunk Level " + maxLOD);
                        newChunkObject.transform.SetParent(transform);
                        MapChunk newChunk   = newChunkObject.AddComponent <MapChunk> ();
                        int      numOfChunk = (int)Mathf.Pow(2, maxLOD - 1);
                        newChunk.init(maxLOD, cellsForChunks [i, j], numOfChunk, numOfChunk);
                        newChunk.cellRenderer.material = defaultMaterial;
                        newChunk.updateMesh();
                        chunks.Add(newChunk);
                    }
                }
            }

            generatedChunk = true;
            yield return(updateWholeMap());
        }