コード例 #1
0
 public MapChunk(
     Vector3 location,
     int xResolution,
     int zResolution,
     float scale,
     Material material,
     MeshFilter meshFilter,
     MeshRenderer meshRenderer,
     MeshCollider meshCollider,
     int i,
     int j,
     MapChanger mapChanger,
     MapChunksAccessor mapChunksAccessor)
 {
     Location               = location;
     XResolution            = xResolution;
     ZResolution            = zResolution;
     Scale                  = scale;
     Material               = material;
     _meshRenderer          = meshRenderer;
     _meshCollider          = meshCollider;
     _meshFilter            = meshFilter;
     _i                     = i;
     _j                     = j;
     XLocationAmongstChunks = _i;
     ZLocationAmongstChunks = _j;
     _mapChanger            = mapChanger;
     _mapChunksAccessor     = mapChunksAccessor;
 }
コード例 #2
0
 public MapChunk GenerateMap(int i, int j, MapChanger mapChanger, MapChunksAccessor MapChunksAccessor)
 {
     try
     {
         var frame = new MapChunk(
             Location,
             XResolution,
             ZResolution,
             Scale,
             Material,
             GetComponent <MeshFilter>(),
             GetComponent <MeshRenderer>(),
             GetComponent <MeshCollider>(),
             i,
             j,
             mapChanger,
             MapChunksAccessor);
         frame.Build();
         return(frame);
     }
     catch (Exception e)
     {
         print("MapChanger generator error: " + e.Message);
         throw e;
     }
 }
コード例 #3
0
        private MapChunk CreateTerrainChunk(int i, int j, MapChanger mapChanger, MapChunksAccessor MapChunksAccessor, Vector2 location, int chunkSizeX, int chunkSizeZ)
        {
            MapChunkBuilder chunk = Instantiate(mapChunkPrefab);

            chunk.Location    = new Vector3(location.x, 0, location.y);
            chunk.XResolution = chunkSizeX;
            chunk.ZResolution = chunkSizeZ;
            chunk.Scale       = 1;
            var frame = chunk.GenerateMap(i, j, mapChanger, MapChunksAccessor);

            chunk.transform.SetParent(transform);

            return(frame);
        }
コード例 #4
0
        void Awake()
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            var time1 = stopwatch.ElapsedMilliseconds;

            print("time1 " + time1);

            var chunksCountX = (int)Mathf.Ceil((float)xResolution / MaxResolutionOfSingleChunk);
            int chunkSizeX   = xResolution / chunksCountX;

            var chunksCountZ = (int)Mathf.Ceil((float)zResolution / MaxResolutionOfSingleChunk);
            int chunkSizeZ   = zResolution / chunksCountZ;

            var chunks = new MapChunk[chunksCountX, chunksCountZ];

            var MapChunksAccessor = new MapChunksAccessor();
            var mapChanger        = new MapChanger(
                xResolution,
                zResolution,
                MapChunksAccessor);


            for (int i = 0; i < chunksCountX; i++)
            {
                for (int j = 0; j < chunksCountZ; j++)
                {
                    chunks[i, j] = CreateTerrainChunk(i, j, mapChanger, MapChunksAccessor, new Vector2(i * chunkSizeX * meshScale, j * chunkSizeZ * meshScale), chunkSizeX, chunkSizeZ);
                }
            }

            MapChunksAccessor.Recalculate(mapChanger);

            var randomMapGenerator = new RandomMapGenerator(mapChanger);

            randomMapGenerator.GenerateFor();

            foreach (var mapChunk in chunks)
            {
                mapChunk.CommitChanges();
            }

            var time2 = stopwatch.ElapsedMilliseconds;

            print("time2 " + time2);
        }