Beispiel #1
0
        protected virtual IEnumerator Connect()
        {
            if (Provider == Providers.Photon)
            {
                var matchmaker  = new PhotonMatchmaker(_client);
                var matchmaker2 = new PhotonMatchmaker(_client2);

                yield return(UpdateUntilSubscription(
                                 Observable.WhenAll(
                                     matchmaker.ConnectToCloudWithSettings(_settings),
                                     matchmaker2.ConnectToCloudWithSettings(_settings)
                                     )
                                 ));

                yield return(UpdateUntilSubscription(
                                 matchmaker.CreateGame(PhotonCreateGameOptions.FromRoomName(PlaymodeTestUtils.RoomName))
                                 ));

                var game1 = (IGame)LastResult;

                yield return(UpdateUntilSubscription(
                                 matchmaker2.FindGame(PhotonGameQuery.FromRoomName(PlaymodeTestUtils.RoomName))
                                 ));

                var game2 = (IGame)LastResult;

                yield return(UpdateUntilSubscription(
                                 Observable.WhenAll(
                                     game1.ConnectWithPhoton(),
                                     game2.ConnectWithPhoton()
                                     )
                                 ));

                var connections = (IConnection[])LastResult;
                _connection  = connections[0];
                _connection2 = connections[1];
            }
            else if (Provider == Providers.Mock)
            {
                _connection  = new MockConnection(true, MockConnection.MockNetwork.Default);
                _connection2 = new MockConnection(false, MockConnection.MockNetwork.Default);
            }
            else if (Provider == Providers.LiteNetLib)
            {
                _connection  = LiteNetLibConnectionExperimental.CreateServer(5000, 2, "0.1", false);
                _connection2 = LiteNetLibConnectionExperimental.CreateClient("localhost", 5000, 2, "0.1", false);
            }
        }
Beispiel #2
0
        protected virtual IEnumerator Connect(int num, bool create)
        {
            if (Provider == Providers.Photon)
            {
                if (num < 0 || num > 1)
                {
                    throw new ArgumentException("Invalid service number", nameof(num));
                }

                var matchmaker = new PhotonMatchmaker(num == 0 ? _client : _client2);

                yield return(UpdateUntilSubscription(
                                 matchmaker.ConnectToCloudWithSettings(_settings)
                                 ));

                if (create)
                {
                    yield return(UpdateUntilSubscription(
                                     matchmaker.CreateGame(PhotonCreateGameOptions.FromRoomName(PlaymodeTestUtils.RoomName))
                                     ));
                }
                else
                {
                    yield return(UpdateUntilSubscription(
                                     matchmaker.FindGame(PhotonGameQuery.FromRoomName(PlaymodeTestUtils.RoomName))
                                     ));
                }

                var game = (IGame)LastResult;

                yield return(UpdateUntilSubscription(game.ConnectWithPhoton()));

                var connection = (IConnection)LastResult;

                if (num == 0)
                {
                    _connection = connection;
                }
                else
                {
                    _connection2 = connection;
                }
            }
            else if (Provider == Providers.Mock)
            {
                if (num == 0)
                {
                    _connection = new MockConnection(true, MockConnection.MockNetwork.Default);
                }
                else
                {
                    _connection2 = new MockConnection(false, MockConnection.MockNetwork.Default);
                }
            }
            else if (Provider == Providers.LiteNetLib)
            {
                IConnection connection;
                if (create)
                {
                    connection = LiteNetLibConnectionExperimental.CreateServer(5000, 2, "0.1", false);
                }
                else
                {
                    connection = LiteNetLibConnectionExperimental.CreateClient("localhost", 5000, 2, "0.1", false);
                }

                if (num == 0)
                {
                    _connection = connection;
                }
                else
                {
                    _connection2 = connection;
                }
            }
        }