public override void MatchDidReceiveDataForRecipient(GKMatch match, NSData data, GKPlayer recipient, GKPlayer remotePlayer) { if (recipient != null && recipient.Equals(GKLocalPlayer.LocalPlayer)) { MatchDidReceiveData(match, data, remotePlayer); } }
void OnCustomFoundMatch(GKMatch match, NSError error) { if (error != null) { Log("Error with matchmaker: " + error.LocalizedDescription()); } else if (match != null) { // set the high-level match, and it will raise MatchMakerFoundMatch event RealTimeMatchesController.SetCurrentMatch(match); } }
private void SetupCurrentMatchAndListener(GKMatch match, IRealTimeMultiplayerListener listener) { mCurrentMatch = match; mCurrentListener = listener; if (mCurrentMatch != null) { mCurrentMatch.Delegate = new InternalGKMatchDelegateImpl(this); } }
public override void PlayerDidChangeState(GKMatch match, string playerID, GKPlayerConnectionState state) { Player.LoadPlayersByIDs(new string[] { playerID }, delegate(Player[] players) { var rtMatch = NSObjectWrapper.GetWrapper(match.Uuid) as RealTimeMatch; if ((rtMatch != null) && (rtMatch.gkMatch != null) && (players.Length > 0)) { rtMatch._OnPlayerStateChanged(players[0], state); } match = null; }); }
public override void DidReceive(GKMatch match, NSData data, string playerID) { Player.LoadPlayersByIDs(new string[] { playerID }, delegate(Player[] players) { var rtMatch = NSObjectWrapper.GetWrapper(match.Uuid) as RealTimeMatch; if ((rtMatch != null) && (players.Length > 0)) { rtMatch._OnReceiveData(players[0], data); } match = null; data = null; }); }
public override bool ShouldReinviteDisconnectedPlayer(GKMatch match, GKPlayer player) { var listener = mClient.mCurrentListener; if (listener == null || match == null || player == null) { return(false); } return(listener.ShouldReinviteDisconnectedPlayer(Participant.FromGKPlayer( player, GKPlayerConnectionState.Disconnected.ToParticipantStatus(), false ))); }
public override void MatchDidReceiveData(GKMatch match, NSData data, GKPlayer remotePlayer) { var listener = mClient.mCurrentListener; if (listener == null || match == null || data == null || remotePlayer == null) { return; } var bytes = data.ToBytes(); RuntimeHelper.RunOnMainThread(() => { listener.OnRealTimeMessageReceived(remotePlayer.PlayerID, bytes); }); }
public override void PlayerDidChangeConnectionState(GKMatch match, GKPlayer player, GKPlayerConnectionState state) { RuntimeHelper.RunOnMainThread(() => { var listener = mClient.mCurrentListener; if (listener == null || match == null || player == null) { return; } if (player.Equals(GKLocalPlayer.LocalPlayer)) { // In reality, this never runs because GameKit never reports // connection state changes of local player. if (state == GKPlayerConnectionState.Disconnected) { listener.OnLeftRoom(); } } else { if (state == GKPlayerConnectionState.Connected) { listener.OnPeersConnected(new string[] { player.PlayerID }); ReportRoomSetupProgress(listener, match, null, true); } else if (state == GKPlayerConnectionState.Disconnected) { if (match.ExpectedPlayerCount > 0) // player leaves during room setup { listener.OnParticipantLeft(Participant.FromGKPlayer(player, state.ToParticipantStatus(), false)); ReportRoomSetupProgress(listener, match, null, true); } else // player disconnected after match setup has completed { listener.OnPeersDisconnected(new string[] { player.PlayerID }); } } } }); }
/// <summary> /// U3DXT internal. /// </summary> /// <returns>The current match.</returns> /// <param name="">.</param> public static void SetCurrentMatch(GKMatch gkMatch) { if (gkMatch == null) { _currentMatch = null; return; } // resolve to wrapper and then dispatch event var rtmatch = NSObjectWrapper.CreateWrapper(typeof(RealTimeMatch), gkMatch) as RealTimeMatch; gkMatch = null; rtmatch.ReloadPlayers(delegate() { _currentMatch = rtmatch; if (_matchMakerFoundMatchHandlers != null) { _matchMakerFoundMatchHandlers(null, new MatchEventArgs(rtmatch)); } rtmatch = null; }); }
public void LeaveRoom() { if (mCurrentMatch != null) { // Disconnect the match. mCurrentMatch.Disconnect(); // Nil out the delegate as recommended by GameKit. // https://developer.apple.com/documentation/gamekit/gkmatch?language=objc mCurrentMatch.Delegate = null; if (mCurrentListener != null) { mCurrentListener.OnLeftRoom(); } // Reset current match and listener. mCurrentMatch.Dispose(); mCurrentMatch = null; mCurrentListener = null; } }
private static bool IsRoomSetupComplete(GKMatch match, out float progress) { if (match == null) { progress = 0; return(false); } // Setup succeeded or is progressing. var players = match.Players; uint joinedCount = players != null ? players.Count : 0; uint expectedCount = match.ExpectedPlayerCount; // GameKit doesn't count the local player as a joined player, // so we account for it by +1 manually. joinedCount++; // Now calculate the progress based on the number of joined players // compared to the total players needed. progress = joinedCount * 100f / (joinedCount + expectedCount); return(expectedCount == 0); }
public virtual void PlayerDidChangeConnectionState(GKMatch match, GKPlayer player, GKMatch.GKPlayerConnectionState state) { }
// Must be implemented. public abstract bool ShouldReinviteDisconnectedPlayer(GKMatch match, GKPlayer player);
public override void MatchmakerViewControllerDidFindMatch(GKMatchmakerViewController viewController, GKMatch match) { // Automatically close the VC. if (viewController != null) { viewController.DismissViewController(true, null); } mClient.ResetCurrentMatchmakerVC(); if (match == null) // should never happen { return; } // Set the newly created match as the current one. mClient.SetupCurrentMatchAndListener(match, mListener); // Report room setup completed. RuntimeHelper.RunOnMainThread(() => { ReportRoomSetupProgress(mListener, match, null); }); }
private static void ReportRoomSetupProgress(IRealTimeMultiplayerListener listener, GKMatch match, NSError error, bool programmaticMatchmaking = false) { if (listener == null) { return; } // Setup failed. if (match == null || error != null) { listener.OnRoomConnected(false); return; } // Setup succeeded or is progressing. float progress; bool completed = IsRoomSetupComplete(match, out progress); // On progress. listener.OnRoomSetupProgress(progress); // Connected. if (completed) { // Programmatic matchmaking has finished. if (programmaticMatchmaking) { GKMatchmaker.SharedMatchmaker().FinishMatchmakingForMatch(match); } listener.OnRoomConnected(true); } }
public virtual void MatchmakerViewControllerDidFindMatch(GKMatchmakerViewController viewController, GKMatch match) { }
public virtual void MatchDidReceiveData(GKMatch match, NSData data, GKPlayer remotePlayer) { }
public virtual void MatchDidFailWithError(GKMatch match, NSError error) { }
public override void DidFindMatch(GKMatchmakerViewController viewController, GKMatch match) { UIApplication.SharedApplication().keyWindow.rootViewController.DismissViewController(true, null); RealTimeMatchesController.SetCurrentMatch(match); }
/// <summary> /// U3DXT internal. /// </summary> /// <returns>The current match.</returns> /// <param name="">.</param> public static void SetCurrentMatch(GKMatch gkMatch) { if (gkMatch == null) { _currentMatch = null; return; } // resolve to wrapper and then dispatch event var rtmatch = NSObjectWrapper.CreateWrapper(typeof(RealTimeMatch), gkMatch) as RealTimeMatch; gkMatch = null; rtmatch.ReloadPlayers(delegate() { _currentMatch = rtmatch; if (_matchMakerFoundMatchHandlers != null) _matchMakerFoundMatchHandlers(null, new MatchEventArgs(rtmatch)); rtmatch = null; }); }
public override void DidFindMatch(GKMatchmakerViewController viewController, GKMatch match) { UIApplication.deviceRootViewController.DismissViewController(true, null); RealTimeMatchesController.SetCurrentMatch(match); }
public virtual void MatchDidReceiveDataForRecipient(GKMatch match, NSData data, GKPlayer recipient, GKPlayer remotePlayer) { }