예제 #1
0
        /// <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>
        /// 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);
        }
예제 #3
0
        /// <summary>
        /// Sends data to some players in the match.
        /// </summary>
        /// <returns>The error code; 0 means successful.</returns>
        /// <param name="players">An array of Player objects to send the data to.</param>
        /// <param name="data">A byte array representing the data to be sent.</param>
        /// <param name="reliable">Whether to send it using reliable method; using false for this sends it faster but does not guarantee delivery or the order of delivering multiple data packets.</param>
        public int SendData(Player[] players, byte[] data, bool reliable)
        {
            int code  = 0;
            var error = new NSError();

            if (!gkMatch.SendData(NSData.FromByteArray(data),
                                  Player.PlayersToIDs(players),
                                  reliable ? GKMatchSendDataMode.Reliable : GKMatchSendDataMode.Unreliable,
                                  error))
            {
                code = error.Code();
            }

            error = null;
            return(code);
        }