Exemple #1
0
    public async void Matchmake(User user)
    {
        try
        {
            client = new Colyseus.Client("ws://10.57.30.20:2567");
            room   = await client.JoinOrCreate <State>("game");

            await Task.Delay(1000);

            await room.Send(
                new
            {
                userInfo =
                    new
                {
                    user.DeviceID,
                    user.Gender,
                    user.Name,
                    user.Star,
                    user.Age
                }
            });

            room.State.players.OnAdd    += Players_OnAdd;
            room.State.players.OnChange += Players_OnChange;
            room.State.OnChange         += State_OnChange;
            room.OnError += Room_OnError;

            numPlayers++;

            if (room.State.players.Count == 2)
            {
                playernumber = 2;
                USER value = ((PlayerSchema)(room.State.players.Items[0])).User;

                EnemyInfoReceived?.Invoke(new User()
                {
                    Age    = (int)value.Age,
                    Name   = value.Name,
                    Star   = value.Star,
                    Gender = value.Gender
                });

                PlayersConnected?.Invoke(true);
            }
        }
        catch (Exception e)
        {
            PlayersConnected?.Invoke(false);
            Debug.Log("Error: " + e.Message);
        }
    }
Exemple #2
0
    private void Players_OnAdd(PlayerSchema value, string key)
    {
        numPlayers++;

        Debug.Log("A player has joined");

        if (numPlayers == 2)
        {
            Debug.LogWarning("changing scenes");

            PlayersConnected?.Invoke(true);
        }
    }