//Starts the game session
        public void StartNewRTSession(RTSessionInfo _info)
        {
            //if the settings arent null
            if (gameSparksRTUnity == null)
            {
                Debug.Log("GSM| Creating New RT Session Instance...");
                sessionInfo       = _info;                                              //player/session information
                gameSparksRTUnity = this.gameObject.AddComponent <GameSparksRTUnity>(); //add the RT script to the manager
                GSRequestData mockedResponse = new GSRequestData();                     //create a new request
                mockedResponse.AddNumber("port", (double)_info.GetPortID());            //gets the port id
                mockedResponse.AddString("host", _info.GetHostURL());                   //gets host server
                mockedResponse.AddString("accessToken", _info.GetAccessToken());        // construct a dataset from the game-details
                FindMatchResponse response = new FindMatchResponse(mockedResponse);     //create a mock response for match

                //configures the game
                gameSparksRTUnity.Configure(response,
                                            (peerId) => { OnPlayerConnectedToGame(peerId); },
                                            (peerId) => { OnPlayerDisconnected(peerId); },
                                            (ready) => { OnRTReady(ready); },
                                            (packet) => { OnPacketReceived(packet); });
                gameSparksRTUnity.Connect(); // when the config is set, connect the game
            }
            else
            {
                Debug.LogError("Session Already Started");
            }
        }
示例#2
0
 //Once a match is found, a message will be received. this will hold player details and such
 private void OnMatchFound(MatchFoundMessage _message)
 {
     matchDetails.text = "Match Found...";
     tempRTSessionInfo = new RTSessionInfo(_message); // we'll store the match data until we need to create an RT session instance
 }