Apple Game Center
최소 SDK 버전: 2.4.0
이 문서에서는 게임에서 Apple Game Center 플레이어 식별자를 사용해 플레이어의 인증을 설정하는 다음 시나리오에 대해 설명합니다.
- Apple Game Center 로그인 설정
- 기존 사용자 로그인 또는 새 사용자 생성
- 사용자를 익명 로그인에서 Apple Game Center 계정을 통한 플랫폼 로그인으로 업데이트
게임에서 플레이어에게 Apple Game Center 로그인 옵션을 제공하려면 앱에서 Apple Game Center 로그인을 활성화하십시오.
Unity 에디터에서 직접 또는 Unity Cloud Dashboard에서 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'와 같은 형식이어야 합니다.
참고: 참조된 패키지는 Unity가 개발하거나 보유, 운영하지 않습니다. Unity가 제공하지 않는 패키지의 사용법은 베스트 프랙티스를 참고하십시오.
중요: Unity Authentication에서는 보안상의 이유로 타임스탬프 입력이 10분 동안만 유효합니다. SignInWithAppleGameCenterAsync 또는 LinkWithAppleGameCenterAsync를 호출하기 전에 Apple의 FetchItems API를 호출해 입력을 새로 가져오십시오. SignInWithAppleGameCenterAsync 또는 LinkWithAppleGameCenterAsync를 성공적으로 한 번 호출한 이후에는 FetchItems API를 더 이상 호출할 필요가 없습니다.
필요한 플러그인을 설치하고 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 자격 증명을 사용해 기존 플레이어 로그인
프로젝트에서 자격 증명과 연결된 Unity Authentication 플레이어가 존재하지 않는 경우, SignInWithAppleGameCenterAsync
가 새 플레이어를 생성합니다. 프로젝트에서 자격 증명과 연결된 Unity Authentication 플레이어가 존재하는 경우, SignInWithAppleCenterAsync
가 해당 플레이어의 계정으로 로그인합니다. 이 기능은 캐시된 플레이어를 고려하지 않으며, SignInWithAppleGameCenterAsync
가 캐시된 플레이어를 대체합니다.
async 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
API를 호출해 플레이어를 Apple Game Center teamPlayerID에 연결합니다.
SDK에 캐시된 플레이어가 존재하는 경우, 캐시된 플레이어를 Apple Game Center 계정에 연결할 수 있습니다.
SignInAnonymouslyAsync
를 사용해 캐시된 플레이어의 계정에 로그인합니다.LinkWithAppleGameCenterAsync
를 사용해 캐시된 플레이어의 계정을 Apple 계정에 연결합니다.
캐시된 플레이어에 대한 자세한 내용은 캐시된 사용자 로그인 섹션을 참고하십시오.
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 계정 연결을 해제할 수 있도록 UnlinkAppleGameCenterAsync
API를 사용합니다. 연결이 해제되면 계정이 다른 ID에 연결되지 않은 경우 익명 계정으로 전환됩니다.
async 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);
}
}