/** * <summary>Given RtSession details will establish the Real Time Session connection</summary> * <param name="s">RtSession details of the Real Time session to connect to</param> */ public void ConnectSession(RtSession s) { _gameSparksRtUnity.Configure( new FindMatchResponse(new GSRequestData() // In order to create a new RtSession .AddString("host", s.HostUrl) // we need a 'FindMatchResponse' that .AddNumber("port", (double)s.PortId) // we can then us to configure a Real .AddString("accessToken", s.AccessToken)), // Time Session from // OnPlayerConnected / Disconnected Callbacks peerId => { OnLogEntry(LogEntryFactory.CreatePeerConnectedLogEntry(peerId)); }, peerId => { OnLogEntry(LogEntryFactory.CreatePeerDisconnectedLogEntry(peerId)); }, state => // OnRtReady Callback { OnLogEntry(LogEntryFactory.CreateSessionStateLogEntry(state)); foreach (var l in _onRtReady) { l(state); } }, packet => // OnPacketReceived Callback { switch (packet.OpCode) { case (int)OpCode.Ping: OnPingReceived(packet); break; case (int)OpCode.Pong: OnPongReceived(packet); break; default: OnPacketReceived(packet); break; } }); _rtConnected = true; _gameSparksRtUnity.Connect(); // Connect OnLogEntry(LogEntryFactory.CreateSessionJoinLogEntry()); }
/** * <summary>Given RtSession details will establish the Real Time Session connection</summary> * <param name="s">RtSession details of the Real Time session to connect to</param> */ public void ConnectSession(RtSession s) { _gameSparksRtUnity.Configure( // Note a MatchFoundMessage can also be used here. // Gets the message needed to configure a real time session. GetMatchFoundResponse(s), // OnPlayerConnected / Disconnected Callbacks peerId => { OnLogEntry(LogEntryFactory.CreatePeerConnectedLogEntry(peerId)); }, peerId => { OnLogEntry(LogEntryFactory.CreatePeerDisconnectedLogEntry(peerId)); }, state => // OnRtReady Callback { _rtConnected = state; foreach (var l in _onRtReady) { l(state); } OnLogEntry(LogEntryFactory.CreateSessionStateLogEntry(state)); }, packet => // OnPacketReceived Callback { switch (packet.OpCode) { case (int)OpCode.Ping: OnPingReceived(packet); return; case (int)OpCode.Pong: OnPongReceived(packet); return; default: OnPacketReceived(packet); return; } }); _gameSparksRtUnity.Connect(); // Connect OnLogEntry(LogEntryFactory.CreateSessionJoinLogEntry()); }