summaryrefslogtreecommitdiff
path: root/Runtime/Export/GameCenterServices.txt
blob: b19ad5fd0e8dc9cbe24a8c9971209b8e4e504086 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
C++RAW

#include "UnityPrefix.h"
#include "Runtime/Scripting/ScriptingUtility.h"
#include "Runtime/Utilities/Utility.h"
#include <vector>

#if ENABLE_GAMECENTER
#include "External/GameKit/GameCenter.h"
#endif


CSRAW 
using System;
using System.Runtime.InteropServices;

#if ENABLE_GAMECENTER
namespace UnityEngine.SocialPlatforms.GameCenter
{
	using UnityEngine.SocialPlatforms.Impl;
	
	/// GameCenter implementation for network services.
	/// An application bundle ID must be registered on iTunes Connect
	/// before it can access GameCenter. This ID must be properly set in
	/// the iOS player properties in Unity, or in the Info.plist file inside your
	/// application bundle for OS X Standalone builds. When debugging you can use the GameCenter
	/// sandbox (a text displaying this is shown when logging on). You
	/// must log on in the application to get into sandbox mode, logging
	/// on in the GameCenter application will always use the production version.
	///

	// Remove this note if apple gets to fix it!
	/// Note: Mac OS X (as of version 10.8.2) has a bug where it will not allow you to enter 
	/// Game Center sandbox mode unless you use the following workaround as suggested by Apple:
	/// https://devforums.apple.com/message/763000
	/// It does not seem to be possible to create Game Center sandbox accounts using this workaround,
	/// though, so if you don't have an existing sandbox account, you need to create one using iOS.
	///

	/// For testing Game Center on OS X, you need to first set up your Info.plist file to contain
	/// the correct application bundle ID and version to match the app set up in iTunes Connect.
	/// Then, you need to set up the correct entitlements for Game Center. Create an entitlements file
	/// with the following contents:
	
	BEGIN EX
	<?xml version="1.0" encoding="UTF-8"?>
	<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
	<plist version="1.0">
	<dict>
		<key>com.apple.security.app-sandbox</key>
		<true/>
		<key>com.apple.security.temporary-exception.mach-lookup.global-name</key>
		<array>
			<string>com.apple.gamed.osx</string>
			<string>com.apple.gamed.xpc</string>
			<string>com.apple.developer.game-center</string>
		</array>
	</dict>
	</plist>
	END EX
	
	/// Finally, you need to sign you application using the entitlements file like this:

	BEGIN EX
	codesign -f -s "<Your code signing certificate>" --entitlements <path to your entitlements file> <path to your created unity standalone app> 
	END EX

	/// When using the GameCenterPlatform class in C# you need to include the 
	/// UnityEngine.SocialPlatforms.GameCenter namespace.
	///
	/// Some things to be aware of when using the generic API:
	///
	/// __Authenticate()__ \\
	/// If the user is not logged in, a standard GameKit UI is shown 
	/// where he can log on or create a new user. It is recommended
	/// this is done as early as possible.
	/// 
	/// __Achievement descriptions and Leaderboards__ \\
	/// The achivements descriptions and leaderboard configurations can be configured in the 
	/// iTunes Connect portal. Achievements get unique identifiers and the
	/// leaderboards use category names as identifiers.
	///
	/// __GameCenter Sandbox__ \\
	/// Development applications use the GameCenter Sandbox. This is a seperate GameCenter
	/// than the live one, nothing is shared between them. It is recommended that you
	/// create a seperate user for testing with the GameCenter Sandbox, you should not use
	/// your real Apple ID for this. You can only log on to the sandbox through a development
	/// application, make sure you are not logged into GameCenter using the GameCenter app before
	/// testing begins. You should see ''*** Sandbox ***'' in the login dialog, if you don't see this
	/// then you are logging on to the real one. Sometime it happens that the OS forgets that the
	/// application is using the sandbox and you will be logged on to the real one. If the application
	/// has not be submitted to Apple already then this will probably result in an error. To fix this
	/// all that needs to be done is to delete the app and redeploy with Xcode. To make another apple 
	/// ID a friend of a sandbox user it needs to be a sandbox user as well.
	///
	/// If you start getting errors when accessing GameCenter stating that the
	/// application is not recognized you'll need to delete the application complately and re-deploy.
	/// Make sure you are not logged on when starting the newly installed application again.
	CONDITIONAL ENABLE_GAMECENTER
	CLASS GameCenterPlatform : ISocialPlatform
		
