Exemple #1
0
 private void CreateAndUpdateChunk(int i, int j, TerrainChunkData data)
 {
     _terrainChunks[i][j] = new TerrainChunk(data, transform);
     _chunksLods[i][j]    = new ChunkLod(data);
     _chunksLods[i][j].IsThereNewData(0, 0);
     _chunkMeshDatas[i][j] = _chunksLods[i][j].GetNewData();
     _terrainChunks[i][j].UpdateChunk(_chunkMeshDatas[i][j]);
 }
Exemple #2
0
        IEnumerator BuilWorldMesh()
        {
            var w           = ServiceLocator.I.TerrainData.GetMapSize() - 1;
            var u           = (Consts.UnitDataSize - 1);
            var unitsNumber = Mathf.CeilToInt((float)w / u) + 1;
            var bounds      = Mathf.FloorToInt((u * unitsNumber - w) / 2.0f);
            var middle      = (unitsNumber * Consts.UnitSize) / 2.0f;

            _chunksLods     = new ChunkLod[unitsNumber][];
            _terrainChunks  = new TerrainChunk[unitsNumber][];
            _chunkMeshDatas = new TerrainChunkMeshData[unitsNumber][];

            for (int i = 0; i < unitsNumber; i++)
            {
                _chunksLods[i]     = new ChunkLod[unitsNumber];
                _terrainChunks[i]  = new TerrainChunk[unitsNumber];
                _chunkMeshDatas[i] = new TerrainChunkMeshData[unitsNumber];
                for (int j = 0; j < unitsNumber; j++)
                {
                    var data = new TerrainChunkData()
                    {
                        HeigthData = ServiceLocator.I.TerrainData.GetBaseData(i, j, Consts.UnitDataSize, bounds),
                        Origin     = new Int2(i * (Consts.UnitDataSize - 1) - bounds, j * (Consts.UnitDataSize - 1) - bounds),
                        MaxHeight  = Consts.MaxHight,
                        UnitSize   = Consts.UnitSize,
                        Position   = new Vector3(((i - 1) * Consts.UnitSize) - middle, 0, ((j - 1) * Consts.UnitSize) - middle)
                    };

                    CreateAndUpdateChunk(i, j, data);
                }
                yield return(null);
            }

            ServiceLocator.I.EventsHolder.CameraPositionChangedEvent += OnCameraPositionChangedEvent;

            _isUpdateTaskActive = true;


            var t = new Thread(UpdateTask)
            {
                Priority = ThreadPriority.Normal
            };

            t.Start();
        }