PlayFab과 GPGS(Google Play Game Serivce) 연결 방법에 대해 알아보겠습니다.
📚 기본 준비물
유니티와
PlayFab이 연결된 상태유니티와
Google Play Game Service가 연결된 상태
PlayFab에 Google 콘텐츠 추가
PlayFab에 접속합니다.
빌드의
추가 콘텐츠->Google순서로 접속합니다.Google과 연결하려면 다음과 같은 정보가 필요합니다.
Google 앱 패키지 ID
Google 앱 라이선스 키
Google OAuth 클라이언트 ID
Google OAuth 클라이언트 암호
서비스 계정 키 (선택)
차례대로 알아보도록 하겠습니다.
Google 앱 패키지 ID
Google Play Console에 접속합니다.
홈 화면에서 자신이 개발 중인 앱 이름 아래의 ID를 복사하시면 됩니다.
Google 앱 라이선스 키
이 필드는 영수증 유효성 검사를 위한 필드입니다. 로그인과는 관련 없지만 필요하면 넣도록 합시다.
Google Play Console에 접속합니다.
자신의
앱에 접속합니다.메뉴의
수익 창출 설정을 클릭합니다.라이선스를 찾으시고 복사하시면 됩니다.
Google OAuth 클라이언트 ID
Google Cloud Console에 접속합니다.
사용자 인증 정보클릭유니티에 연결할 때 사용했던
클라이언트 ID를 복사하시면 됩니다.
Google OAuth 클라이언트 암호
Google Cloud Console에 접속합니다.
사용자 인증 정보클릭유니티에 연결할 때 사용했던
클라이언트 ID클릭클라이언트 보안 비밀번호를 복사하시면 됩니다.
여기까지 잘 따라오셨으면 설정 저장을 누르시면 됩니다.
Unity 코드 테스트
Unity에서 Google 로그인 후 Google 인증 코드를 가지고 PlayFab에 로그인하는 방법입니다.
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
using System;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using PlayFab;
using PlayFab.ClientModels;
using UnityEngine;
public class TestLogin : MonoBehaviour
{
public void Start()
{
GoogleLogin();
}
// PlayFab Google Login
private void GoogleLogin()
{
// 구글 초기화
GoogleInit();
// 구글 연동 진행
Social.localUser.Authenticate((bool success) =>
{
if (!success)
{
Debug.Log("Google Play 인증 실패!");
return;
}
// 구글 서버 인증코드 가져오기
string serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();
// PlayFab 보낼 메시지 만들기
var request = new LoginWithGoogleAccountRequest()
{
TitleId = PlayFabSettings.TitleId,
ServerAuthCode = serverAuthCode, // 구글 서버 인증 코드
CreateAccount = true // 해당 게정이 없을 때 PlayFab 계정을 자동 생성할지 여부
};
// PlayFab 로그인 요청 보내기
PlayFabClientAPI.LoginWithGoogleAccount(request, OnLoginSuccess, OnLoginFailed);
});
}
// Google Play 초기화
private void GoogleInit()
{
// 구글(GPGS) 초기화 설정
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.AddOauthScope("profile")
.RequestServerAuthCode(false)
.Build();
PlayGamesPlatform.InitializeInstance(config);
// 로그 활성화/비활성화
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
}
// PlayFab 로그인 성공 시 호출
private void OnLoginSuccess(LoginResult result)
{
Debug.Log("PlayFab 로그인 성공!");
Debug.Log("PlayFab Id : " + result.PlayFabId);
}
// PlayFab 로그인 실패 시 호출
private void OnLoginFailed(PlayFabError error)
{
Debug.Log("PlayFab 로그인 실패!");
Debug.Log("PlayFab Error : " + error.ErrorMessage);
}
}