99See the [ Quick-Start Guide] ( ../../../../../../Documentation/Quickstart.md ) for general installation instructions.
1010
1111## Usage
12- Since most calls to GameKit are asynchronous, the public methods are Task, or Task<> based. For a comprehensive guide to GameKit on Apple devices, please see [ GameKit Developer Documentation] ( https://developer.apple.com/documentation/gamekit/ )
12+ Since most calls to GameKit are asynchronous, the public methods are ` Task ` , or ` Task<> ` based. For a comprehensive guide to GameKit on Apple devices, please see [ GameKit Developer Documentation] ( https://developer.apple.com/documentation/gamekit/ )
1313
1414### Exceptions
1515If there is any error reported from GameKit, it will be reported by throwing a ` GameKitException ` . In all cases, a ` try -catch ` should be used to properly handle exceptions.
@@ -55,7 +55,7 @@ var localPlayer = GKLocalPlayer.Local;
5555Debug .Log ($" Local Player: {localPlayer .DisplayName }" );
5656
5757if (! localPlayer .IsUnderage ) {
58- // Ask for analytics permissions, etc
58+ // Ask for analytics permissions, etc.
5959 }
6060```
6161
@@ -64,19 +64,19 @@ Each call to LoadPlayerPhoto generates a new Texture2D so ensure you cache as ne
6464``` csharp
6565var player = await GKLocalPlayer .Local ;
6666
67- // Resolves a new instance of the players photo as a Texture2D
67+ // Resolves a new instance of the players photo as a Texture2D.
6868var photo = await player .LoadPhoto (size );
6969```
7070
7171#### 1.4 Friends
7272``` csharp
73- // Loads the local player's friends list if the local player and their friends grant access
73+ // Loads the local player's friends list if the local player and their friends grant access.
7474var friends = await GKLocalPlayer .Local .LoadFriends ();
7575
7676// Loads players to whom the local player can issue a challenge.
7777var challengeableFriends = await GKLocalPlayer .Local .LoadChallengeableFriends ();
7878
79- // Loads players from the friends list or players that recently participated in a game with the local player
79+ // Loads players from the friends list or players that recently participated in a game with the local player.
8080var recentPlayers = await GKLocalPlayer .Local .LoadRecentPlayers ();
8181```
8282
@@ -125,7 +125,7 @@ var achievements = await GKAchievement.LoadAchievements();
125125foreach (var a in achievements )
126126{
127127 var image = await a .LoadImage ();
128- // Do something with the image
128+ // Do something with the image.
129129 }
130130```
131131
@@ -137,7 +137,7 @@ var showCompletionBanner = true;
137137
138138var achievements = await GKAchievement .LoadAchievements ();
139139
140- // Only completed achievements are returned
140+ // Only completed achievements are returned.
141141var achievement = achievements .FirstOrDefault (a => a .Identifier == achievementId );
142142
143143// If null, initialize it
@@ -147,7 +147,7 @@ if(!achievement.IsCompleted) {
147147 achievement .PercentComplete = progressPercentage ;
148148 achievement .ShowCompletionBanner = showCompletionBanner ;
149149
150- // Accepts a param GKAchievement[] for reporting multiple achievements
150+ // Accepts a param GKAchievement[] for reporting multiple achievements.
151151 await GKAchievement .Report (achievement , .. .);
152152}
153153
@@ -184,7 +184,8 @@ GKMatch match = await GKMatchmakerViewController.Request(matchRequest);
184184match .Delegate .DataReceived += OnMatchDataReceived ;
185185match .Delegate .DataReceivedForPlayer ++ OnMatchDataReceivedForPlayer ;
186186match .Delegate .DidFailWithError += OnMatchErrorReceived ;
187- match .Delegate .PlayerConnectionStateChanged += OnMatchPlayerConnectionStateChanged ;
187+ match .Delegate .PlayerConnectionChanged += OnMatchPlayerConnectionChanged ;
188+ match .Delegate .ShouldReinviteDisconnectedPlayer += OnShouldReinviteDisconnectedPlayer ;
188189
189190private void OnMatchDataReceived (byte [] data , GKPlayer fromPlayer )
190191{
@@ -201,10 +202,15 @@ private void OnMatchErrorReceived(GameKitException exception)
201202 // Handle error
202203 }
203204
204- private void OnMatchPlayerConnectionStateChanged (GKPlayer player , GKPlayerConnectionState state )
205+ private void OnMatchPlayerConnectionChanged (GKPlayer player , GKPlayerConnectionState state )
205206{
206207 // Handle state change
207208 }
209+
210+ private bool ShouldReinviteDisconnectedPlayerHandler (GKPlayer player )
211+ {
212+ // Reinvite disconnected player
213+ }
208214```
209215
210216#### 4.2 Request Match
@@ -217,36 +223,52 @@ request.PlayerAttributes = 0;
217223request .PlayerGroup = 0 ;
218224request .RestrictToAutomatch = false ;
219225
226+ // If using rule-based matchmaking...
227+ request .QueueName = " NameOfYourMatchmakerQueue" ;
228+
229+ request .Properties = GKMatchProperties .FromJson (jsonPropertyBagToSendToServer );
230+ // -or-
231+ request .Properties = new NSMutableDictionary <NSString , NSObject > {
232+ { " YourPropertyNameHere" , new NSNumber (3 . 14159 ) },
233+ { " AnotherPropertyName" , new NSString (" some string value" ) }
234+ };
220235```
236+
221237##### 4.2.1 Request using native OS UI
222238``` csharp
223239var match = await GKMatchmakerViewController .Request (request );
224240```
225241
226242##### 4.2.2 Request without using native OS UI.
227243``` csharp
228- // A match based on the GKMatchRequest
244+ // A match based on the GKMatchRequest.
229245var match = await GKMatchmaker .Shared .FindMatch (request );
230246
231- // A match from an accepted invite
247+ // A match from an accepted invite.
232248var matchForInvite = await GKMatchmaker .Shared .Match (invite );
233249
234- // Initiates a request to find players for a hosted match
250+ // Initiates a request to find players for a hosted match.
235251var players = await GKMatchmaker .Shared .FindPlayers (request );
236252
253+ // Initiates a request to find players for a hosted match via rule-based matchmaking.
254+ GKMatchedPlayers matchedPlayers = GKMatchmaker .Shared .FindMatchedPlayers (request );
255+
237256// Invites additional players to an existing match...
238257await GKMatchmaker .Shared .AddPlayers (match , request );
239258
240- // Finds the number of players, across player groups, who recently requested a match
259+ // Finds the number of players, across player groups, who recently requested a match.
241260var numMatchRequests = await GKMatchmaker .Shared .QueryActivity ();
242261
243- // Finds the number of players in a player group who recently requested a match
262+ // Finds the number of players, across player groups, who recently requested a match via the specified rule-based matchmaking queue.
263+ var numMatchRequests = await .GKMatchmaker .Shared .QueryQueueActivity (" NameOfYourQueue" );
264+
265+ // Finds the number of players in a player group who recently requested a match.
244266var numMatchRequestsInGroup = await GKMatchmaker .Shared .QueryPlayerGroupActivity (playerGroupId );
245267
246- // Cancels a matchmaking request
268+ // Cancels a matchmaking request.
247269GKMatchmaker .Shared .Cancel ();
248270
249- // Cancels a pending invitation to another player
271+ // Cancels a pending invitation to another player.
250272GKMatchmaker .Shared .CancelPendingInvite (playerBeingInvited );
251273```
252274
@@ -258,16 +280,16 @@ match.Disconnect();
258280#### 4.4 Send To All
259281Sends a message to all players
260282``` csharp
261- var data = Encoding .ASCII .GetBytes (" Hello World" );
262- match .Send (data , GKSendDataMode .Reliable );
283+ var data = Encoding .UTF8 .GetBytes (" Hello World" );
284+ match .Send (data , GKMatch . GKSendDataMode .Reliable );
263285```
264286
265287#### 4.4 Send To Players
266288Sends a message to the selected players
267289``` csharp
268290var players = new GKPlayer [] { .. . };
269- var data = Encoding .ASCII .GetBytes (" Hello World" );
270- match .SendToPlayers (data , players , GKSendDataMode .Reliable );
291+ var data = Encoding .UTF8 .GetBytes (" Hello World" );
292+ match .SendToPlayers (data , players , GKMatch . GKSendDataMode .Reliable );
271293```
272294
273295#### 4.5 GKVoiceChat
0 commit comments