Exemplo n.º 1
0
    /// <summary>Sends the client into the game and informs other clients of the new player.</summary>
    /// <param name="playerName">The username of the new player.</param>
    public void SendIntoGame(string playerName)
    {
        PlayerHandler player = GameManager.Get.InstantiatePlayer();

        player.Initialize(id, playerName);

        // Send all players to the new player
        foreach (PlayerHandler p in GameManager.Get.Players.Values)
        {
            if (p.id != id)
            {
                PacketSender.SpawnPlayer(id, p);
            }
        }

        // Send the new player to all players (including himself)
        foreach (ClientConnection client in Server.clients.Values)
        {
            PacketSender.SpawnPlayer(client.id, player);
        }

        GameManager.Get.AddPlayer(id, player);

        foreach (DroppedBlock block in GameManager.Get.DroppedBlocks.Values)
        {
            PacketSender.BlockDropped(id, block.ID, block.type, block.transform.position);
        }

        PacketSender.HeldItemChanged(id, player.inventory.HeldBlock);
    }
Exemplo n.º 2
0
        public static int Instantiate(BlockType type, Vector3 pos)
        {
            DroppedBlock block = Instantiate(GameManager.Get.droppedBlockPrefab, pos, Quaternion.identity).GetComponent <DroppedBlock>().Init(type);

            PacketSender.BlockDropped(block.ID, type, pos);
            GameManager.Get.DroppedBlocks.Add(block.ID, block);
            return(block.ID);
        }