Apple Game Center
Provide an Apple Game Center sign-in option to enable players to authenticate using their Game Center accounts on Apple platforms.
읽는 시간 1분최근 업데이트: 한 달 전
최소 SDK 버전: 2.4.0
이 문서에서는 게임에서 Apple Game Center 플레이어 식별자를 사용해 플레이어의 인증을 설정하는 다음 시나리오에 대해 설명합니다.- Apple Game Center 로그인 설정
- 기존 사용자 로그인 또는 새 사용자 생성
- 사용자를 익명 로그인에서 Apple Game Center 계정을 통한 플랫폼 로그인으로 업데이트
Apple Game Center 로그인 설정
- Apple Unity Plug-ins 저장소에서 Apple Game Kit Unity 플러그인을 설정하고 설치합니다. GameKit 프레임워크는 플레이어 ID를 비롯한 Apple Game Center 기능을 구현하는 데 사용됩니다.
-
Unity의 ID 제공업체로 Apple Game Center를 추가합니다.
- Unity 에디터 메뉴에서 Edit > Project Settings… 로 이동한 후, 내비게이션 메뉴에서 Services > Authentication을 선택합니다.
- ID Providers를 Apple Game Center로 설정한 후, Add를 선택합니다.
- Bundle ID 텍스트 필드에 Apple 개발자 콘솔의 번들 ID를 입력한 후, Save를 선택합니다. 번들 ID는 'com.something.somethingelse'와 같은 형식이어야 합니다.
필요한 플러그인을 설치하고 ID 제공업체를 설정한 후, 다음 샘플 코드를 따라 ID 확인에 필요한 파라미터를 가져올 수 있습니다.
using System;using System.Threading.Tasks;using UnityEngine;using Apple.GameKit;public class AppleGameCenterExampleScript : MonoBehaviour{ string Signature; string TeamPlayerID; string Salt; string PublicKeyUrl; string Timestamp; // Start is called before the first frame update async void Start() { await Login(); } public async Task Login() { if (!GKLocalPlayer.Local.IsAuthenticated) { // Perform the authentication. var player = await GKLocalPlayer.Authenticate(); Debug.Log($"GameKit Authentication: player {player}"); // Grab the display name. var localPlayer = GKLocalPlayer.Local; Debug.Log($"Local Player: {localPlayer.DisplayName}"); // Fetch the items. var fetchItemsResponse = await GKLocalPlayer.Local.FetchItems(); Signature = Convert.ToBase64String(fetchItemsResponse.GetSignature()); TeamPlayerID = localPlayer.TeamPlayerId; Debug.Log($"Team Player ID: {TeamPlayerID}"); Salt = Convert.ToBase64String(fetchItemsResponse.GetSalt()); PublicKeyUrl = fetchItemsResponse.PublicKeyUrl; Timestamp = fetchItemsResponse.Timestamp.ToString(); Debug.Log($"GameKit Authentication: signature => {Signature}"); Debug.Log($"GameKit Authentication: publickeyurl => {PublicKeyUrl}"); Debug.Log($"GameKit Authentication: salt => {Salt}"); Debug.Log($"GameKit Authentication: Timestamp => {Timestamp}"); } else { Debug.Log("AppleGameCenter player already logged in."); } }}
기존 플레이어 로그인 또는 신규 플레이어 생성
SignInWithAppleGameCenterAsync- Apple Game Center 자격 증명을 사용해 새 Unity Authentication 플레이어 생성
- Apple Game Center 자격 증명을 사용해 기존 플레이어 로그인
SignInWithAppleGameCenterAsyncSignInWithAppleCenterAsyncSignInWithAppleGameCenterAsyncasync Task SignInWithAppleGameCenterAsync(string signature, string teamPlayerId, string publicKeyURL, string salt, ulong timestamp){ try { await AuthenticationService.Instance.SignInWithAppleGameCenterAsync(signature, teamPlayerId, publicKeyURL, salt, timestamp); Debug.Log("SignIn is successful."); } catch (AuthenticationException ex) { // Compare error code to AuthenticationErrorCodes // Notify the player with the proper error message Debug.LogException(ex); } catch (RequestFailedException ex) { // Compare error code to CommonErrorCodes // Notify the player with the proper error message Debug.LogException(ex); }}
플레이어를 익명 로그인에서 Apple Game Center 계정 로그인으로 업데이트
익명 인증을 설정한 후, 플레이어가 Apple Game Center 계정을 생성하고 Apple Game Center를 통해 로그인하도록 업그레이드하려는 경우, 게임이 플레이어에게 Apple Game Center 로그인 창을 표시하고 GameKit를 통해 ID 확인 파라미터를 가져와야 합니다. 그런 다음LinkWithAppleGameCenterAsync- 를 사용해 캐시된 플레이어의 계정에 로그인합니다.
SignInAnonymouslyAsync - 를 사용해 캐시된 플레이어의 계정을 Apple 계정에 연결합니다.
LinkWithAppleGameCenterAsync
async Task LinkWithAppleGameCenterAsync(string signature, string teamPlayerId, string publicKeyURL, string salt, ulong timestamp){ try { await AuthenticationService.Instance.LinkWithAppleGameCenterAsync(signature, teamPlayerId, publicKeyURL, salt, timestamp); Debug.Log("Link is successful."); } catch (AuthenticationException ex) when (ex.ErrorCode == AuthenticationErrorCodes.AccountAlreadyLinked) { // Prompt the player with an error message. Debug.LogError("This user is already linked with another account. Log in instead."); } catch (AuthenticationException ex) { // Compare error code to AuthenticationErrorCodes // Notify the player with the proper error message Debug.LogException(ex); } catch (RequestFailedException ex) { // Compare error code to CommonErrorCodes // Notify the player with the proper error message Debug.LogException(ex); }}
Apple Game Center 계정 연결 해제
플레이어가 Apple Game Center 계정 연결을 해제할 수 있도록UnlinkAppleGameCenterAsyncasync Task UnlinkAppleGameCenterAsync(string idToken){ try { await AuthenticationService.Instance.UnlinkAppleGameCenterAsync(idToken); Debug.Log("Unlink is successful."); } catch (AuthenticationException ex) { // Compare error code to AuthenticationErrorCodes // Notify the player with the proper error message Debug.LogException(ex); } catch (RequestFailedException ex) { // Compare error code to CommonErrorCodes // Notify the player with the proper error message Debug.LogException(ex); }}