Beispiel #1
0
        public static Chunk PositionToChunk(Vector3 p)
        {
            Index      idx = PositionToChunkIndex(p);
            GameObject g   = ChunkManager.GetChunk(idx);

            return((g == null) ? null : g.GetComponent <Chunk>());
        }
Beispiel #2
0
	public static GameObject PositionToChunk ( Vector3 position ) {
		Index chunkIndex = new Index (Mathf.RoundToInt(position.x / Engine.ChunkScale.x) / Engine.ChunkSideLength,
									  Mathf.RoundToInt(position.y / Engine.ChunkScale.y) / Engine.ChunkSideLength, 
									  Mathf.RoundToInt(position.z / Engine.ChunkScale.z) / Engine.ChunkSideLength);
		return ChunkManager.GetChunk (chunkIndex);
	
	}
Beispiel #3
0
        public static GameObject SpawnChunk(Index index)
        {         // spawns a single chunk (only if it's not already spawned)
            GameObject chunk = ChunkManager.GetChunk(index);

            if (chunk == null)
            {
                return(Engine.ChunkManagerInstance.DoSpawnChunk(index));
            }
            else
            {
                return(chunk);
            }
        }
Beispiel #4
0
        // ==== spawn chunks functions ====

        public static GameObject SpawnChunk(int x, int y, int z)      // spawns a single chunk (only if it's not already spawned)
        {
            GameObject chunk = ChunkManager.GetChunk(x, y, z);

            if (chunk == null)
            {
                return(Engine.ChunkManagerInstance.DoSpawnChunk(new Index(x, y, z)));
            }
            else
            {
                return(chunk);
            }
        }
        public void ReceiveChangeBlock(NetworkPlayer sender, int x, int y, int z, int chunkx, int chunky, int chunkz, int data)         // receives a change sent by other client or server
        {
            GameObject chunkObject = ChunkManager.GetChunk(chunkx, chunky, chunkz);

            if (chunkObject != null)
            {
                // convert back to VoxelInfo
                Index     voxelIndex = new Index(x, y, z);
                VoxelInfo info       = new VoxelInfo(voxelIndex, chunkObject.GetComponent <Chunk>());

                // apply change
                Voxel.ChangeBlockMultiplayer(info, (ushort)data, sender);
            }
        }
        public void ReceiveVoxelData(int chunkx, int chunky, int chunkz, byte[] data)
        {
            GameObject chunkObject = ChunkManager.GetChunk(chunkx, chunky, chunkz);    // find the chunk

            if (chunkObject == null)
            {
                return;                                 // abort if chunk isn't spawned anymore
            }
            Chunk chunk = chunkObject.GetComponent <Chunk>();

            ChunkDataFiles.DecompressData(chunk, GetString(data)); // decompress data
//		ChunkManager.DataReceivedCount ++; // let ChunkManager know that we have received the data
            chunk.VoxelsDone = true;                               // let Chunk know that it can update it's mesh
            Chunk.CurrentChunkDataRequests--;
        }
Beispiel #7
0
        public static GameObject SpawnChunkFromServer(Index index)
        {         // spawns a chunk and disables mesh generation and enables timeout (used by the server in multiplayer)
            GameObject chunk = ChunkManager.GetChunk(index);

            if (chunk == null)
            {
                chunk = Engine.ChunkManagerInstance.DoSpawnChunk(index);
                Chunk chunkComponent = chunk.GetComponent <Chunk>();
                chunkComponent.EnableTimeout = true;
                chunkComponent.DisableMesh   = true;
                return(chunk);
            }
            else
            {
                return(chunk);             // don't disable mesh generation and don't enable timeout for chunks that are already spawned
            }
        }
        public static bool DestroyChunk(Index index)
        {
            GameObject chunkObject = ChunkManager.GetChunk(index);

            if (chunkObject != null)
            {
                Chunk chunk = chunkObject.GetComponent <Chunk>();
                RemoveChunkFromUpdateQueue(chunk);
                chunk.FlagToRemove();
                Resources.UnloadUnusedAssets();
                return(true);
            }
            else
            {
                return(false);
            }
        }