Exemple #1
0
        public void OnChunkRecieve(ChunkPacket packet)
        {
            var chunkX = packet.X;
            var chunkY = packet.Y;
            var data   = packet.ChunkData;

            var chunkParent = new GameObject("chunk_" + chunkX + "_" + chunkY);

            Chunk c = new Chunk()
            {
                x = chunkX,
                y = chunkY
            };

            Debug.Log("Rendering Chunk " + chunkX + " " + chunkY);
            for (var x = 0; x < 16; x++)
            {
                for (var y = 0; y < 16; y++)
                {
                    var tileId = data[x, y];
                    c.SetTile(x, y, tileId);
                    TileFactory.BuildAndInstantiate(chunkX * 16 + x, chunkY * 16 + y, tileId, chunkParent);
                }
            }

            // To be a tracked chunk
            UnityClient.Map.AddChunk(c);
        }
Exemple #2
0
        public void OnChunkRecieve(ChunkPacket packet)
        {
            var chunkX = packet.X;
            var chunkY = packet.Y;
            var data   = packet.ChunkData;

            if (!UnityClient.Map.Chunks.Any(cp => cp.Key.Equals($"{chunkX}_{chunkY}")))
            {
                var chunkParent = new GameObject($"chunk_{chunkX}_{chunkY}");

                ClientChunk c = new ClientChunk()
                {
                    x          = chunkX,
                    y          = chunkY,
                    GameObject = chunkParent
                };

                Debug.Log("Rendering Chunk " + chunkX + " " + chunkY);
                for (var x = 0; x < 16; x++)
                {
                    for (var y = 0; y < 16; y++)
                    {
                        var tileId = data[x, y];

                        var tilePosition = new Position(chunkX * 16 + x, chunkY * 16 + y);

                        c.Tiles[x, y] = new MapTile(tilePosition, tileId);

                        TileFactory.BuildAndInstantiate(new TileOptions()
                        {
                            Parent   = chunkParent,
                            Position = tilePosition,
                            TileId   = tileId
                        });
                    }
                }

                // To be a tracked chunk
                UnityClient.Map.AddChunk(c);
            }
        }