반응형
구글 로그인 SDK 설치
구글 로그인 구현
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using PlayFab;
using PlayFab.ClientModels;
using PlayFab.Json;
using PlayFab.ProfilesModels;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using EntityKey = PlayFab.ProfilesModels.EntityKey;
public class PlayfabManager : MonoBehaviour
{
private void Awake()
{
#if UNITY_ANDROID
GoogleActivate();
#endif
}
private void GoogleActivate() //구글 초기화
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.AddOauthScope("profile")
.RequestServerAuthCode(false)
.Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
}
public void OnClickGoogleLogin() //구글 로그인 버튼
{
#if UNITY_ANDROID
LoginGoogleAuthenticate();
#else
SetEditorOnlyMessage("Only Android Platform");
#endif
}
private void LoginGoogleAuthenticate() //로그인 시도
{
Debug.Log("구글 로그인 시도중");
if (Social.localUser.authenticated)
{
Debug.Log("이미 구글 로그인 되어있는 상태입니다.");
return;
}
Social.localUser.Authenticate((bool success) =>
{
if (!success)
{
Debug.Log("구글 사용자 인증 실패!");
return;
}
var serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();
PlayFabClientAPI.LoginWithGoogleAccount(new LoginWithGoogleAccountRequest()
{
TitleId = PlayFabSettings.TitleId,
ServerAuthCode = serverAuthCode,
CreateAccount = true,
},
result =>
{
Debug.Log("플레이팹 구글 로그인 성공!");
OnLoginSuccess(result);
},
error =>
{
Debug.Log("플레이팹 구글 로그인 실패!");
});
});
}
public void OnClickGoogleLogout() //구글 로그아웃
{
((PlayGamesPlatform)Social.Active).SignOut();
}
public void OnLoginSuccess(LoginResult result) //로그인 결과
{
Debug.Log("Playfab Login Success");
}
}
게스트 로그인 상태에서 구글 로그인으로 전환하기
public void OnClickGoogleLink()
{
#if UNITY_ANDROID
if (!Social.localUser.authenticated)
{
Social.localUser.Authenticate((bool success) =>
{
if (success)
{
var serverAuthCode = PlayGamesPlatform.Instance.GetServerAuthCode();
LinkGoogleAccountRequest request = new LinkGoogleAccountRequest()
{
ForceLink = true,
ServerAuthCode = serverAuthCode
};
PlayFabClientAPI.LinkGoogleAccount(request, result =>
{
Debug.Log("Link Google Account Success");
}, error =>
{
Debug.Log(error.GenerateErrorReport());
});
}
else
{
Debug.Log("Link Google Account Fail");
}
});
}
else
{
Debug.Log("Link Google Account Fail");
}
}
- 플레이팹 사이트 / 추가 콘텐츠 / Google 설정
Google 앱 패키지 Id : com.xxx.xxxx
Google 앱 라이선스 키 : 구글 콘솔 / 수익 창출 설정 / 라이선스 키
- 플레이팹 Api 참고
참고할만한 글
반응형
'개발 > Playfab' 카테고리의 다른 글
유니티 플레이팹 유저 프로필 가져오기 Playfab GetProfile 간단 사용법 (0) | 2022.07.08 |
---|---|
유니티 플레이팹 유저 데이터 불러오기 Playfab GetUserData 간단 사용법 (0) | 2022.07.08 |
유니티 플레이팹 유저 데이터 가져오기 Playfab SetUserData 간단 사용법 (0) | 2022.07.08 |
유니티 플레이팹 통계 저장 불러오기 Playfab GetStatistics 간단 사용법 (0) | 2022.07.02 |
유니티 플레이팹 상점 카테고리 가져오기 Playfab GetCatalog 간단 사용법 (0) | 2022.07.02 |
유니티 플레이팹 유저 인벤토리 가져오기 Playfab GetUserInventory 간단 사용법 (0) | 2022.07.02 |
유니티 플레이팹 게스트 로그인 Playfab Sign In with Guest Login 간단 사용법 (0) | 2022.06.21 |
유니티 플레이팹 패키지 Playfab Unity SDK 설치 (0) | 2022.06.18 |
댓글