/// <summary> /// Send a photo to a friend via GameCenter /// </summary> /// <param name="matchFoundCallback">Match found callback.</param> /// <param name="cancelCallback">Cancel callback.</param> /// <param name="errorCallback">Error callback.</param> /// <param name="playerQuitCallback">Player quit callback.</param> public static void NewVersusPhoto(Action <UIViewController> showCallback, Action <PuzzleData> matchFoundCallback, Action cancelCallback, Action errorCallback, Action playerQuitCallback) { Logger.I("Game center: new turn based match request..."); GKMatchRequest matchRequest = new GKMatchRequest(); matchRequest.MinPlayers = 2; matchRequest.MaxPlayers = 2; matchRequest.DefaultNumberOfPlayers = 2; GKTurnBasedMatchmakerViewController matchMakerVc = new GKTurnBasedMatchmakerViewController(matchRequest); var d = new MatchMakerDelegate(); d.MatchFoundCallback += matchFoundCallback; d.CancelCallback += cancelCallback; d.ErrorCallback += errorCallback; d.PlayerQuitCallback += playerQuitCallback; matchMakerVc.Delegate = d; if (showCallback != null) { showCallback(matchMakerVc); } }
/// <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> /// Brings up the match making interface to start or join a turn-based match with other players. /// Raises TurnChanged, 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="playersToInvite">An array of Player instances; this is passed in from the PlayersInvited event.</param> /// <param name="showExistingMatches">If set to <c>true</c> show existing matches.</param> public static void StartMatch(uint minPlayers, uint maxPlayers, Player[] playersToInvite = null, bool showExistingMatches = true) { if ((minPlayers < 2) || (minPlayers > 16) || (maxPlayers < 2) || (maxPlayers > 16) || (maxPlayers < minPlayers)) { throw new U3DXTException("minPlayers and maxPlayers must be between 2 and 16."); } // create request var request = new GKMatchRequest(); request.minPlayers = minPlayers; request.maxPlayers = maxPlayers; if (playersToInvite != null) { request.playersToInvite = Player.PlayersToIDs(playersToInvite); } // create view controller var mmvc = new GKTurnBasedMatchmakerViewController(request); mmvc.showExistingMatches = showExistingMatches; mmvc.turnBasedMatchmakerDelegate = TurnBasedMatchmakerViewControllerDelegate.instance; // show it UIApplication.deviceRootViewController.PresentViewController(mmvc, true, null); }
/// <summary> /// Gets the maximum number of players allowed for the specified match type. /// </summary> /// <returns>The max players allowed.</returns> /// <param name="matchType">Match type.</param> public static uint GetMaxPlayersAllowed(MatchType matchType) { switch (matchType) { case MatchType.RealTime: #if UNITY_ANDROID // https://developers.google.com/games/services/common/concepts/realtimeMultiplayer return(8); #elif UNITY_IOS return(GKMatchRequest.MaxPlayersAllowedForMatchType(matchType.ToGKMatchType())); #else return(0); #endif case MatchType.TurnBased: #if UNITY_ANDROID && EM_GPGS // https://developers.google.com/games/services/common/concepts/turnbasedMultiplayer return(8); #elif UNITY_IOS return(GKMatchRequest.MaxPlayersAllowedForMatchType(matchType.ToGKMatchType())); #else return(0); #endif case MatchType.Unknown: default: return(0); } }
void CreateMeetingCustom() { Log("Creating meeting with custom UI."); var request = new GKMatchRequest(); request.minPlayers = 2; request.maxPlayers = 4; GKMatchmaker.SharedMatchmaker().FindMatch(request, OnCustomFoundMatch); }
void CreateMeetingCustom() { Log("Creating meeting with custom UI."); var request = new GKMatchRequest(); request.minPlayers = 2; request.maxPlayers = 4; GKMatchmaker.SharedMatchmaker().FindMatch(request, OnCustomFoundMatch); }
/// <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); }
public void ShowMatchesUI() { if (mCurrentMatchmakerVC != null) { Debug.Log("Ignoring CreateWithMatchmakerUI call because another matchmaker UI is being shown."); return; } // Create a dummy request with the widest range of players possible. var gkRequest = new GKMatchRequest(); gkRequest.MinPlayers = 2; gkRequest.MaxPlayers = GKMatchRequest.MaxPlayersAllowedForMatchType(GKMatchRequest.GKMatchType.TurnBased); // Create a new TBM VC with the dummy request. var vc = InteropObjectFactory <GKTBMVC> .Create( () => new GKTBMVC(gkRequest), viewController => viewController.ToPointer()); // This VC should show existing matches. vc.ShowExistingMatches = true; // Create a delegate for the TBM VC with no callbacks. // The delegate is necessary so the VC can be closed. vc.TurnBasedMatchmakerDelegate = new InternalGKTBMVCDelegateImpl() { CancelCallback = null, ErrorCallback = null, ResetMatchmakerVC = () => mCurrentMatchmakerVC = null }; // Store the VC ref. mCurrentMatchmakerVC = vc; // Now show the VC. using (var unityVC = UIViewController.UnityGetGLViewController()) unityVC.PresentViewController(vc, true, null); }
/// <summary> /// Send a photo to a friend via GameCenter /// </summary> /// <param name="matchFoundCallback">Match found callback.</param> /// <param name="cancelCallback">Cancel callback.</param> /// <param name="errorCallback">Error callback.</param> /// <param name="playerQuitCallback">Player quit callback.</param> public static void NewVersusPhoto(Action<UIViewController> showCallback, Action<PuzzleData> matchFoundCallback, Action cancelCallback, Action errorCallback, Action playerQuitCallback) { Logger.I ("Game center: new turn based match request..."); GKMatchRequest matchRequest = new GKMatchRequest (); matchRequest.MinPlayers = 2; matchRequest.MaxPlayers = 2; matchRequest.DefaultNumberOfPlayers = 2; GKTurnBasedMatchmakerViewController matchMakerVc = new GKTurnBasedMatchmakerViewController (matchRequest); var d = new MatchMakerDelegate (); d.MatchFoundCallback += matchFoundCallback; d.CancelCallback += cancelCallback; d.ErrorCallback += errorCallback; d.PlayerQuitCallback += playerQuitCallback; matchMakerVc.Delegate = d; if (showCallback != null) { showCallback (matchMakerVc); } }
/// <summary> /// Brings up the match making interface to start or join a turn-based match with other players. /// Raises TurnChanged, 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="playersToInvite">An array of Player instances; this is passed in from the PlayersInvited event.</param> /// <param name="showExistingMatches">If set to <c>true</c> show existing matches.</param> public static void StartMatch(uint minPlayers, uint maxPlayers, Player[] playersToInvite = null, bool showExistingMatches = true) { if ((minPlayers < 2) || (minPlayers > 16) || (maxPlayers < 2) || (maxPlayers > 16) || (maxPlayers < minPlayers)) throw new U3DXTException("minPlayers and maxPlayers must be between 2 and 16."); // create request var request = new GKMatchRequest(); request.minPlayers = minPlayers; request.maxPlayers = maxPlayers; if (playersToInvite != null) request.playersToInvite = Player.PlayersToIDs(playersToInvite); // create view controller var mmvc = new GKTurnBasedMatchmakerViewController(request); mmvc.showExistingMatches = showExistingMatches; mmvc.turnBasedMatchmakerDelegate = TurnBasedMatchmakerViewControllerDelegate.instance; // show it UIApplication.SharedApplication().keyWindow.rootViewController.PresentViewController(mmvc, 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> /// 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 NewMatch(Action<VersusMatch> matchFoundCallback, Action cancelCallback, Action errorCallback, Action playerQuitCallback) { GKMatchRequest matchRequest = new GKMatchRequest(); matchRequest.MinPlayers = 2; matchRequest.MaxPlayers = 2; matchRequest.DefaultNumberOfPlayers = 2; GKTurnBasedMatchmakerViewController matchMakerVc = new GKTurnBasedMatchmakerViewController(matchRequest); var mmDelegate = new MatchMakerDelegate(this); mmDelegate.MatchFoundCallback += matchFoundCallback; mmDelegate.CancelCallback += cancelCallback; mmDelegate.ErrorCallback += errorCallback; mmDelegate.PlayerQuitCallback += playerQuitCallback; matchMakerVc.Delegate = mmDelegate; ShowGameCenter(matchMakerVc); }