Unity/수업내용

TestGPGS - 구글 플레이에 앱등록하기(연동 로그인 로그아웃)

최승길 2019. 6. 13. 17:42

Google Play Console
https://play.google.com/apps/publish/?hl=ko&account=5791372854232521888#AppListPlace

Google APIs
https://console.developers.google.com/apis/dashboard?project=testgpgs-94684386&folder=&organizationId=

//고객센터
https://support.google.com/googleplay/android-developer/answer/113469?hl=ko

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

//참고영상-24분 27초
https://youtu.be/UkafEdb342A?t=1467


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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
using GooglePlayGames;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
 
public class TestGPGS : MonoBehaviour
{
    public Text txt_Ver;
    public Button btn_SignIn;
    public Button btn_SignOut;
    public Text txt_Result;
    public Text txt_LocalUser;
    public Image img_localUserImage;
 
    void Start()
    {
 
        GPGSManager.Instance.Init();
 
        Debug.LogFormat("Version : {0}", Application.version);
 
        this.txt_Ver.text = Application.version;
 
        this.btn_SignIn.onClick.AddListener(() =>
        {
 
            GPGSManager.Instance.SignIn((result) =>
            {
                if (result)
                {
                    this.txt_Result.text = "로그인 성공";
 
                    var id = Social.localUser.id;
                    var name = Social.localUser.userName;
 
                    StartCoroutine(this.WaitForImage(() =>
                    {
                        img_localUserImage.sprite
                        = Sprite.Create(Social.localUser.image, new Rect(00, Social.localUser.image.width, Social.localUser.image.height), new Vector2(00));
                    }));
                    this.txt_LocalUser.text = string.Format("{0}\n{1}", id, name);
                }
                else
                {
                    this.txt_Result.text = "로그인 실패";
                }
            });
        });
 
        this.btn_SignOut.onClick.AddListener(() => 
        {
            PlayGamesPlatform.Instance.SignOut();
            SceneManager.LoadScene("TestGPGS");
            Debug.Log("로그아웃");
 
        });
    }
 
    private IEnumerator WaitForImage(System.Action onLoaded)
    {
        while (true)
        {
            if (Social.localUser.image != null)
            {
                break;
            }
            yield return null;
        }
 
        onLoaded();
    }
}
 
cs


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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
using System;
 
public class GPGSManager : MonoBehaviour
{
    public static GPGSManager Instance;
 
    void Awake()
    {
        GPGSManager.Instance = this;
    }
 
    public void Init()
    {
        PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder().Build();
 
 
        PlayGamesPlatform.InitializeInstance(config);
        // recommended for debugging:
        PlayGamesPlatform.DebugLogEnabled = true;
        // Activate the Google Play Games platform
        PlayGamesPlatform.Activate();
    }
 
    public void SignIn(System.Action<bool> onResult)
    {
        Social.localUser.Authenticate((bool success) =>
        {
            // handle success or failure
            onResult(success);
        });
    }
 
    public void SignOut()
    {
        PlayGamesPlatform.Instance.SignOut();
    }
}
 
cs