[Unity] 유니티 플러그인, Unity Plugin, GPGS로그인

APP 2020. 1. 29. 17:16

 

1.깃허브의 플러그인 받기

 

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

 

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

 

 

2.압축을 풀면 나오는 유니티 패키지를 내가 빌드한 유니티 프로젝트에 풀어넣기

 

 

 

 

3.jdk 다운로드( Windows x64로 받음)

 

https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

 

Java SE Development Kit 8 - Downloads

Java SE Development Kit 8 Downloads Thank you for downloading this release of the Java™ Platform, Standard Edition Development Kit (JDK™). The JDK is a development environment for building applications, applets, and components using the Java programming la

www.oracle.com

 

 

 

 

 

 

4.환경변수 설정

 

윈도우 키 누르고 환경이라고 검색하면 시스템 환경 변수 편집 나옴

 

환경변수>>시스템변수>>새로만들기 에서

 

변수이름을                     JAVA_HOME

디렉터리 찾아보기로         나의자바가 설치된 폴더를 선택한다.  (C:\Program Files\Java\jdk1.8.0_241)

 

시스템변수 Path로 들어가서 새로만들기

 

%JAVA_HOME%\bin

 

이라고 추가해준다.

 

 

 

 

 

5. GPGS 라이브러리 받기

 

 

Resolve에 성공했다면 GPGSIds라는 스크립트가 생긴다

 

 

 

6. GPGS를 위한 코드 작성하기

Init 메서드 안에 있는 내용은 github의

https://github.com/playgameservices/play-games-plugin-for-unity#configuration--initialization-play-game-services 

 

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

 

Configuration & Initialization Play Game Services 부분에 있고 필요없는 부분은 주석처리 하였다.

 

 

GPGSManager 스크립트

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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
 
public class GPGSManager : MonoBehaviour
{
    public static GPGSManager instance;
 
    public void Awake()
    {
        GPGSManager.instance = this;
    }
    public void Init()
    {
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
            // enables saving game progress.
            //.EnableSavedGames()
            // registers a callback to handle game invitations received while the game is not running.
            // .WithInvitationDelegate(< callback method >)
            // registers a callback for turn based match notifications received while the
            // game is not running.
            //.WithMatchDelegate(< callback method >)
            // requests the email address of the player be available.
            // Will bring up a prompt for consent.
            //.RequestEmail()
            // requests a server auth code be generated so it can be passed to an
            //  associated back end server application and exchanged for an OAuth token.
            //.RequestServerAuthCode(false)
            // requests an ID token be generated.  This OAuth token can be used to
            //  identify the player to other services such as Firebase.
            //.RequestIdToken()
            .Build();
 
        PlayGamesPlatform.InitializeInstance(config);
        // recommended for debugging:
        PlayGamesPlatform.DebugLogEnabled = true;
        // Activate the Google Play Games platform
        PlayGamesPlatform.Activate();
    }
    public void SignIn(System.Action<bool> complete)
    {
        // authenticate user:
        Social.localUser.Authenticate((bool success) =>
        {
            // handle success or failure
 
            Debug.Log(success);
            complete(success);
        });
    }
 
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

 

Test스크립트

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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
    public Button btnSignIn;
    public Text txt;
    public System.Action<bool> OnComplete;
    // Start is called before the first frame update
    void Start()
    {
 
 
        OnComplete = (success) =>
        {
            this.txt.text = success.ToString();
        };
 
        this.btnSignIn.onClick.AddListener(() =>
        {
            Debug.Log("SignIn Button Pressed");
        });
 
    }
 
}
 
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
 

 

 

 

: