public void StartNewRTSession(RTSessionInfo _info) { Debug.Log("GSM| Creating New RT Session Instance..."); sessionInfo = _info; gameSparksRTUnity = this.gameObject.AddComponent <GameSparksRTUnity>(); // Adds the RT script to the game // In order to create a new RT game we need a 'FindMatchResponse' // // This would usually come from the server directly after a successful MatchmakingRequest // // However, in our case, we want the game to be created only when the first player decides using a button // // therefore, the details from the response is passed in from the gameInfo and a mock-up of a FindMatchResponse // // is passed in. // GSRequestData mockedResponse = new GSRequestData() .AddNumber("port", (double)_info.GetPortID()) .AddString("host", _info.GetHostURL()) .AddString("accessToken", _info.GetAccessToken()); // construct a dataset from the game-details FindMatchResponse response = new FindMatchResponse(mockedResponse); // create a match-response from that data and pass it into the game-config // So in the game-config method we pass in the response which gives the instance its connection settings // // In this example, I use a lambda expression to pass in actions for // OnPlayerConnect, OnPlayerDisconnect, OnReady and OnPacket actions // // These methods are self-explanatory, but the important one is the OnPacket Method // // this gets called when a packet is received // 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 }
public void StartNewRTSession(RTSessionInfo _info) { Debug.Log("GSM| Creating New RT Session Instance..."); sessionInfo = _info; gameSparksRTUnity = this.gameObject.AddComponent <GameSparksRTUnity>(); GSRequestData mockedResponse = new GSRequestData() .AddNumber("port", (double)_info.GetPortID()) .AddString("host", _info.GetHostURL()) .AddString("accessToken", _info.GetAccessToken()); FindMatchResponse response = new FindMatchResponse(mockedResponse); gameSparksRTUnity.Configure(response, (peerId) => { OnPlayerConnectedToGame(peerId); }, (peerId) => { OnPlayerDisconnected(peerId); }, (ready) => { OnRTReady(ready); }, (packet) => { OnPacketReceived(packet); }); gameSparksRTUnity.Connect(); }