internal static void _OnInvitePlayers(Player[] players)
 {
     if (_playersInvitedHandlers != null)
         _playersInvitedHandlers(null, new PlayersInvitedEventArgs(players));
 }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="U3DXT.iOS.GameKit.PlayersInvitedEventArgs"/> class.
 /// </summary>
 /// <param name="playersToInvite">Players to invite.</param>
 public PlayersInvitedEventArgs(Player[] playersToInvite)
 {
     this.playersToInvite = playersToInvite;
 }
Example #3
0
 /// <summary>
 /// Players to player IDs.
 /// </summary>
 /// <returns>The player IDs.</returns>
 /// <param name="players">Players.</param>
 public static string[] PlayersToIDs(Player[] players)
 {
     return players.Select(x => x.playerID).ToArray();
 }
        /// <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);
        }
Example #5
0
        /// <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>
 /// Initializes a new instance of the <see cref="U3DXT.iOS.GameKit.VoiceChatPlayerStateChangedEventArgs"/> class.
 /// </summary>
 /// <param name="voiceChat">Voice Chat.</param>
 /// <param name="player">Player.</param>
 /// <param name="state">State.</param>
 public VoiceChatPlayerStateChangedEventArgs(VoiceChat voiceChat, Player player, GKVoiceChatPlayerState state)
 {
     this.voiceChat = voiceChat;
     this.player = player;
     this.state = state;
 }
Example #7
0
 internal void _OnReceiveData(Player player, NSData data)
 {
     if (_dataReceivedHandlers != null)
         _dataReceivedHandlers(this, new DataReceivedEventArgs(player, data.ToByteArray()));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="U3DXT.iOS.GameKit.PlayerStateChangedEventArgs"/> class.
 /// </summary>
 /// <param name="player">Player.</param>
 /// <param name="isConnected">If set to <c>true</c> is connected.</param>
 public PlayerStateChangedEventArgs(Player player, bool isConnected)
 {
     this.player = player;
     this.isConnected = isConnected;
 }
Example #9
0
 internal void _OnPlayerStateChanged(Player player, GKPlayerConnectionState state)
 {
     if (_playerStateChangedHandlers != null)
         _playerStateChangedHandlers(this, new PlayerStateChangedEventArgs(player, (state == GKPlayerConnectionState.Connected)));
 }
Example #10
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 string 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, string data, bool reliable)
 {
     return SendData(players, data.ToStraightBytes(), reliable);
 }
Example #11
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;
        }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="U3DXT.iOS.GameKit.DataReceivedEventArgs"/> class.
 /// </summary>
 /// <param name="player">Player.</param>
 /// <param name="data">Data.</param>
 public DataReceivedEventArgs(Player player, byte[] data)
 {
     this.player = player;
     this.data = data;
 }
Example #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="U3DXT.iOS.GameKit.InviteAcceptedEventArgs"/> class.
 /// </summary>
 /// <param name="inviter">Inviter.</param>
 /// <param name="playerGroup">Player group.</param>
 /// <param name="playerAttributes">Player attributes.</param>
 public InviteAcceptedEventArgs(Player inviter, uint playerGroup, uint playerAttributes)
 {
     this.inviter = inviter;
     this.playerGroup = playerGroup;
     this.playerAttributes = playerAttributes;
 }