유니티 구글 플레이 게임즈 연동 v11.01(파이어베이스 연동)
사실 파이어베이스라기보다는 외부 서버에 대한 연동이라고 보는 편이 맞을 것 같다.
우선 유니티 구글 플레이 게임즈 가이드에 나와있는 변동사항을 확인해 보자.
https://developer.android.com/games/preview/multiplatform/pgs-unity-integration-guide?hl=ko
Play 게임즈 서비스 통합 가이드(Unity) | Android 개발자 | Android Developers
Play 게임즈 서비스 통합 가이드(Unity) 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 참고: 네이티브 (C) 버전의 SDK도 EAP에서 사용할 수 있습니다. 액세스 방
developer.android.com
기존에는 PlayGamesPlatform.Instance.getServerAuthCode()를 통해 직접 서버의 코드를 가지고 왔으나, 이제는 PlayGamesPlatform.Instance.RequestServerSideAccess(bool forceRefreshToken, Action<string> callback)을 통해 서버의 엑세스 토큰을 콜백 함수에 넣어주는 방식으로 변경되었다.
forceRefreshToken이 true일 경우에는 새로고침 토큰이 추가로 반환되며 이를 이용해 유저가 게임을 플레이하지 않을 때도 서버에서 플레이 게임즈에 엑세스할 수 있다고 한다.
아래는 구글 플레이 게임즈를 통한 파이어 베이스 로그인 코드
using UnityEngine;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
public class GoogleLogIn : MonoBehaviour
{
private void Start()
{
// 로그인 결과 받아오기
PlayGamesPlatform.Instance.Authenticate(ProcessAuthentication);
}
internal void ProcessAuthentication(SignInStatus status)
{
if (status == SignInStatus.Success)
{
PlayGamesPlatform.Instance.RequestServerSideAccess(
/* forceRefreshToken= */
false,
FirebaseMng.instance.SignIn
);
}
else
{
// 다시 로그인 시도
PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication);
// Disable your integration with Play Games Services or show a login button
// to ask users to sign-in. Clicking it should call
// PlayGamesPlatform.Instance.ManuallyAuthenticate(ProcessAuthentication).
}
}
}
기존 파이어베이스 로그인 함수에 매개변수로 string 변수를 추가하고 PlayGamesPlatform.Instance.getServerAuthCode() 대신 string 변수를 넣어주면 된다.