示例#1
0
 void GenerateChunk(int x, int z)
 {
     if (!ChunkGenerated(x, z))
     {
         generated.Add(x, z, new Chunk(x, z, seed));
     }
 }
示例#2
0
        /// <summary>
        /// Tries to spawn a child chunk.
        /// </summary>
        /// <returns>The spawn chunk.</returns>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="z">The z coordinate.</param>
        public Chunk TrySpawnChunk(int x, int y, int z)
        {
            // create the key
            string key = GenerateKey(x, y, z);

            // exit if the key already exists
            if (ChunkDict.ContainsKey(key))
            {
                return(null);
            }

            // spawn the chunk, and parent it
            Chunk newChunk = Instantiate(_chunkPrefab, transform);

            // generate and set the position
            Vector3 localPos = LocalisedPositionFromGroupCoord(x, y, z);

            newChunk.transform.localPosition = localPos;

            // set basic values
            // name
            newChunk.name = "Chunk_" + key;
            // parent
            newChunk.Parent = this;
            // group coord
            newChunk.GroupCoord = new Vector3Int(x, y, z);
            newChunk.SetChunkVars(ChunkSize);

            ChunkDict.Add(key, newChunk);

            return(newChunk);
        }
示例#3
0
 void LoadChunk(int x, int z)
 {
     if (!ChunkLoaded(x, z))
     {
         GenerateChunk(x, z);
         GenerateChunk(x - 1, z);
         GenerateChunk(x + 1, z);
         GenerateChunk(x, z - 1);
         GenerateChunk(x, z + 1);
         loaded.Add(x, z, generated.Get(x, z));
         generated.Get(x, z).GenerateChunkMesh();
     }
 }