TestGPGS - 구글 플레이에 앱등록하기-2(업적 연동)

Unity/수업내용 2019. 6. 14. 16:12

단계별 업적은
PlayGamesPlatform.Instance.IncrementAchievement(GPGSIds.achievement_4, 1, (success) => { //무명함수 내용 });
여기에 1은, 1단계씩 증가한다 라는 뜻

일회성 업적은

Social.ReportProgress(GPGSIds.achievement, 100,
(success) =>
{ //무명함수 내용 });
여기에 100은 완료 0은 미완료

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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
using GooglePlayGames;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using System.Linq;
using Newtonsoft.Json;
 
public class TestGPGS : MonoBehaviour
{
    public Text txt_Ver;
 
    public Button btn_SignOut;
    public Button btn_achMenu;//업적 메뉴 보기
    public Button btn_ach1;//버튼누르면 몬스터 1킬
    public Button btn_reward;
 
    public Text txt_reward;
    public Text txt_Result;
    public Text txt_kill;//몬스터 처치수
    public Text txt_goldValue;
    public Text txt_gemValue;
 
    private int kill = 0;
 
    private int killMonsterGoal;//몬스터 목표 처치수
    private int killMonsterAchivementStep = 0;//몬스터처치 단계별 업적 달성 단계
    private Dictionary<int, Increment_Achivement> dicIncrement_Achivement;
    private Dictionary<int, Achivement> dicAchivement;
 
    private List<Achivement> achivementsList = new List<Achivement>();
 
    private int gold = 0;
    private int gem = 0;
    private int rewardType;
    private int rewardValue;
 
    void Start()
    {
        this.dicAchivement = new Dictionary<int, Achivement>();
        this.dicIncrement_Achivement = new Dictionary<int, Increment_Achivement>();
 
        var ta1 = Resources.Load<TextAsset>("achivement");
        var arrAchivement = JsonConvert.DeserializeObject<Achivement[]>(ta1.text);
        this.dicAchivement = arrAchivement.ToDictionary(x => x.id);
 
        var ta2 = Resources.Load<TextAsset>("Incremental_achivement");
        var arrIncremental_achivement = JsonConvert.DeserializeObject<Increment_Achivement[]>(ta2.text);
        this.dicIncrement_Achivement = arrIncremental_achivement.ToDictionary(x => x.id);
 
        var arr1 = this.dicAchivement.Where(x => x.Value.achivement_id == 1);
        foreach (var data in arr1)
        {
            this.achivementsList.Add(data.Value);
        }
 
        GPGSManager.Instance.Init();
 
        Debug.LogFormat("Version : {0}", Application.version);
 
        this.txt_Ver.text = Application.version;
 
        GPGSManager.Instance.SignIn((result) =>
        {
            if (result)
            {
                this.txt_Result.text = "로그인 성공";
                Social.ReportProgress(GPGSIds.achievement, 100, (success) =>
                {
                    if (success)
                    {
                        Debug.Log("비긴허 업적 완료");
                    }
                });
            }
            else
            {
                this.txt_Result.text = "로그인 실패";
            }
        });
 
        this.btn_SignOut.onClick.AddListener(() =>
        {
            GPGSManager.Instance.SignOut();
            SceneManager.LoadScene("TestGPGS");
            Debug.Log("로그아웃");
 
        });
 
        this.btn_achMenu.onClick.AddListener(() =>
        {
            Debug.Log("업적 메뉴 띄우기");
            Social.ShowAchievementsUI();
        });
 
        this.btn_ach1.onClick.AddListener(() =>
        {
            this.kill++;
            this.txt_kill.text = string.Format("몬스터 처치 : {0}/{1}", this.kill, this.dicAchivement[killMonsterAchivementStep].goal_value);
 
            if (this.kill == this.dicAchivement[killMonsterAchivementStep].goal_value)
            {
                PlayGamesPlatform.Instance.IncrementAchievement(GPGSIds.achievement_4, 1, (success) =>
                {
                    Debug.LogFormat("success : {0}", success);
                    if (success)
                    {
                        //보상버튼 활성화
                        this.btn_reward.gameObject.SetActive(true);
                        this.txt_reward.gameObject.SetActive(true);
                        this.rewardType = this.dicAchivement[killMonsterAchivementStep].reward_type;
                        this.rewardValue = this.dicAchivement[killMonsterAchivementStep].reward_val;
                        this.txt_reward.text = string.Format("{0} : {1} 받기", this.rewardType, this.rewardValue);
                    }
                });
                this.killMonsterAchivementStep++;
 
                if (this.kill == this.dicAchivement[this.dicAchivement.Count - 1].goal_value)
                {
                    this.txt_kill.text = string.Format("업적 달성");
                    this.btn_ach1.gameObject.SetActive(false);
 
                }
 
            }
        });
 
        this.btn_reward.onClick.AddListener(() =>
        {
            if (this.rewardType == 0)
            {
                this.gold += this.rewardValue;
            }
            else
            {
                this.gem += this.rewardValue;
            }
 
            this.txt_goldValue.text = this.gold.ToString();
            this.txt_gemValue.text = this.gem.ToString();
            this.btn_reward.gameObject.SetActive(false);
 
        });
    }
 
    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
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) =>
        {
            onResult(success);
        });
    }
 
    public void SignOut()
    {
        PlayGamesPlatform.Instance.SignOut();
    }
}
 
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
// <copyright file="GPGSIds.cs" company="Google Inc.">
// Copyright (C) 2015 Google Inc. All Rights Reserved.
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//    limitations under the License.
// </copyright>
 
///
/// This file is automatically generated DO NOT EDIT!
///
/// These are the constants defined in the Play Games Console for Game Services
/// Resources.
///
 
 
public static class GPGSIds
{
        public const string achievement_4 = "CgkImtHoveUREAIQBQ"; // <GPGSID>
        public const string achievement = "CgkImtHoveUREAIQAQ"; // <GPGSID>
        public const string achievement_2 = "CgkImtHoveUREAIQAg"; // <GPGSID>
        public const string achievement_3 = "CgkImtHoveUREAIQAw"; // <GPGSID>
 
}
 
 
cs


1
2
3
4
5
6
7
8
9
public class Increment_Achivement
{
    public int id;
    public string name;
    public int type;
    public int reward_type;
    public int reward_value;
 
}
cs


1
2
3
4
5
6
7
8
9
public class Achivement
{
    public int id;
    public int achivement_id;
    public int goal_value;
    public int reward_type;
    public int reward_val;
 
}
cs


'Unity > 수업내용' 카테고리의 다른 글

TestGPGS - 구글 플레이에 앱등록하기(연동 로그인 로그아웃)  (0) 2019.06.13
UGUI Test  (0) 2019.05.24
<Test_SunnyLand>짬뿌END  (0) 2019.05.09
<Test_SunnyLand>짬뿌2  (0) 2019.05.08
<Test_SunnyLand>짬뿌  (0) 2019.05.07
: