본문 바로가기
개발/C#

유니티 C# 구글 로그인 Google Play Games GPGS 간단 구현

by SPNK 2022. 6. 19.
반응형

구글 유니티용 SDK 다운로드

 

Unity용 Google Play 게임즈 플러그인 시작하기  |  Android 게임 개발  |  Android Developers

Unity용 Google Play 게임즈 플러그인 시작하기 컬렉션을 사용해 정리하기 내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요. 이 주제에서는 Unity용 Google Play 게임즈 플러그인을 사용하도록 Unit

developer.android.com

 

  • 코드 작성
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using GooglePlayGames.BasicApi;

public class GooglePlayManager : MonoBehaviour
{
    private void Awake() //구글 로그인 초기화
    {
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
        .AddOauthScope("profile")
        .RequestServerAuthCode(false)
        .Build();

        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.DebugLogEnabled = true;
        PlayGamesPlatform.Activate();
    }

    public void Login() //로그인
    {
        if (!Social.localUser.authenticated) //구글 로그인이 안 되어 있을 경우
        {
            Social.localUser.Authenticate((bool bSuccess) =>
            {
                if (bSuccess)
                {
                    Debug.Log("Google Login Success");
                }
                else
                {
                    Debug.Log("Google Login Fall");
                }
            });
        }
    }
    
    public void LogOut() //구글 로그아웃
    {
        ((PlayGamesPlatform)Social.Active).SignOut();
        Debug.Log("Google LogOut");
    }
}
반응형

댓글