Beispiel #1
0
    public void OnClientDisconnected(int connectionId)
    {
        var playerId = playerIdsByConnectionId[connectionId];

        var playerObject = PlayerObjectSystem.Instance.FindPlayerObject(playerId);

        if (playerObject != null)
        {
            Object.Destroy(playerObject);
        }

        var playerComponent = PlayerObjectSystem.Instance.FindPlayerComponent(playerId);
        var playerName      = playerComponent.State.Name;

        Object.Destroy(playerComponent.gameObject);

        playerIdsByConnectionId.Remove(connectionId);

        // Send out a chat message.
        ServerPeer.CallRpcOnAllClients("ClientOnReceiveChatMessage", ServerPeer.reliableSequencedChannelId, new
        {
            playerId = (uint?)null,
            message  = $"{playerName} left."
        });
    }