준비물
1. 앱 업로드
https://play.google.com/console/
2. OAuth Client ID
https://console.cloud.google.com/
https://hesterdiary.tistory.com/26
남은 작업
1. Android Config Setup
2. Build 및 테스트
작업 시작
1. Android Config Setup
Unity에 해당 경로로 팝업을 출력한다.
①은 Google Play Console에서 로그인을 한 후
업로드된 앱 보기를 선택한다.
Play 게임 서비스-> 설정 및 관리->설정을 선택한 후
현재 프로젝트 사용자 인증 정보 옆에 리소스보기를 클릭한다.
위의 내용을 복붙하면 된다.
②은 Google Cloud Platform에서
클라이언트ID를 복붙하면 된다.
이제 Setup버튼을 눌러보면
위와 같은 팝업이 뜬다면 성공이다!
2. Build 및 테스트
Scene구성은 위와 같이 하고 로그인에 성공하면 LoginState에 Success가 출력되고 UserName이 출력될 것이다.
using UnityEngine;
using UnityEngine.UI;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
namespace GameScene
{
public class FirstScene : MonoBehaviour
{
[SerializeField] GameObject _objUserNameActiveText = null;
[SerializeField] GameObject _objUserNameDeactiveText = null;
[SerializeField] Button _btnLogin = null;
[SerializeField] private Text _txtUserName = null;
[SerializeField] private Text _txtLoginBtn = null;
[SerializeField] private Text _txtLoginState = null;
private const string _strLogin = "Login";
private const string _strLogout = "Logout";
private const string _strSuccess = "Success";
private const string _strFail = "Fail";
private const string _strDefault = "-";
private void Awake()
{
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
_btnLogin.onClick.AddListener(OnClickLogin);
Refresh();
}
private void Refresh()
{
bool isAuthenticated = Social.localUser.authenticated;
_txtLoginBtn.text = isAuthenticated ? _strLogout : _strLogin;
_txtUserName.text = isAuthenticated ? Social.localUser.userName : string.Empty;
_objUserNameActiveText.SetActive(isAuthenticated);
_objUserNameDeactiveText.SetActive(!isAuthenticated);
}
#region Button Event
private void OnClickLogin()
{
if (!Social.localUser.authenticated)
{
Social.localUser.Authenticate((bool bSuccess) =>
{
_txtLoginState.text = bSuccess ? _strSuccess : _strFail;
Refresh();
});
}
else
{
((PlayGamesPlatform)Social.Active).SignOut();
_txtLoginState.text = _strDefault;
Refresh();
}
}
#endregion
}
}
다른 유튜브와 블로그 주소를 참고해서 적용하였다. 버튼 같은 건 사실 코드로 연결하는 건 나중에 업데이트할 때 불편하니 외부에서 연결해주는 게 좋다.
필수 코드는 아래와 같이 초기화와 인증하는 코드만 들어가면 된다.
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
Social.localUser.Authenticate((bool bSuccess) =>{}); //로그인
((PlayGamesPlatform)Social.Active).SignOut(); //로그아웃
빌드를 한 후에 실행을 시켜보면 아래와 같이 잘 동작하는 걸 확인할 수 있다.
참고:
https://www.youtube.com/watch?v=M6nwu00-VR4&t=971s
'Unity2020.1' 카테고리의 다른 글
[Unity::Addressable] Remote AssetBundle Update받는 방법 (0) | 2021.08.12 |
---|---|
[Unity]async/await 통합 패키지 UniTask (0) | 2021.08.03 |
[Unity]Assets->Open C# Project 폴더가 열리는 현상 (0) | 2021.08.03 |
[Unity::Addressable] AssetBundle 빌드하기 (0) | 2021.07.20 |
[Unity] Assembly 'Assets/ExternalDependencyManager/Editor/Google.IOSResolver_v1.2.162.dll' will not be loaded due to errors (0) | 2021.07.13 |