public void CreateWithMatchmakerUI(MatchRequest request, IRealTimeMultiplayerListener listener) { Util.NullArgumentTest(request); Util.NullArgumentTest(listener); if (mCurrentMatchmakerVC != null) { Debug.Log("Ignoring CreateWithMatchmakerUI call because another matchmaker UI is being shown."); return; } // Create a new GKMatchmakerViewController. var vc = InteropObjectFactory <GKMatchmakerViewController> .Create( () => { using (var gkReq = request.ToGKMatchRequest()) return(new GKMatchmakerViewController(gkReq)); }, viewController => { return(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); }
/// <summary> /// Brings up the match making interface to start a real-time match with other players. /// Raises MatchMakerFoundMatch, MatchMakerCancelled, and MatchMakerFailed events. /// </summary> /// <param name="minPlayers">The minimum nubmer of players that can join a match; between 2 and 4 inclusively.</param> /// <param name="maxPlayers">The maximum number of players that can join a match; between 2 and 4 inclusively.</param> /// <param name="playerGroup">The group this player belongs to such as skill level; Game Center will match players with the same playerGroup.</param> /// <param name="playerAttributes">The attributes of this player such as white or black pieces in chest; Game Center will try to match players so that all bits of this attribute are filled by all players of a game.</param> /// <param name="playersToInvite">An array of Player instances; this is passed in from the PlayersInvited event.</param> public static void StartMatch(uint minPlayers, uint maxPlayers, uint playerGroup = 0, uint playerAttributes = 0, Player[] playersToInvite = null) { if ((minPlayers < 2) || (minPlayers > 4) || (maxPlayers < 2) || (maxPlayers > 4) || (maxPlayers < minPlayers)) { throw new U3DXTException("minPlayers and maxPlayers must be between 2 and 4."); } _currentMatch = null; // create request var request = new GKMatchRequest(); request.minPlayers = minPlayers; request.maxPlayers = maxPlayers; request.playerGroup = playerGroup; request.playerAttributes = playerAttributes; if (playersToInvite != null) { request.playersToInvite = Player.PlayersToIDs(playersToInvite); } // create view controller var mmvc = new GKMatchmakerViewController(request); // set delegate mmvc.matchmakerDelegate = MatchmakerViewControllerDelegate.instance; // show it UIApplication.deviceRootViewController.PresentViewController(mmvc, true, null); }
/// <summary> /// Displays the iOS matchmaker to the player. /// </summary> /// <remarks> /// Note this is not overloaded in derived classes on purpose. This is /// only a reason this exists is for caching effects. /// </remarks> /// <param name="minPlayers">Minimum players to find</param> /// <param name="maxPlayers">Maximum players to find</param> /// <param name="playersToInvite">Players to invite</param> public static void ShowMatchMaker(int minPlayers, int maxPlayers, string[] playersToInvite) { AssertInitialised(); if ((Gamer.SignedInGamers.Count > 0) && (Gamer.SignedInGamers[0].IsSignedInToLive)) { var matchmakerViewController = new GKMatchmakerViewController(new GKMatchRequest()); matchmakerViewController.DidFailWithError += delegate(object sender, GKErrorEventArgs e) { HideViewController(matchmakerViewController); }; matchmakerViewController.DidFindMatch += delegate(object sender, GKMatchEventArgs e) { Guide.Match = e.Match; }; matchmakerViewController.DidFindPlayers += delegate(object sender, GKPlayersEventArgs e) { }; matchmakerViewController.WasCancelled += delegate(object sender, EventArgs e) { HideViewController(matchmakerViewController); }; matchmakerViewController.MatchRequest.MinPlayers = minPlayers; matchmakerViewController.MatchRequest.MaxPlayers = maxPlayers; matchmakerViewController.MatchRequest.PlayersToInvite = playersToInvite; ShowViewController(matchmakerViewController); } }
public override void MatchmakerViewControllerWasCancelled(GKMatchmakerViewController viewController) { // Close the VC. if (viewController != null) { viewController.DismissViewController(true, null); } mClient.ResetCurrentMatchmakerVC(); }
/// <summary> /// Displays the iOS matchmaker to the player. /// </summary> /// <remarks> /// Note this is not overloaded in derived classes on purpose. This is /// only a reason this exists is for caching effects. /// </remarks> /// <param name="minPlayers">Minimum players to find</param> /// <param name="maxPlayers">Maximum players to find</param> /// <param name="playersToInvite">Players to invite/param> public static void ShowMatchMaker(int minPlayers, int maxPlayers, string[] playersToInvite) { AssertInitialised(); if ((Gamer.SignedInGamers.Count > 0) && (Gamer.SignedInGamers[0].IsSignedInToLive)) { // Lazy load it if (matchmakerViewController == null) { matchmakerViewController = new GKMatchmakerViewController(new GKMatchRequest()); } if (matchmakerViewController != null) { matchmakerViewController.MatchRequest.MinPlayers = minPlayers; matchmakerViewController.MatchRequest.MaxPlayers = maxPlayers; matchmakerViewController.MatchRequest.PlayersToInvite = playersToInvite; matchmakerViewController.DidFailWithError += delegate(object sender, GKErrorEventArgs e) { matchmakerViewController.DismissModalViewControllerAnimated(true); IsVisible = false; TouchPanel.EnabledGestures = prevGestures; }; matchmakerViewController.DidFindMatch += delegate(object sender, GKMatchEventArgs e) { Guide.Match = e.Match; }; matchmakerViewController.DidFindPlayers += delegate(object sender, GKPlayersEventArgs e) { }; matchmakerViewController.WasCancelled += delegate(object sender, EventArgs e) { matchmakerViewController.DismissModalViewControllerAnimated(true); IsVisible = false; TouchPanel.EnabledGestures = prevGestures; }; if (_window != null) { if (viewController == null) { viewController = new GuideViewController(_gameViewController); _window.Add(viewController.View); viewController.View.Hidden = true; } prevGestures = TouchPanel.EnabledGestures; TouchPanel.EnabledGestures = GestureType.None; viewController.PresentModalViewController(matchmakerViewController, true); IsVisible = 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 static void ShowMatchMaker() { if ((Gamer.SignedInGamers.Count > 0) && (Gamer.SignedInGamers[0].IsSignedInToLive)) { // Lazy load it if (matchmakerViewController == null) { matchmakerViewController = new GKMatchmakerViewController(); } if (matchmakerViewController != null) { matchmakerViewController.DidFailWithError += delegate(object sender, GKErrorEventArgs e) { matchmakerViewController.DismissModalViewControllerAnimated(true); isVisible = false; TouchPanel.EnabledGestures = prevGestures; }; matchmakerViewController.DidFindMatch += delegate(object sender, GKMatchEventArgs e) { }; matchmakerViewController.DidFindPlayers += delegate(object sender, GKPlayersEventArgs e) { }; matchmakerViewController.WasCancelled += delegate(object sender, EventArgs e) { matchmakerViewController.DismissModalViewControllerAnimated(true); isVisible = false; TouchPanel.EnabledGestures = prevGestures; }; if (Window != null) { if (viewController == null) { viewController = new GameVc(); Window.Add(viewController.View); viewController.View.Hidden = true; } prevGestures = TouchPanel.EnabledGestures; TouchPanel.EnabledGestures = GestureType.None; viewController.PresentModalViewController(matchmakerViewController, true); isVisible = true; } } } }
/// <summary> /// Brings up the Game Center match maker interface to add players to the game after some players have disconnected. /// Use the same params as when you called RealTimeMatchesController.StartMatch(). /// </summary> /// <param name="minPlayers">Minimum players.</param> /// <param name="maxPlayers">Max players.</param> /// <param name="playerGroup">Player group.</param> /// <param name="playerAttributes">Player attributes.</param> /// <seealso cref="RealTimeMatchesController.StartMatch()"/> public void AddPlayers(uint minPlayers, uint maxPlayers, uint playerGroup = 0, uint playerAttributes = 0) { if ((minPlayers < 2) || (minPlayers > 4) || (maxPlayers < 2) || (maxPlayers > 4) || (maxPlayers < minPlayers)) { throw new U3DXTException("minPlayers and maxPlayers must be between 2 and 4."); } var request = new GKMatchRequest(); request.minPlayers = minPlayers; request.maxPlayers = maxPlayers; request.playerGroup = playerGroup; request.playerAttributes = playerAttributes; var mmvc = new GKMatchmakerViewController(request); mmvc.matchmakerDelegate = MatchmakerViewControllerDelegate.instance; UIApplication.deviceRootViewController.PresentViewController(mmvc, true, null); }
internal static void _MatchInviteHandler(GKInvite acceptedInvite, object[] playersToInvite) { if (acceptedInvite != null) { // show new view controller var mmvc = new GKMatchmakerViewController(acceptedInvite); mmvc.matchmakerDelegate = MatchmakerViewControllerDelegate.instance; UIApplication.deviceRootViewController.PresentViewController(mmvc, true, null); // load players and dispatch event Player.LoadPlayersByIDs(new string[] { acceptedInvite.inviter }, delegate(Player[] players) { if (players.Length > 0) { if (_inviteAcceptedHandlers != null) { _inviteAcceptedHandlers(null, new InviteAcceptedEventArgs(players[0], acceptedInvite.playerGroup, acceptedInvite.playerAttributes)); } } acceptedInvite = null; }); mmvc = null; } else if (playersToInvite != null) { // load players and dispatch event Player.LoadPlayersByIDs(playersToInvite.Cast <string>().ToArray(), delegate(Player[] players) { if (players.Length > 0) { if (_playersInvitedHandlers != null) { _playersInvitedHandlers(null, new PlayersInvitedEventArgs(players)); } } }); } }
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); }); }
public override void WasCancelled(GKMatchmakerViewController viewController) { UIApplication.deviceRootViewController.DismissViewController(true, null); RealTimeMatchesController._OnMatchMakerCancelled(); }
public virtual void MatchmakerViewControllerDidFindHostedPlayers(GKMatchmakerViewController viewController, NSArray <GKPlayer> players) { }
public override void DidFail(GKMatchmakerViewController viewController, NSError error) { UIApplication.deviceRootViewController.DismissViewController(true, null); RealTimeMatchesController._OnMatchMakerFailed(error); }
public virtual void MatchmakerViewControllerWasCancelled(GKMatchmakerViewController viewController) { }
public override void DidFail(GKMatchmakerViewController viewController, NSError error) { UIApplication.SharedApplication().keyWindow.rootViewController.DismissViewController(true, null); RealTimeMatchesController._OnMatchMakerFailed(error); }
public override void WasCancelled(GKMatchmakerViewController viewController) { UIApplication.SharedApplication().keyWindow.rootViewController.DismissViewController(true, null); RealTimeMatchesController._OnMatchMakerCancelled(); }
public virtual void MatchmakerViewControllerDidFailWithError(GKMatchmakerViewController viewController, NSError error) { }
/// <summary> /// Displays the iOS matchmaker to the player. /// </summary> /// <remarks> /// Note this is not overloaded in derived classes on purpose. This is /// only a reason this exists is for caching effects. /// </remarks> /// <param name="minPlayers">Minimum players to find</param> /// <param name="maxPlayers">Maximum players to find</param> /// <param name="playersToInvite">Players to invite</param> public static void ShowMatchMaker(int minPlayers, int maxPlayers, string[] playersToInvite) { AssertInitialised(); if ((Gamer.SignedInGamers.Count > 0) && (Gamer.SignedInGamers[0].IsSignedInToLive)) { var matchmakerViewController = new GKMatchmakerViewController(new GKMatchRequest()); matchmakerViewController.DidFailWithError += delegate(object sender, GKErrorEventArgs e) { HideViewController(matchmakerViewController); }; matchmakerViewController.DidFindMatch += delegate(object sender, GKMatchEventArgs e) { Guide.Match = e.Match; }; matchmakerViewController.DidFindPlayers += delegate(object sender, GKPlayersEventArgs e) { }; matchmakerViewController.WasCancelled += delegate(object sender, EventArgs e) { HideViewController(matchmakerViewController); }; matchmakerViewController.MatchRequest.MinPlayers = minPlayers; matchmakerViewController.MatchRequest.MaxPlayers = maxPlayers; matchmakerViewController.MatchRequest.PlayersToInvite = playersToInvite; ShowViewController(matchmakerViewController); } }
public virtual void MatchmakerViewControllerHostedPlayerDidAccept(GKMatchmakerViewController viewController, GKPlayer player) { }
public virtual void MatchmakerViewControllerDidFindMatch(GKMatchmakerViewController viewController, GKMatch match) { }
private void ResetCurrentMatchmakerVC() { mCurrentMatchmakerVC = null; }
public override void WasCancelled(GKMatchmakerViewController viewController) { UIApplication.deviceRootViewController.DismissViewController(true, null); RealTimeMatchesController._OnMatchMakerCancelled(); }
public static void ShowMatchMaker() { if ( ( Gamer.SignedInGamers.Count > 0 ) && ( Gamer.SignedInGamers[0].IsSignedInToLive ) ) { // Lazy load it if ( matchmakerViewController == null ) { matchmakerViewController = new GKMatchmakerViewController(); } if (matchmakerViewController != null) { matchmakerViewController.DidFailWithError += delegate(object sender, GKErrorEventArgs e) { matchmakerViewController.DismissModalViewControllerAnimated(true); isVisible = false; }; matchmakerViewController.DidFindMatch += delegate(object sender, GKMatchEventArgs e) { }; matchmakerViewController.DidFindPlayers += delegate(object sender, GKPlayersEventArgs e) { }; matchmakerViewController.WasCancelled += delegate(object sender, EventArgs e) { matchmakerViewController.DismissModalViewControllerAnimated(true); isVisible = false; }; if (Window !=null) { if(viewController == null) { viewController = new GameVc(); Window.Add(viewController.View); viewController.View.Hidden = true; } viewController.PresentModalViewController(matchmakerViewController, true); isVisible = true; } } } }
/// <summary> /// Brings up the Game Center match maker interface to add players to the game after some players have disconnected. /// Use the same params as when you called RealTimeMatchesController.StartMatch(). /// </summary> /// <param name="minPlayers">Minimum players.</param> /// <param name="maxPlayers">Max players.</param> /// <param name="playerGroup">Player group.</param> /// <param name="playerAttributes">Player attributes.</param> /// <seealso cref="RealTimeMatchesController.StartMatch()"/> public void AddPlayers(uint minPlayers, uint maxPlayers, uint playerGroup = 0, uint playerAttributes = 0) { if ((minPlayers < 2) || (minPlayers > 4) || (maxPlayers < 2) || (maxPlayers > 4) || (maxPlayers < minPlayers)) throw new U3DXTException("minPlayers and maxPlayers must be between 2 and 4."); var request = new GKMatchRequest(); request.minPlayers = minPlayers; request.maxPlayers = maxPlayers; request.playerGroup = playerGroup; request.playerAttributes = playerAttributes; var mmvc = new GKMatchmakerViewController(request); mmvc.matchmakerDelegate = MatchmakerViewControllerDelegate.instance; UIApplication.SharedApplication().keyWindow.rootViewController.PresentViewController(mmvc, true, null); }
public override void DidFindMatch(GKMatchmakerViewController viewController, GKMatch match) { UIApplication.deviceRootViewController.DismissViewController(true, null); RealTimeMatchesController.SetCurrentMatch(match); }
public override void MatchmakerViewControllerDidFailWithError(GKMatchmakerViewController viewController, NSError error) { Debug.Log("MatchmakerViewControllerDidFailWithError: " + (error != null ? error.LocalizedDescription : "null")); }
/// <summary> /// Brings up the match making interface to start a real-time match with other players. /// Raises MatchMakerFoundMatch, MatchMakerCancelled, and MatchMakerFailed events. /// </summary> /// <param name="minPlayers">The minimum nubmer of players that can join a match; between 2 and 4 inclusively.</param> /// <param name="maxPlayers">The maximum number of players that can join a match; between 2 and 4 inclusively.</param> /// <param name="playerGroup">The group this player belongs to such as skill level; Game Center will match players with the same playerGroup.</param> /// <param name="playerAttributes">The attributes of this player such as white or black pieces in chest; Game Center will try to match players so that all bits of this attribute are filled by all players of a game.</param> /// <param name="playersToInvite">An array of Player instances; this is passed in from the PlayersInvited event.</param> public static void StartMatch(uint minPlayers, uint maxPlayers, uint playerGroup = 0, uint playerAttributes = 0, Player[] playersToInvite = null) { if ((minPlayers < 2) || (minPlayers > 4) || (maxPlayers < 2) || (maxPlayers > 4) || (maxPlayers < minPlayers)) throw new U3DXTException("minPlayers and maxPlayers must be between 2 and 4."); _currentMatch = null; // create request var request = new GKMatchRequest(); request.minPlayers = minPlayers; request.maxPlayers = maxPlayers; request.playerGroup = playerGroup; request.playerAttributes = playerAttributes; if (playersToInvite != null) request.playersToInvite = Player.PlayersToIDs(playersToInvite); // create view controller var mmvc = new GKMatchmakerViewController(request); // set delegate mmvc.matchmakerDelegate = MatchmakerViewControllerDelegate.instance; // show it UIApplication.deviceRootViewController.PresentViewController(mmvc, true, null); }
public override void DidFindMatch(GKMatchmakerViewController viewController, GKMatch match) { UIApplication.SharedApplication().keyWindow.rootViewController.DismissViewController(true, null); RealTimeMatchesController.SetCurrentMatch(match); }
/// <summary> /// Displays the iOS matchmaker to the player. /// </summary> /// <remarks> /// Note this is not overloaded in derived classes on purpose. This is /// only a reason this exists is for caching effects. /// </remarks> /// <param name="minPlayers">Minimum players to find</param> /// <param name="maxPlayers">Maximum players to find</param> /// <param name="playersToInvite">Players to invite/param> public static void ShowMatchMaker(int minPlayers, int maxPlayers, string[] playersToInvite) { AssertInitialised (); if ( ( Gamer.SignedInGamers.Count > 0 ) && ( Gamer.SignedInGamers[0].IsSignedInToLive ) ) { // Lazy load it if ( matchmakerViewController == null ) { matchmakerViewController = new GKMatchmakerViewController(new GKMatchRequest()); } if (matchmakerViewController != null) { matchmakerViewController.MatchRequest.MinPlayers = minPlayers; matchmakerViewController.MatchRequest.MaxPlayers = maxPlayers; matchmakerViewController.MatchRequest.PlayersToInvite = playersToInvite; matchmakerViewController.DidFailWithError += delegate(object sender, GKErrorEventArgs e) { matchmakerViewController.DismissModalViewControllerAnimated(true); IsVisible = false; TouchPanel.EnabledGestures=prevGestures; }; matchmakerViewController.DidFindMatch += delegate(object sender, GKMatchEventArgs e) { Guide.Match = e.Match; }; matchmakerViewController.DidFindPlayers += delegate(object sender, GKPlayersEventArgs e) { }; matchmakerViewController.WasCancelled += delegate(object sender, EventArgs e) { matchmakerViewController.DismissModalViewControllerAnimated(true); IsVisible = false; TouchPanel.EnabledGestures=prevGestures; }; if (_window != null) { if(viewController == null) { viewController = new GuideViewController(_gameViewController); _window.Add(viewController.View); viewController.View.Hidden = true; } prevGestures=TouchPanel.EnabledGestures; TouchPanel.EnabledGestures=GestureType.None; viewController.PresentModalViewController(matchmakerViewController, true); IsVisible = true; } } } }
internal static void _MatchInviteHandler(GKInvite acceptedInvite, object[] playersToInvite) { if (acceptedInvite != null) { // show new view controller var mmvc = new GKMatchmakerViewController(acceptedInvite); mmvc.matchmakerDelegate = MatchmakerViewControllerDelegate.instance; UIApplication.deviceRootViewController.PresentViewController(mmvc, true, null); // load players and dispatch event Player.LoadPlayersByIDs(new string[] {acceptedInvite.inviter}, delegate(Player[] players) { if (players.Length > 0) { if (_inviteAcceptedHandlers != null) _inviteAcceptedHandlers(null, new InviteAcceptedEventArgs(players[0], acceptedInvite.playerGroup, acceptedInvite.playerAttributes)); } acceptedInvite = null; }); mmvc = null; } else if (playersToInvite != null) { // load players and dispatch event Player.LoadPlayersByIDs(playersToInvite.Cast<string>().ToArray(), delegate(Player[] players) { if (players.Length > 0) { if (_playersInvitedHandlers != null) _playersInvitedHandlers(null, new PlayersInvitedEventArgs(players)); } }); } }