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();
}
}