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);
            }
        }
Exemple #2
0
 /// <summary>
 /// Initializes the controller. You must call this after subscribing to real-time match events.
 /// </summary>
 public static void Init()
 {
     if (!_init)
     {
         GKMatchmaker.SharedMatchmaker().inviteHandler = _MatchInviteHandler;
         _init = true;
     }
 }
Exemple #3
0
    void CreateMeetingCustom()
    {
        Log("Creating meeting with custom UI.");

        var request = new GKMatchRequest();

        request.minPlayers = 2;
        request.maxPlayers = 4;

        GKMatchmaker.SharedMatchmaker().FindMatch(request, OnCustomFoundMatch);
    }
 /// <summary>
 /// Initializes the controller. You must call this after subscribing to real-time match events.
 /// </summary>
 public static void Init()
 {
     if (!_init)
     {
         if (GKLocalPlayer.InstancesRespondToSelector("registerListener:"))
         {
             LocalPlayerListener.instance.Register();
         }
         else
         {
             GKMatchmaker.SharedMatchmaker().inviteHandler = _MatchInviteHandler;
         }
         _init = true;
     }
 }
        public void AcceptInvitation(Invitation invitation, bool showWaitingRoomUI, IRealTimeMultiplayerListener listener)
        {
            Util.NullArgumentTest(invitation);
            Util.NullArgumentTest(listener);

            if (showWaitingRoomUI)
            {
                // Close the current matchmakerVC if any.
                if (mCurrentMatchmakerVC != null)
                {
                    mCurrentMatchmakerVC.DismissViewController(true, null);
                    mCurrentMatchmakerVC = null;
                }

                // Create a new GKMatchmakerViewController from the invitation.
                var vc = InteropObjectFactory <GKMatchmakerViewController> .Create(
                    () => new GKMatchmakerViewController(invitation.GK_Invite),
                    viewController => viewController.ToPointer()
                    );

                // Create a delgate for the vc.
                vc.MatchmakerDelegate = new InternalGKMatchmakerViewControllerDelegateImpl(this, listener);

                // Store the VC ref.
                mCurrentMatchmakerVC = vc;

                // Now show the VC.
                using (var unityVC = UIViewController.UnityGetGLViewController())
                    unityVC.PresentViewController(vc, true, null);
            }
            else
            {
                // Create a GKMatch from the invitation without any UI.
                GKMatchmaker.SharedMatchmaker().MatchForInvite(invitation.GK_Invite, (gkMatch, nsError) =>
                {
                    // If new match is created successfully, store it and the given listener.
                    if (gkMatch != null)
                    {
                        SetupCurrentMatchAndListener(gkMatch, listener);
                    }

                    RuntimeHelper.RunOnMainThread(() =>
                    {
                        ReportRoomSetupProgress(listener, gkMatch, nsError);
                    });
                });
            }
        }
        public void CreateQuickMatch(MatchRequest request, IRealTimeMultiplayerListener listener)
        {
            Util.NullArgumentTest(request);
            Util.NullArgumentTest(listener);

            using (var gkReq = request.ToGKMatchRequest())
            {
                GKMatchmaker.SharedMatchmaker().FindMatchForRequest(gkReq, (gkMatch, nsError) =>
                {
                    // If new match is created successfully, store it and the given listener.
                    if (gkMatch != null)
                    {
                        SetupCurrentMatchAndListener(gkMatch, listener);
                    }

                    RuntimeHelper.RunOnMainThread(() =>
                    {
                        ReportRoomSetupProgress(listener, gkMatch, nsError);
                    });
                });
            }
        }