Esempio n. 1
0
        /// <summary>Instantiates a new chunk at a given position</summary>
        /// <param name="pos">Position to create this chunk on in the world coordinates</param>
        /// <param name="chunk">Chunk at a given positon</param>
        /// <returns>Trus if a new chunk was created. False otherwise</returns>
        public bool CreateChunk(ref Vector3Int pos, out Chunk chunk)
        {
            Assert.IsTrue(Helpers.IsMainThread);

            chunk = null;

            // Transform the position into chunk coordinates
            Vector3Int chunkPos = Helpers.ContainingChunkPos(ref pos);

            // Let's keep it within allowed world bounds
            if (!IsCoordInsideWorld(ref chunkPos))
            {
                return(false);
            }

            chunk = GetChunk(ref chunkPos);
            if (chunk == null)
            {
                // Create a new chunk if it does not exist yet
                chunk = Chunk.Create(this, chunkPos);
                chunks.Add(chunkPos, chunk);
                return(true);
            }

            return(false);
        }