		CUSTOM internal static void Internal_Authenticate()
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcLocalUser::GetInstance()->Authenticate();
			#endif
		}
		
		CUSTOM internal static bool Internal_Authenticated()
		{
			#if ENABLE_GAMECENTER
			return GameCenter::GcLocalUser::GetInstance()->GetAuthenticated();
			#else
			return false;
			#endif
		}
		
		CUSTOM internal static string Internal_UserName()
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcLocalUser *user = GameCenter::GcLocalUser::GetInstance();
			std::string name = user->GetUserName();
			return scripting_string_new(name);
			#else
			return scripting_string_new("");
			#endif
		}
		
		CUSTOM internal static string Internal_UserID()
		{
			#if ENABLE_GAMECENTER
			return scripting_string_new(GameCenter::GcLocalUser::GetInstance()->GetUserID());
			#else
			return scripting_string_new("");
			#endif
		}
		
		CUSTOM internal static bool Internal_Underage()
		{
			#if ENABLE_GAMECENTER
			return GameCenter::GcLocalUser::GetInstance()->GetIsUnderage();
			#else
			return false;
			#endif
		}
		
		CUSTOM internal static Texture2D Internal_UserImage()
		{
			#if ENABLE_GAMECENTER
			return GameCenter::GcLocalUser::GetInstance()->GetUserImage();
			#else
			return SCRIPTING_NULL;
			#endif
		}

		CUSTOM internal static void Internal_LoadFriends()
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcLocalUser::GetInstance()->LoadFriends();
			#endif
		}
		
		CUSTOM internal static void Internal_LoadAchievementDescriptions()
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcAchievementDescription::LoadAchievementDescriptions();
			#endif
		}
	
		CUSTOM internal static void Internal_LoadAchievements()
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcAchievement::LoadAchievements();
			#endif
		}
		
		CUSTOM internal static void Internal_ReportProgress(string id, double progress)
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcAchievement::ReportProgress(id, progress);
			#endif
		}
		
		CUSTOM internal static void Internal_ReportScore(Int64 score, string category)
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcScore::ReportScore(score, category);
			#endif
		}
				
		CUSTOM internal static void Internal_LoadScores(string category)
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcScore::LoadScores(category);
			#endif
		}
		
		CUSTOM internal static void Internal_ShowAchievementsUI()
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcAchievementDescription::ShowAchievementsUI();
			#endif
		}
		
		CUSTOM internal static void Internal_ShowLeaderboardUI()
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcLeaderboard::ShowLeaderboardUI();
			#endif
		}
		
		CUSTOM internal static void Internal_LoadUsers(string[] userIds)
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcLocalUser::LoadUsers(userIds);
			#endif
		}
		
		CUSTOM internal static void Internal_ResetAllAchievements()
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcAchievement::ResetAllAchievements();
			#endif
		}
		
		CUSTOM internal static void Internal_ShowDefaultAchievementBanner(bool value)
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcAchievement::ShowDefaultAchievementBanner(value);
			#endif
		}
		
		// Reset all the achievements for the local user.
		CSRAW static public void ResetAllAchievements(Action<bool> callback)
		{
			s_ResetAchievements = callback;
			Internal_ResetAllAchievements();
		}

		// Show the default iOS banner when achievements are completed.
		CSRAW static public void ShowDefaultAchievementCompletionBanner(bool value)
		{
			Internal_ShowDefaultAchievementBanner(value);
		}
		
		// Show the leaderboard UI with a specific leaderboard shown initially with a specific time scope selected.
		CSRAW static public void ShowLeaderboardUI(string leaderboardID, TimeScope timeScope)
		{
			Internal_ShowSpecificLeaderboardUI(leaderboardID, (int)timeScope);
		}
		
		CUSTOM internal static void Internal_ShowSpecificLeaderboardUI(string leaderboardID, int timeScope)
		{
			#if ENABLE_GAMECENTER
			GameCenter::GcLeaderboard::ShowLeaderboardUI(leaderboardID, timeScope);
			#endif
		}
	END
	
	// This class cannot inherit from the generic Leaderboard class as it will break the marshaling of the pointer
	// *undocumented*
	CSRAW [StructLayout (LayoutKind.Sequential)]
	CONDITIONAL ENABLE_GAMECENTER
	CLASS internal GcLeaderboard
		C++RAW
		#if ENABLE_GAMECENTER
		struct GcLeaderboardToMono
		{
			GameCenter::GcLeaderboard* leaderboard;
			ScriptingObjectPtr genericLeaderboard;
		};
		#endif
		
		CSRAW
		private IntPtr m_InternalLeaderboard;
		Leaderboard m_GenericLeaderboard;

		internal GcLeaderboard(Leaderboard board)
		{
			m_GenericLeaderboard = board;
		}
		
		~GcLeaderboard()
		{
			Dispose();
		}
		
		internal bool Contains(Leaderboard board)
		{
			return m_GenericLeaderboard == board;
		}
		
		internal void SetScores(GcScoreData[] scoreDatas)
		{
			if (m_GenericLeaderboard != null)
			{
				Score[] scores = new Score[scoreDatas.Length];
				for(int i = 0; i < scoreDatas.Length; ++i)
					scores[i] = scoreDatas[i].ToScore();
				m_GenericLeaderboard.SetScores(scores);
			}
		}
		
		internal void SetLocalScore(GcScoreData scoreData)
		{
			if (m_GenericLeaderboard != null)
				m_GenericLeaderboard.SetLocalUserScore(scoreData.ToScore());
		}
		
		internal void SetMaxRange(uint maxRange)
		{
			if (m_GenericLeaderboard != null)
				m_GenericLeaderboard.SetMaxRange(maxRange);
		}
		
		internal void SetTitle(string title)
		{
			if (m_GenericLeaderboard != null)
				m_GenericLeaderboard.SetTitle(title);
		}
				
		CUSTOM internal void Internal_LoadScores(string category, int from, int count, int playerScope, int timeScope)
		{
			#if ENABLE_GAMECENTER
			GcLeaderboardToMono& monoBoard = ExtractMonoObjectData<GcLeaderboardToMono>(self);
			monoBoard.leaderboard = new GameCenter::GcLeaderboard();
			monoBoard.leaderboard->Create();
			monoBoard.leaderboard->RegisterManagedSelf(self);
			monoBoard.leaderboard->LoadScores(category, from, count, playerScope, timeScope);
			#endif
		}
		
		CUSTOM internal void Internal_LoadScoresWithUsers(string category, int timeScope, string[] userIDs)
		{
			#if ENABLE_GAMECENTER
			GcLeaderboardToMono& monoBoard = ExtractMonoObjectData<GcLeaderboardToMono>(self);
			monoBoard.leaderboard = new GameCenter::GcLeaderboard();
			monoBoard.leaderboard->Create(userIDs);
			monoBoard.leaderboard->RegisterManagedSelf(self);
			monoBoard.leaderboard->LoadScores(category, 1, 10, 0, timeScope);
			#endif
		}
		
		CUSTOM internal bool Loading()
		{
			#if ENABLE_GAMECENTER
			GcLeaderboardToMono& monoBoard = ExtractMonoObjectData<GcLeaderboardToMono>(self);
			return monoBoard.leaderboard->Loading();
			#else
			return false;
			#endif
		}
		
		THREAD_SAFE
		CUSTOM internal void Dispose()
		{
			#if ENABLE_GAMECENTER
			GcLeaderboardToMono& monoBoard = ExtractMonoObjectData<GcLeaderboardToMono>(self);
			delete monoBoard.leaderboard;
			monoBoard.leaderboard = NULL;
			#endif
		}
	END 
	
CSRAW
}
#endif