Provide a Google sign-in option to enable players to authenticate using their Google accounts in your game.
์ฝ๋ ์๊ฐ 2๋ถ์ต๊ทผ ์
๋ฐ์ดํธ: 8๋ฌ ์
์ต์ SDK ๋ฒ์ : 2.0.0
์ด ๋ฌธ์์์๋ ๊ฒ์์์ Google ๊ณ์ ์ ์ฌ์ฉํด ํ๋ ์ด์ด์ ์ธ์ฆ์ ์ค์ ํ๋ ๋ค์ ์๋๋ฆฌ์ค์ ๋ํด ์ค๋ช
ํฉ๋๋ค.
- Google ๋ก๊ทธ์ธ ์ค์
- ๊ธฐ์กด ์ฌ์ฉ์ ๋ก๊ทธ์ธ ๋๋ ์ ์ฌ์ฉ์ ์์ฑ
- ์ฌ์ฉ์๋ฅผ ์ต๋ช ๋ก๊ทธ์ธ์์ Google ๊ณ์ ์ ํตํ ํ๋ซํผ ๋ก๊ทธ์ธ์ผ๋ก ์ ๋ฐ์ดํธ
๊ฒ์์์ ํ๋ ์ด์ด์๊ฒ Google ๋ก๊ทธ์ธ ์ต์
์ ์ ๊ณตํ๋ ค๋ฉด Google Play Console์์ ์ฑ์ ์์ฑํ๊ณ Google Play Games plugin for Unity v10.14๋ฅผ ์ค์นํด ํ๋ ์ด์ด๋ฅผ ๋ก๊ทธ์ธ ์ฒ๋ฆฌํ๊ณ ์ก์ธ์ค ํ ํฐ์ ๊ฐ์ ธ์ค์ญ์์ค. ์ด๋ฅผ ์ํด์๋ Firebase ๋๋ Google๊ณผ ๊ฐ์ ๋ค๋ฅธ ์๋น์ค์์ ํ๋ ์ด์ด๋ฅผ ์๋ณํ๊ธฐ ์ํด Open Authentication(ID) ์ก์ธ์ค ํ ํฐ์ด ํ์ํฉ๋๋ค.
{ ((PlayGamesLocalUser)Social.localUser).GetIdToken()}
v10.14 ์ด์์ ์คํํ๋ ํ๋ฌ๊ทธ์ธ ๋ฒ์ ์ Google Play ๊ฒ์์ฆ๋ฅผ ์ฐธ๊ณ ํ์ญ์์ค.
Google ๋ก๊ทธ์ธ ์ค์
์ฐธ๊ณ : Google ๋ก๊ทธ์ธ์ Play Games Services v1 SDK๋ฅผ ์ฌ์ฉํ๋ Google Play Games plugin for Unity v10.14 ์ดํ๋ฅผ ํตํด ์ง์๋ฉ๋๋ค.
- Google Play Games plugin for Unity v10.14๋ฅผ ๋ค์ด๋ก๋ํ๊ณ ์ํฌํธํฉ๋๋ค.
- ์ฑ์ Google ๋ก๊ทธ์ธ์ ํ์ฑํํฉ๋๋ค. Google ๋ก๊ทธ์ธ์ ์ฌ์ฉํ๋๋ก ๊ฒ์์ ์ค์ ํ๋ ค๋ฉด Google์ ๊ธฐ์ ์๋ฃ๋ฅผ ์ฐธ๊ณ ํ์ญ์์ค.
- Unity Authentication์ ID ์ ๊ณต์
์ฒด๋ฅผ Google๋ก ์ค์ ํฉ๋๋ค.
- Unity ์๋ํฐ ๋ฉ๋ด์์ Edit > Project Settingsโฆ ๋ก ์ด๋ํ ํ, ๋ด๋น๊ฒ์ด์ ๋ฉ๋ด์์ Services > Authentication์ ์ ํํฉ๋๋ค.
- ID Providers๋ฅผ Google๋ก ์ค์ ํ ํ, Add๋ฅผ ์ ํํฉ๋๋ค.
- Client ID ํ ์คํธ ํ๋์ ์น ์ฑ ํด๋ผ์ด์ธํธ ID๋ฅผ ์ ๋ ฅํ ํ, Save๋ฅผ ์ ํํฉ๋๋ค.
void InitializePlayGamesLogin(){ var config = new PlayGamesClientConfiguration.Builder() // Requests an ID token be generated. // This OAuth token can be used to // identify the player to other services such as Firebase. .RequestIdToken() .Build(); PlayGamesPlatform.InitializeInstance(config); PlayGamesPlatform.DebugLogEnabled = true; PlayGamesPlatform.Activate();}void LoginGoogle(){ Social.localUser.Authenticate(OnGoogleLogin);}void OnGoogleLogin(bool success){ if (success) { // Call Unity Authentication SDK to sign in or link with Google. Debug.Log("Login with Google done. IdToken: " + ((PlayGamesLocalUser)Social.localUser).GetIdToken()); } else { Debug.Log("Unsuccessful login"); }}
๊ธฐ์กด ํ๋ ์ด์ด ๋ก๊ทธ์ธ ๋๋ ์ ๊ท ํ๋ ์ด์ด ์์ฑ
SignInWithGoogleAsync- Google ์๊ฒฉ ์ฆ๋ช ์ ์ฌ์ฉํด ์ Unity Authentication ํ๋ ์ด์ด ์์ฑ
- Google ์๊ฒฉ ์ฆ๋ช ์ ์ฌ์ฉํด ๊ธฐ์กด ํ๋ ์ด์ด ๋ก๊ทธ์ธ
async Task SignInWithGoogleAsync(string idToken){ try { await AuthenticationService.Instance.SignInWithGoogleAsync(idToken); 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 ๊ณ์ ๋ก๊ทธ์ธ์ผ๋ก ์ ๋ฐ์ดํธ
์ต๋ช
์ธ์ฆ์ ์ค์ ํ ํ, ํ๋ ์ด์ด๊ฐ Google ๊ณ์ ์ ์์ฑํ๊ณ Google์ ํตํด ๋ก๊ทธ์ธํ๋๋ก ์
๊ทธ๋ ์ด๋ํ๋ ค๋ ๊ฒฝ์ฐ, ๊ฒ์์ด ํ๋ ์ด์ด์๊ฒ Google ๋ก๊ทธ์ธ ์ฐฝ์ ํ์ํ๊ณ Google์์ ID ํ ํฐ์ ๊ฐ์ ธ์์ผ ํฉ๋๋ค. ๊ทธ๋ฐ ๋ค์ API๋ฅผ ํธ์ถํด ํ๋ ์ด์ด๋ฅผ Google ID ํ ํฐ์ ์ฐ๊ฒฐํฉ๋๋ค.
LinkWithGoogleAsyncSDK์ ์บ์๋ ํ๋ ์ด์ด๊ฐ ์กด์ฌํ๋ ๊ฒฝ์ฐ, ์บ์๋ ํ๋ ์ด์ด๋ฅผ Google ๊ณ์ ์ ์ฐ๊ฒฐํ ์ ์์ต๋๋ค.
- ๋ฅผ ์ฌ์ฉํด ์บ์๋ ํ๋ ์ด์ด์ ๊ณ์ ์ ๋ก๊ทธ์ธํฉ๋๋ค.
SignInAnonymouslyAsync - ๋ฅผ ์ฌ์ฉํด ์บ์๋ ํ๋ ์ด์ด์ ๊ณ์ ์ Google ๊ณ์ ์ ์ฐ๊ฒฐํฉ๋๋ค.
LinkWithGoogleAsync
async Task LinkWithGoogleAsync(string idToken){ try { await AuthenticationService.Instance.LinkWithGoogleAsync(idToken); 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 ๊ณ์ ์ฐ๊ฒฐ ํด์
ํ๋ ์ด์ด๊ฐ Google ๊ณ์ ์ฐ๊ฒฐ์ ํด์ ํ ์ ์๋๋ก API๋ฅผ ์ฌ์ฉํฉ๋๋ค. ์ฐ๊ฒฐ์ด ํด์ ๋๋ฉด ๊ณ์ ์ด ๋ค๋ฅธ ID์ ์ฐ๊ฒฐ๋์ง ์์ ๊ฒฝ์ฐ ์ต๋ช
๊ณ์ ์ผ๋ก ์ ํ๋ฉ๋๋ค.
UnlinkGoogleAsyncasync Task UnlinkGoogleAsync(string idToken){ try { await AuthenticationService.Instance.UnlinkGoogleAsync(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); }}