일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Class
- 문제풀이
- Unreal Engine 5
- 시작해요 언리얼 2022
- dfs
- 재귀
- Algorithm
- W3Schools
- DP
- c++
- 기초
- 파이썬
- UE5
- 프로그래밍
- Programming
- Material
- w3school
- 백준
- loop
- String
- github
- Basic
- Unity
- python
- parameter
- guide
- dynamic
- Tutorial
- C#
- 오류
- Today
- Total
행복한 개구리
소셜로그인 21.06.30. Firebase - Google 본문
Unity 프로젝트에 Firebase 추가
Unity 프로젝트에 Firebase 추가plat_iosplat_androidplat_unity Firebase Unity SDK를 활용하여 Unity 게임을 업그레이드 해보세요. Firebase를 Unity 프로젝트에 연결하는 것이 얼마나 간편한지 보여드리기 위해 Google
firebase.google.com
Firebase docs
나는 두개의 앱이 이름이 같지만 둘의 ID가 다르기때문에 ID로 구분할 수 있었다.
여기까지 했다면 다음 설정창이 나온다.
유니티 로고 클릭
Firebase SDK를 추가해야한다.
이후 아까 3단계에서 다운받은 firebase SDK를 압축을 풀어준 뒤 우리가 필요한 Auth(인증)을 유니티 프로젝트에 임포트하자.
나는 2019이후 버전이므로 dotnet4패키지를 사용했다.
여기까지 설정이 되었다면 이제 Android Setup에 들어가서 Firebase에서 생성한 WebClientID를 클라이언트 ID로서 새롭게 입력해주자.
이 다음에는 GoogleIdToken을 얻기 위해 조금의 코드를 추가해보자.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
using UnityEngine.SceneManagement;
public class App : MonoBehaviour
{
public enum ePlayMode
{
Test, Build
}
public Text version;
public Text txtId;
public Text txtUserName;
public Text txtState;
public Image thumb; //아바타 이미지
public Button btnStart;
public ePlayMode playMode;
void Start()
{
if (playMode == ePlayMode.Test)
{
this.btnStart.gameObject.SetActive(true);
}
else
{
this.btnStart.gameObject.SetActive(false);
}
this.btnStart.onClick.AddListener(() =>
{
SceneManager.LoadSceneAsync("GameScene").completed += (oper) =>
{
GameMain gameMain = GameObject.FindObjectOfType<GameMain>();
gameMain.Init(Social.localUser.userName);
};
});
this.version.text = Application.version;
Debug.Log("==================== Init GPGS");
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.RequestIdToken()
.Build();
PlayGamesPlatform.InitializeInstance(config);
PlayGamesPlatform.DebugLogEnabled = true;
PlayGamesPlatform.Activate();
Debug.Log("==================== Authenticate");
PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptOnce, (result) => {
this.txtState.text = result.ToString();
if (result == SignInStatus.Success)
{
var localUser = (PlayGamesLocalUser)Social.localUser;
var googleIdToken = localUser.GetIdToken();
Debug.LogFormat("googleIdToken: {0}", googleIdToken);
Firebase.Auth.FirebaseAuth auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
Firebase.Auth.Credential credential =
Firebase.Auth.GoogleAuthProvider.GetCredential(googleIdToken, null);
auth.SignInWithCredentialAsync(credential).ContinueWith(task => {
if (task.IsCanceled)
{
Debug.LogError("SignInWithCredentialAsync was canceled.");
return;
}
if (task.IsFaulted)
{
Debug.LogError("SignInWithCredentialAsync encountered an error: " + task.Exception);
return;
}
Firebase.Auth.FirebaseUser newUser = task.Result;
Debug.LogFormat("User signed in successfully: {0} ({1})",
newUser.DisplayName, newUser.UserId);
});
}
});
}
}
GoogleIdToken을 받아서 해당 ID토큰을 이용하여 Firebase에 인증을 시도하는 코드이다.
그리고 NOX의 adb를 사용하여 로그를 살펴보면 구글ID토큰이 제대로 들어오는 것을 확인할 수 있다.
'소셜 로그인 > 수업내용' 카테고리의 다른 글
소셜로그인 수업내용 21.07.08. 카카오로그인 (0) | 2021.07.08 |
---|---|
소셜로그인 21.07.08. 구글 애널리틱스(Google Analytics) (0) | 2021.07.08 |
Unity 수업내용 21.06.24. Naver로그인 (0) | 2021.06.24 |
Unity 수업내용 21.06.24 GPGS LeaderBoard (0) | 2021.06.24 |
Unity 수업내용 21.06.23. GPGS 업적 (0) | 2021.06.23 |