9
9
See the [ Quick-Start Guide] ( ../../../../../../Documentation/Quickstart.md ) for general installation instructions.
10
10
11
11
## 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/ )
13
13
14
14
### Exceptions
15
15
If 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;
55
55
Debug .Log ($" Local Player: {localPlayer .DisplayName }" );
56
56
57
57
if (! localPlayer .IsUnderage ) {
58
- // Ask for analytics permissions, etc
58
+ // Ask for analytics permissions, etc.
59
59
}
60
60
```
61
61
@@ -64,19 +64,19 @@ Each call to LoadPlayerPhoto generates a new Texture2D so ensure you cache as ne
64
64
``` csharp
65
65
var player = await GKLocalPlayer .Local ;
66
66
67
- // Resolves a new instance of the players photo as a Texture2D
67
+ // Resolves a new instance of the players photo as a Texture2D.
68
68
var photo = await player .LoadPhoto (size );
69
69
```
70
70
71
71
#### 1.4 Friends
72
72
``` 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.
74
74
var friends = await GKLocalPlayer .Local .LoadFriends ();
75
75
76
76
// Loads players to whom the local player can issue a challenge.
77
77
var challengeableFriends = await GKLocalPlayer .Local .LoadChallengeableFriends ();
78
78
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.
80
80
var recentPlayers = await GKLocalPlayer .Local .LoadRecentPlayers ();
81
81
```
82
82
@@ -125,7 +125,7 @@ var achievements = await GKAchievement.LoadAchievements();
125
125
foreach (var a in achievements )
126
126
{
127
127
var image = await a .LoadImage ();
128
- // Do something with the image
128
+ // Do something with the image.
129
129
}
130
130
```
131
131
@@ -137,7 +137,7 @@ var showCompletionBanner = true;
137
137
138
138
var achievements = await GKAchievement .LoadAchievements ();
139
139
140
- // Only completed achievements are returned
140
+ // Only completed achievements are returned.
141
141
var achievement = achievements .FirstOrDefault (a => a .Identifier == achievementId );
142
142
143
143
// If null, initialize it
@@ -147,7 +147,7 @@ if(!achievement.IsCompleted) {
147
147
achievement .PercentComplete = progressPercentage ;
148
148
achievement .ShowCompletionBanner = showCompletionBanner ;
149
149
150
- // Accepts a param GKAchievement[] for reporting multiple achievements
150
+ // Accepts a param GKAchievement[] for reporting multiple achievements.
151
151
await GKAchievement .Report (achievement , .. .);
152
152
}
153
153
@@ -184,7 +184,8 @@ GKMatch match = await GKMatchmakerViewController.Request(matchRequest);
184
184
match .Delegate .DataReceived += OnMatchDataReceived ;
185
185
match .Delegate .DataReceivedForPlayer ++ OnMatchDataReceivedForPlayer ;
186
186
match .Delegate .DidFailWithError += OnMatchErrorReceived ;
187
- match .Delegate .PlayerConnectionStateChanged += OnMatchPlayerConnectionStateChanged ;
187
+ match .Delegate .PlayerConnectionChanged += OnMatchPlayerConnectionChanged ;
188
+ match .Delegate .ShouldReinviteDisconnectedPlayer += OnShouldReinviteDisconnectedPlayer ;
188
189
189
190
private void OnMatchDataReceived (byte [] data , GKPlayer fromPlayer )
190
191
{
@@ -201,10 +202,15 @@ private void OnMatchErrorReceived(GameKitException exception)
201
202
// Handle error
202
203
}
203
204
204
- private void OnMatchPlayerConnectionStateChanged (GKPlayer player , GKPlayerConnectionState state )
205
+ private void OnMatchPlayerConnectionChanged (GKPlayer player , GKPlayerConnectionState state )
205
206
{
206
207
// Handle state change
207
208
}
209
+
210
+ private bool ShouldReinviteDisconnectedPlayerHandler (GKPlayer player )
211
+ {
212
+ // Reinvite disconnected player
213
+ }
208
214
```
209
215
210
216
#### 4.2 Request Match
@@ -217,36 +223,52 @@ request.PlayerAttributes = 0;
217
223
request .PlayerGroup = 0 ;
218
224
request .RestrictToAutomatch = false ;
219
225
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
+ };
220
235
```
236
+
221
237
##### 4.2.1 Request using native OS UI
222
238
``` csharp
223
239
var match = await GKMatchmakerViewController .Request (request );
224
240
```
225
241
226
242
##### 4.2.2 Request without using native OS UI.
227
243
``` csharp
228
- // A match based on the GKMatchRequest
244
+ // A match based on the GKMatchRequest.
229
245
var match = await GKMatchmaker .Shared .FindMatch (request );
230
246
231
- // A match from an accepted invite
247
+ // A match from an accepted invite.
232
248
var matchForInvite = await GKMatchmaker .Shared .Match (invite );
233
249
234
- // Initiates a request to find players for a hosted match
250
+ // Initiates a request to find players for a hosted match.
235
251
var players = await GKMatchmaker .Shared .FindPlayers (request );
236
252
253
+ // Initiates a request to find players for a hosted match via rule-based matchmaking.
254
+ GKMatchedPlayers matchedPlayers = GKMatchmaker .Shared .FindMatchedPlayers (request );
255
+
237
256
// Invites additional players to an existing match...
238
257
await GKMatchmaker .Shared .AddPlayers (match , request );
239
258
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.
241
260
var numMatchRequests = await GKMatchmaker .Shared .QueryActivity ();
242
261
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.
244
266
var numMatchRequestsInGroup = await GKMatchmaker .Shared .QueryPlayerGroupActivity (playerGroupId );
245
267
246
- // Cancels a matchmaking request
268
+ // Cancels a matchmaking request.
247
269
GKMatchmaker .Shared .Cancel ();
248
270
249
- // Cancels a pending invitation to another player
271
+ // Cancels a pending invitation to another player.
250
272
GKMatchmaker .Shared .CancelPendingInvite (playerBeingInvited );
251
273
```
252
274
@@ -258,16 +280,16 @@ match.Disconnect();
258
280
#### 4.4 Send To All
259
281
Sends a message to all players
260
282
``` 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 );
263
285
```
264
286
265
287
#### 4.4 Send To Players
266
288
Sends a message to the selected players
267
289
``` csharp
268
290
var 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 );
271
293
```
272
294
273
295
#### 4.5 GKVoiceChat
0 commit comments