반응형

.

안녕하세요.

[Unity] 유니티 구글 플레이 게임 서비스 연동 ( 로그인 하기 ) 를 이어서 구글 플레이 게임 서비스 업적과 리더보드 연동해보겠습니다.

 

[Unity] 구글 플레이 게임 서비스 연동 ( 로그인 하기 )

안녕하세요. 이 글은 이전에 작성한 [Unity] 유니티 구글 플레이 게임 서비스(GPGS) 연동 후 앱 등록을 진행한 것을 기반으로 합니다. [Unity] 유니티 구글 플레이 게임 서비스(GPGS) 연동 후 앱등록 안녕하세요...

scvtwo.tistory.com

1. 업적

구글 플레이 콘솔로 접속합니다.

https://play.google.com/apps/publish/?hl=ko

 

Redirecting...

 

play.google.com

업적 추가 버튼을 누릅니다.

업적을 추가합니다.

업적 이름을 적고 아이콘을 넣습니다.

단계별 업적은 여러 단계가 있는 업적을 추가하려면 설정합니다.

초기 상태는 초기에 업적을 공개할지 안할지 정합니다.

점수는 이게임에서 추가할 업적 점수입니다.

목록 순서는 사용자에게 보는 업적 순서입니다.

 

설정이 다 끝났으면, 저장을 합니다.

그럼 다음과 같이 저장됩니다.

 

 

2. 리더보드

리더보드를 추가해보겠습니다.

리더보드 이름을 적고 저장합니다.

리소스 받기를 눌러서 소스를 복사합니다.

3. API & 서비스

동의해줍니다.

 

Credentials(사용자 인증정보)에서 키이미지를 클릭합니다.

이전 포스팅에서 이미 추가했으므로 확인만하고 다음 단계로 넘어갑니다.

 

4. 유니티 셋팅

추가할 유니티 프로젝트를 실행합니다.

Window - Google Play Games - Setup-Android setup... 를 실행합니다.

이전에 복사한 리더보드 코드를 추가합니다.

그 후 Setup 버튼을 누릅니다.

 

업적 추가, 리더보드 보기, 업적보기 버튼을 추가합니다.

 

코드를 추가합니다.

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
    // 리더보드에 점수등록 후 보기
    public void OnShowLeaderBoard()
    {
        text.text = "ShowLeaderBoard";
        // 1000점을 등록
        Social.ReportScore(1000, GPGSIds.leaderboard_leaderboardtest, (bool bSuccess) =>
        {
            if (bSuccess)
            {
                Debug.Log("ReportLeaderBoard Success");
                text.text = "ReportLeaderBoard Success";
            }
            else
            {
                Debug.Log("ReportLeaderBoard Fall");
                text.text = "ReportLeaderBoard Fail";
            }
        }
        );
        Social.ShowLeaderboardUI();
    }
 
    // 업적보기
    public void OnShowAchievement()
    {
        text.text = "ShowAchievement";
        Social.ShowAchievementsUI();
    }
 
    // 업적추가
    public void OnAddAchievement()
    {
        text.text = "AddAchievement";
 
        Social.ReportProgress(GPGSIds.achievement_achievements1, 100.0f, (bool bSuccess) =>
        {
            if (bSuccess)
            {
                Debug.Log("AddAchievement Success");
                text.text = "AddAchievement Success";
            }
            else
            {
                Debug.Log("AddAchievement Fall");
                text.text = "AddAchievement Fail";
            }
        }
        );
    }
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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Text UI 사용
using UnityEngine.UI;
// 구글 플레이 연동
using GooglePlayGames;
using GooglePlayGames.BasicApi;
 
public class GooglePlayManager : MonoBehaviour
{
    bool bWait = false;
    public Text text;
 
    void Awake()
    {
        PlayGamesPlatform.InitializeInstance(new PlayGamesClientConfiguration.Builder().Build());
        PlayGamesPlatform.DebugLogEnabled = true;
        PlayGamesPlatform.Activate();
 
        text.text = "no Login";
    }
    // Start is called before the first frame update
    void Start()
    {
        
    }
 
    // Update is called once per frame
    void Update()
    {
        
    }
 
    public void OnLogin()
    {
        if (!Social.localUser.authenticated)
        {
            Social.localUser.Authenticate((bool bSuccess) =>
            {
                if (bSuccess)
                {
                    Debug.Log("Success : " + Social.localUser.userName);
                    text.text = Social.localUser.userName;
                }
                else
                {
                    Debug.Log("Fall");
                    text.text = "Fail";
                }
            });
        }
    }
 
    public void OnLogOut()
    {
        ((PlayGamesPlatform)Social.Active).SignOut();
        text.text = "Logout";
    }
 
    // 리더보드에 점수등록 후 보기
    public void OnShowLeaderBoard()
    {
        text.text = "ShowLeaderBoard";
        // 1000점을 등록
        Social.ReportScore(1000, GPGSIds.leaderboard_leaderboardtest, (bool bSuccess) =>
        {
            if (bSuccess)
            {
                Debug.Log("ReportLeaderBoard Success");
                text.text = "ReportLeaderBoard Success";
            }
            else
            {
                Debug.Log("ReportLeaderBoard Fall");
                text.text = "ReportLeaderBoard Fail";
            }
        }
        );
        Social.ShowLeaderboardUI();
    }
 
    // 업적보기
    public void OnShowAchievement()
    {
        text.text = "ShowAchievement";
        Social.ShowAchievementsUI();
    }
 
    // 업적추가
    public void OnAddAchievement()
    {
        text.text = "AddAchievement";
 
        Social.ReportProgress(GPGSIds.achievement_achievements1, 100.0f, (bool bSuccess) =>
        {
            if (bSuccess)
            {
                Debug.Log("AddAchievement Success");
                text.text = "AddAchievement Success";
            }
            else
            {
                Debug.Log("AddAchievement Fall");
                text.text = "AddAchievement Fail";
            }
        }
        );
    }
}
 
cs

버튼에 메서드를 연결합니다.

 

Show LeaderBoard버튼을 눌렀을 때

Add Achievements 버튼을 누른 후, Show Achievements을 눌렀을 때.

 

그리고 apk로 폰이나 애뮬레이터에서 테스트할 때에는 꼭 테스터를 추가해야 합니다.

테스트가 끝난 후

게임출시가 가능합니다.

 

 

이전 "구글플레이 게임서비스연동(로그인하기)"편이 궁금하시다면 클릭하세요~!

 

[Unity] 구글 플레이 게임 서비스 연동 ( 로그인 하기 )

안녕하세요. 이 글은 이전에 작성한 [Unity] 유니티 구글 플레이 게임 서비스(GPGS) 연동 후 앱 등록을 진행한 것을 기반으로 합니다. 구글 플레이에서 다운로드한 게임을 보면 등록된 구글 계정으로 로그인해서..

scvtwo.tistory.com

읽어주셔서 감사합니다~! 수정할 부분이나 질문은 댓글 달아주세요!

 

반응형

+ Recent posts