본문 바로가기
개발/Playfab

유니티 플레이팹 페이스북 로그인 Playfab Sign ln with Facebook Login 간단 구현

by SPNK 2022. 7. 19.
반응형

페이스북 유니티 SDK 설치

 

Unity SDK - 문서 - Facebook for Developers

The Unity engine and ecosystem gives developers a world class technology platform from which they can build games that work seamlessly across multiple platforms quickly and effectively. The Facebook SDK for Unity complements Unity Technologies' cross-platf

developers.facebook.com

 

코드 작성

using Facebook.Unity;
using PlayFab;
using PlayFab.ClientModels;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayfabManager : MonoBehaviour
{
    public void OnClickFacebookLogin()
    {
       Debug.Log("페이스북 로그인 시도");

       FB.Init(OnFacebookInitialized);
    }

    public void OnClickFacebookLogout()
    {
       Debug.Log("페이스북 로그아웃");

       FB.LogOut();
    }

    private void OnFacebookInitialized()
    {
       if (FB.IsLoggedIn)
           FB.LogOut();

       // We invoke basic login procedure and pass in the callback to process the result
       FB.LogInWithReadPermissions(null, OnFacebookLoggedIn);
    }

    private void OnFacebookLoggedIn(ILoginResult result)
    {
       if (result == null || string.IsNullOrEmpty(result.Error))
       {
           PlayFabClientAPI.LoginWithFacebook(new LoginWithFacebookRequest
           {
               CreateAccount = true,
               AccessToken = AccessToken.CurrentAccessToken.TokenString
           }, result =>
           {
               Debug.Log("플레이팹 페이스북 로그인 성공!");

               GameStateManager.instance.AutoLogin = true;
               GameStateManager.instance.Login = LoginType.Facebook;

               OnLoginSuccess(result);
           }
       , error => { Debug.Log(error.GenerateErrorReport()); });
       }
       else
       {
           Debug.Log("플레이팹 페이스북 로그인 실패!");
       }
    }
}

 

 


페이스북 Api 참고

 

Facebook 및 Unity를 사용한 PlayFab 인증 설정 - PlayFab

Facebook 및 Unity를 사용한 PlayFab 인증의 예제를 안내합니다.

docs.microsoft.com

 


참고할만한 글

 

플레이팹 Playfab 게스트 로그인 Guest Login 간단 사용법

using PlayFab; using PlayFab.ClientModels; using PlayFab.Json; using PlayFab.ProfilesModels; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using Entity..

parksh3641.tistory.com

 

유니티 플레이팹 구글 로그인 Playfab Sign In with Google Login 간단 구현

구글 로그인 SDK 설치 https://github.com/playgameservices/play-games-plugin-for-unity/tree/master/current-build GitHub - playgameservices/play-games-plugin-for-unity: Google Play Games plugin for Unity Google Play Games plugin for Unity. Contribute t

parksh3641.tistory.com

 

유니티 플레이팹 애플 로그인 Playfab Sign ln with Apple Login 간단 구현

애플 SDK https://github.com/lupidan/apple-signin-unity/releases/tag/v1.4.2 Release Sign in with Apple Unity Plugin v1.4.2 · lupidan/apple-signin-unity Changed Handles empty NSPersonNameComponents sent by Apple when not requesting a name, to be nil nativ

parksh3641.tistory.com

 

반응형

댓글