Google Play 게임즈
Provide a Google Play Games sign-in option to provide a frictionless authentication experience for Android players.
읽는 시간 1분최근 업데이트: 한 달 전
최소 SDK 버전: 2.1.0
이 문서에서는 게임에서 Google Play 게임즈 계정을 사용해 플레이어의 인증을 설정하는 다음 시나리오에 대해 설명합니다. 참고: 아래 코드에서는 플레이어의 일회성 인증 코드를 이미 획득했다고 가정합니다.- Google Play 게임즈 로그인 설정
- 기존 사용자 로그인 또는 새 사용자 생성
- 사용자를 익명 로그인에서 Google Play 게임즈 계정을 통한 플랫폼 로그인으로 업데이트
Google Play 게임즈 로그인 설정
참고: Google Play 게임즈 로그인은 Android 기기에서만 호환됩니다. 참고: Google Play 게임즈 로그인은 Play Games Services v2 SDK 사용을 권장하는 Google Play Games plugin for Unity v11.01 이상에서만 지원됩니다.- Google Play Games Plugin for Unity를 다운로드하고 임포트합니다.
- 앱의 Google 로그인을 활성화합니다. Google 로그인을 사용하도록 게임을 설정하려면 Google의 기술 자료를 참고하십시오.
-
Unity Authentication의 ID 제공업체를 Google로 설정합니다.
- Unity 에디터 메뉴에서 Edit > Project Settings… 로 이동한 후, 내비게이션 메뉴에서 Services > Authentication을 선택합니다.
- ID Providers를 Google Play Services로 설정한 후, Add를 클릭합니다.
- Client ID 텍스트 필드에 웹 앱 클라이언트 ID를 입력합니다.
-
Client Secret 텍스트 필드에 웹 앱 클라이언트 비밀 정보를 입력한 후, Save를 선택합니다.
using GooglePlayGames;using GooglePlayGames.BasicApi;using UnityEngine;public class GooglePlayGamesExampleScript : MonoBehaviour{ public string Token; public string Error; void Awake() { //Initialize PlayGamesPlatform PlayGamesPlatform.Activate(); LoginGooglePlayGames(); } public void LoginGooglePlayGames() { PlayGamesPlatform.Instance.Authenticate((success) => { if (success == SignInStatus.Success) { Debug.Log("Login with Google Play games successful."); PlayGamesPlatform.Instance.RequestServerSideAccess(true, code => { Debug.Log("Authorization code: " + code); Token = code;// This token serves as an example to be used for SignInWithGooglePlayGames }); } else { Error = "Failed to retrieve Google play games authorization code"; Debug.Log("Login Unsuccessful"); } }); }}
기존 플레이어 로그인 또는 신규 플레이어 생성
SignInWithGooglePlayGamesAsync- Google Play 게임즈 자격 증명을 사용해 새 Unity Authentication 플레이어 생성
- Google Play 게임즈 자격 증명을 사용해 기존 플레이어 로그인
SignInWithGooglePlayGamesAsyncSignInWithGooglePlayGamesAsyncSignInWithGooglePlayGamesAsyncasync Task SignInWithGooglePlayGamesAsync(string authCode){ try { await AuthenticationService.Instance.SignInWithGooglePlayGamesAsync(authCode); 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); }}
플레이어를 익명 로그인에서 Google Play 게임즈 계정 로그인으로 업데이트
익명 인증을 설정한 후, 플레이어가 Google Play 게임즈 계정을 생성하고 Google Play 게임즈를 통해 로그인하도록 업그레이드하려는 경우, 게임이 플레이어에게 Google Play 게임즈 로그인 창을 표시하고 Google에서 일회성 인증 코드를 가져와야 합니다. 그런 다음LinkWithGooglePlayGamesAsync- 를 사용해 캐시된 플레이어의 계정에 로그인합니다.
SignInAnonymouslyAsync - 를 사용해 캐시된 플레이어의 계정을 Google Play 게임즈 계정에 연결합니다.
LinkWithGooglePlayGamesAsync
async Task LinkWithGooglePlayGamesAsync(string authCode){ try { await AuthenticationService.Instance.LinkWithGooglePlayGamesAsync(authCode); 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); }}
Google Play 계정 연결 해제
플레이어가 Google Play 게임즈 계정 연결을 해제할 수 있도록UnlinkGooglePlayGamesAsyncasync Task UnlinkGooglePlayGamesAsync(string idToken){ try { await AuthenticationService.Instance.UnlinkGooglePlayGamesAsync(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); }}