예제 #1
0
 public override void MatchDidReceiveDataForRecipient(GKMatch match, NSData data, GKPlayer recipient, GKPlayer remotePlayer)
 {
     if (recipient != null && recipient.Equals(GKLocalPlayer.LocalPlayer))
     {
         MatchDidReceiveData(match, data, remotePlayer);
     }
 }
예제 #2
0
 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);
     }
 }
예제 #3
0
        private void SetupCurrentMatchAndListener(GKMatch match, IRealTimeMultiplayerListener listener)
        {
            mCurrentMatch    = match;
            mCurrentListener = listener;

            if (mCurrentMatch != null)
            {
                mCurrentMatch.Delegate = new InternalGKMatchDelegateImpl(this);
            }
        }
예제 #4
0
 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);
     }
 }
예제 #5
0
        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;
            });
        }
예제 #6
0
        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;
            });
        }
예제 #7
0
            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
                                                                     )));
            }
예제 #8
0
            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);
                });
            }
예제 #9
0
            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 });
                            }
                        }
                    }
                });
            }
예제 #10
0
        /// <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;
            });
        }
예제 #11
0
        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;
            }
        }
예제 #12
0
        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);
        }
예제 #13
0
 public virtual void PlayerDidChangeConnectionState(GKMatch match, GKPlayer player, GKMatch.GKPlayerConnectionState state)
 {
 }
예제 #14
0
 // Must be implemented.
 public abstract bool ShouldReinviteDisconnectedPlayer(GKMatch match, GKPlayer player);
예제 #15
0
            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);
                });
            }
예제 #16
0
        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);
            }
        }
예제 #17
0
 public virtual void MatchmakerViewControllerDidFindMatch(GKMatchmakerViewController viewController, GKMatch match)
 {
 }
예제 #18
0
 public virtual void MatchDidReceiveData(GKMatch match, NSData data, GKPlayer remotePlayer)
 {
 }
예제 #19
0
 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);
        }
예제 #21
0
        /// <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);
        }
예제 #23
0
 public virtual void MatchDidReceiveDataForRecipient(GKMatch match, NSData data, GKPlayer recipient, GKPlayer remotePlayer)
 {
 }