GPGS Achievement
2021. 6. 23. 14:53ㆍNode.js
//GameMain
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
using UnityEngine.UI;
public class GameMain : MonoBehaviour
{
public Text txtUserName;
public Button btnAchievement;
public Button btnAttack;
public GameObject achievementDoing;
public GameObject achievementDone;
public Text txtStep;
public Text txtCount;
private int goalCount = 10;
private int totalSteps = 2;
private int currentCount = 0;
private int currentStep = 1;
//초기화
public void Init(string userName)
{
Debug.Log("userName: " + userName);
string stepKey = string.Format("{0}_step", GPGSIds.achievement__10);
//CgkIoJubiaIZEAIQAw_step
string currentCountKey = string.Format("{0}_currentCount", GPGSIds.achievement__10);
//CgkIoJubiaIZEAIQAw_currentCount
if (PlayerPrefs.GetInt(stepKey) == 0)
{
//처음 이 업적을 실행
PlayerPrefs.SetInt(stepKey, currentStep);
}
else
{
this.currentStep = PlayerPrefs.GetInt(stepKey);
}
if (PlayerPrefs.GetInt(currentCountKey) == 0)
{
//현재 스텝에서 이 업적 처음 실행하는것
}
else
{
this.currentCount = PlayerPrefs.GetInt(currentCountKey);
}
//UI업데이트
this.txtCount.text = string.Format("kill count: {0}/{1}", this.currentCount, this.goalCount);
this.txtStep.text = string.Format("step: {0}/{1}", this.currentStep, this.totalSteps);
this.btnAttack.onClick.AddListener(() => {
this.currentCount++;
//저장
PlayerPrefs.SetInt(currentCountKey, currentCount);
//UI업데이트
this.txtCount.text = string.Format("kill count: {0}/{1}", this.currentCount, this.goalCount);
if (this.currentCount >= this.goalCount)
{
if (this.currentStep >= this.totalSteps)
{
PlayGamesPlatform.Instance.ReportProgress(GPGSIds.achievement__10, 100, (success) => {
if (success)
{
//achievement_doing 게임오브젝트를 비활성화
this.achievementDoing.SetActive(false);
//achievement_done 게임오브젝트를 활성화
this.achievementDone.SetActive(true);
}
});
}
else
{
PlayGamesPlatform.Instance.ReportProgress(GPGSIds.achievement__10, 100, (success) => {
if (success)
{
//스텝을 올려준다
this.currentStep++;
//저장
PlayerPrefs.SetInt(stepKey, this.currentCount);
//UI업데이트
this.txtStep.text = string.Format("step: {0}/{1}", this.currentStep, this.totalSteps);
PlayGamesPlatform.Instance.IncrementAchievement(GPGSIds.achievement__10, this.currentStep, (success) => {
Debug.LogFormat("{0} {1} {2}", GPGSIds.achievement__10, this.currentStep, success);
});
//초기화
this.currentCount = 0;
//저장
PlayerPrefs.SetInt(currentCountKey, this.currentCount);
//UI업데이트
this.txtCount.text = string.Format("kill count: {0}/{1}", this.currentCount, this.goalCount);
}
});
}
}
});
this.txtUserName.text = userName;
this.btnAchievement.onClick.AddListener(() => {
PlayGamesPlatform.Instance.ShowAchievementsUI();
});
PlayGamesPlatform.Instance.IncrementAchievement(GPGSIds.achievement_gpgs_test, 1, (bool success) => {
// handle success or failure
Debug.LogFormat("IncrementAchievement: {0}, {1}", GPGSIds.achievement_gpgs_test, success);
});
}
}
//App
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GooglePlayGames;
using GooglePlayGames.BasicApi;
using UnityEngine.SocialPlatforms;
using GooglePlayGames;
using UnityEngine.SocialPlatforms;
using UnityEngine.SceneManagement;
public class App : MonoBehaviour
{
public enum ePlayMode
{
TEST, BUILD
}
public Text txtVersion;
public Text txtId;
public Text txtUsername;
public Text txtState;
public Image thumb;
public Button btnStart;
public ePlayMode playMode;
// Start is called before the first frame update
void Start()
{
this.txtVersion.text = Application.version;
if (this.playMode == ePlayMode.TEST)
{
btnStart.gameObject.SetActive(true);
}
else
{
btnStart.gameObject.SetActive(false);
}
this.btnStart.onClick.AddListener(() =>
{
//SceneManager.LoadScene("GameScene");
SceneManager.LoadSceneAsync("GameScene").completed+=(oper)=>
{
var gameMain = GameObject.FindObjectOfType<GameMain>();
gameMain.Init(Social.localUser.userName);
};
});
Debug.Log("================================= init GPGS =================================");
PlayGamesClientConfiguration config = new PlayGamesClientConfiguration.Builder()
.EnableSavedGames()
.Build();
PlayGamesPlatform.InitializeInstance(config);
// recommended for debugging:
PlayGamesPlatform.DebugLogEnabled = true;
// Activate the Google Play Games platform
PlayGamesPlatform.Activate();
Debug.Log("================================= authenticate =================================");
// authenticate user:
PlayGamesPlatform.Instance.Authenticate(SignInInteractivity.CanPromptAlways, (result) => {
Debug.Log("================================= result ================================="+result);
Debug.Log("================================= local User ================================="+ Social.localUser);
Debug.Log("================================= autenciated =================================" + Social.localUser.authenticated);
this.txtId.text = Social.localUser.id;
this.txtUsername.text = Social.localUser.userName;
this.txtState.text = Social.localUser.state.ToString();
StartCoroutine(this.WaitforLoadThumb(() =>
{
Debug.Log(Social.localUser.image);
Debug.LogFormat("{0}{1}", Social.localUser.image.width, Social.localUser.image.height);
this.thumb.sprite = Sprite.Create(Social.localUser.image, new Rect(0, 0, Social.localUser.image.width,Social.localUser.image.height), Vector2.zero);
this.thumb.SetNativeSize();
}));
this.btnStart.gameObject.SetActive(true);
});
}
private IEnumerator WaitforLoadThumb(System.Action callback)
{
while (true)
{
if (Social.localUser.image != null)
{
break;
}
yield return null;
}
callback();
}
}
//immortal
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Imortal : MonoBehaviour
{
private void Awake()
{
DontDestroyOnLoad(this.gameObject);
}
}
'Node.js' 카테고리의 다른 글
0630 firebase + google analytics (0) | 2021.06.30 |
---|---|
Naver login (0) | 2021.06.24 |
0617 GPGS (0) | 2021.06.17 |
0616 Sequelize (0) | 2021.06.16 |
0615 express서버와 mysql 커넥션 (0) | 2021.06.15 |