유니티/GPGS

구글 로그인 구현

잼잼재미 2024. 6. 18. 00:07

 

 

1. Google Play Games plugin 추가

https://github.com/playgameservices/play-games-plugin-for-unity/releases

 

Releases · playgameservices/play-games-plugin-for-unity

Google Play Games plugin for Unity. Contribute to playgameservices/play-games-plugin-for-unity development by creating an account on GitHub.

github.com

 

 

 

 

위 깃허브 주소로 이동해서 가장 최신버전의 zip를 다운

 

 

 

 

※ 구글 애드몹과 GPGS를 함께 사용하는 경우

플러그인을 둘 다 모두 Import하면, 빌드 시, 반드시 빌드 에러를 일으킨다.

 

 

 

두 플러그인 중, 이미 하나가 Import 되어 있는 경우, ExternalDependencyManager 체크 해제 후, Import 한다.

(GPGS -> Admob 순으로 설치 했음)

 

 

 

Import 후, Enable 클릭

 

 

<?xml version="1.0" encoding="UTF-8" ?>
<dependencies>
<!-- Internal library dependency generated at build time. 
    It also defines the transitive dependencies on play-services
-->
  <androidPackages>
    <androidPackage spec="com.google.games:gpgs-plugin-support:0.11.01">
      <repositories>
        <repository>Assets/GooglePlayGames/com.google.play.games/Editor/m2repository</repository>
      </repositories>
    </androidPackage>
  </androidPackages>
</dependencies>

 

위와 같은 메세지가 뜬다면, 위 경로의 GooglePlayGamesPluginDependencies 에서 경로를 다음과 같이 수정한다. 수정 후, 유니티 에디터를 껐다가 다시 키면 정상적으로 설치가 완료된다.

 

 

 

위와 같이 에러가 뜨기 때문에, Google.IOS Resolver - General - Validate References 체크 해제를 하고 Apply 해준다.

 

 

 

 

위와 같은 에러가 뜬다면, Project Settings - Player - Other Settings - Configuration - Allow downloads over HTTP 에서 Always allowed로 변경한다.

 

 

2. 구글 플레이 어플리케이션 등록

https://kkln2486.tistory.com/402

 

구글 플레이 업로드

구글 플레이 업로드 1. 초기 빌드 설정 1. Build App Bundle * 2021년 8월부터 구글 플레이에 신규 앱을 출시 할 때, aab 형식으로 업로드 해야 함 * 테스트 시에만 체크를 해제해서 apk 파일로 생성하고, 구

kkln2486.tistory.com

 

https://kkln2486.tistory.com/206

 

게임 빌드 프로세스

Windows용 빌드빌드 과정'File' > 'Build Settings'로 이동   'Platform' 목록에서 'Windows'를 선택하고, 'Switch Platform'을 클릭   원하는 씬을 'Scenes in Build' 목록에 추가   'Player Settings'에서 게임의 설정을

kkln2486.tistory.com

 

테스트용으로 내부테스트으로 등록. 아이콘, 이미지는 임의로 등록 (개발 최종 완료 후, 수정할 것!)

 

 

3. Play 게임즈 설정

Play 게임즈 서비스 프로젝트 만들기

 

 

 

 

이 게임용 클라우드 프로젝트가 없다면 새 클라우드 프로젝트 만들기 진행

 

 

 

 

프로젝트 이름을 성정하고 만들기

 

 

 

생성한 클라우드 프로젝트를 선택하고 사용 클릭

 

 

Google Cloud Platform에서 OAuth 동의 화면 만들기

 

 

 

 

사용자 인증 정보

게임 서버 1개, Android 2개를 추가해야 한다.

 

 

 

OAuth 클라이언트가 없기 때문에 위와 같이 입력하고, OAuth 클라이언트 만들기 클릭

 

 

 

OAuth 클라이언트 ID 클릭하고, 위의 유형, 이름과 동일하게 진행

 

 

 

입력하고 만들기 클릭

 

 

 

생성한 클라이언트를 추가하고 변경사항 저장 클릭

 

 

 

Android 사용자 인증 정보를 2개 추가해야 한다.

 

 

 

 

OAuth 클라이언트 ID 만들기를 클릭하고, 위 정보를 똑같이 입력한다.

 

 

 

만들기 클릭

 

 

 

생성한 클라이언트를 추가하고 변경사항 저장 클릭

 

 

 

업로드 키 인증서에 SHA-1 인증서 지문을 복사한다. 출시 전, 테스트를 할 때 사용

 

 

 

신규 설치에 사용은 체크 해제하고 OAuth 클라이언트 만들기 클릭

 

 

 

OAuth 클라이언트 ID 만들기를 클릭해서 위 정보를 입력

 

 

 

SHA-1 인증서 디지털 지문에는 아까 업로드 키 인증서에서 복사한 부분을 입력한다. 

 

 

 

생성한 클라이언트를 추가하고 변경사항 저장 클릭

 

 

 

위와 같이 사용자 인증 정보에 Android 2개, 게임 서버 1개가 제대로 설정되어있다면 완료

 

 

 

 

 

PUBLISH APP을 클릭하고 확인 클릭, 이제 실제로 게임 서버가 작동 시작

 

 

4. 유니티 셋팅

 

위 내용을 복사

 

 

 

복사한 내용을 붙여넣기 한다.

 

 

 

웹 애플리케이션 유형의 클라이언트 ID를 복사한다.

 

 

 

복사한 내용을 붙여넣기 한다.

 

 

 

Setup 클릭 후, OK 클릭

 

 

 

불필요한 Debug.Log가 많이 출력되므로, 위의 Verbose logging을 체크 해제하고, OK를 클릭한다.

 

 

 

수정 내용을 업데이트 해준다.

 

 

5. 스크립트 작성

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using GooglePlayGames;
using GooglePlayGames.BasicApi;

public class GPGSManager : MonoBehaviour
{
    public void GPGSLogin()
    {
        PlayGamesPlatform.Instance.Authenticate(ProcessAuthentication);
    }

    internal void ProcessAuthentication(SignInStatus status)
    {
        if (status == SignInStatus.Success)
        {
            string displayName = PlayGamesPlatform.Instance.GetUserDisplayName();   // 유저가 변경 가능
            string userID = PlayGamesPlatform.Instance.GetUserId(); // 유저가 변경 불가능

            Debug.Log("로그인 성공, " + "DisplayName : " + displayName + ", UserID : " + userID);
        }
        else
        {
            Debug.Log("로그인 실패");
        }
    }

}

 

* 작성일 기준, Google Play Games plugin 최신 버전인 11 버전에서는 로그아웃 기능이 없어짐! 로그아웃 기능을 이요하려면 10버전을 사용해야 한다.

* 구글 로그인은 유니티 에디터에서는 실행할 수 없다. apk 파일로 빌드해서 모바일로 확인해야 함!