private void purchaseSucceededEvent(Purchase purchase) { Debug.Log("purchaseSucceededEvent: " + purchase); _label = "PURCHASED:" + purchase.ToString(); int diamond = 10; switch (purchase.Sku) { case "package1": diamond = quatity[0]; break; case "package2": diamond = quatity[1]; break; case "package3": diamond = quatity[2]; break; case "package4": diamond = quatity[3]; break; case "package5": diamond = quatity[4]; break; case "package6": diamond = quatity[5]; break; default: break; } Debug.Log("------------------------purchase.Sku " + purchase.Sku + " diamond " + diamond); GoogleAnalytics.instance.LogScreen("Buy Inapp: " + diamond + " diamonds!"); VariableSystem.AddDiamond(diamond); //Consume purchase OpenIAB.consumeProduct(purchase); #if UNITY_ANDROID MobilePlugin.getInstance().ShowToast("Purchase success! You have got " + diamond); #endif }
public static void SaveAchievementCache(bool sendServer = false) { try { Debug.Log("-------------------SaveAchievementCache-----------------"); if (dataAchievementCache != null) { string achievement = ""; for (int i = 0; i < dataAchievementCache.Length; i++) { string s = "" + dataAchievementCache[i].Group + "-" + dataAchievementCache[i].Level + "-" + dataAchievementCache[i].Value + "-" + dataAchievementCache[i].Notify + ","; achievement += s; } //Debug.Log("----------LUU ACHIEVEMENT------------ " + achievement); PlayerPrefs.SetString(Achievement_data_key, achievement); if (FB.IsLoggedIn && sendServer) { //Nếu chưa có playerprefs thì sẽ submit lên luôn //Nếu có rồi thì phải check nó cập nhật hoàn thành từ server về thì mới cho up lên bool check = !PlayerPrefs.HasKey(DataMissionControlNew.key_update_achievement_data_from_server) || (PlayerPrefs.HasKey(DataMissionControlNew.key_update_achievement_data_from_server) && PlayerPrefs.GetInt(DataMissionControlNew.key_update_achievement_data_from_server) == 1); if (check) { AudioControl.getMonoBehaviour().StartCoroutine(DHS.PostMeInfoUpdate(DFB.UserId, "" + VariableSystem.diamond, "" + achievement, "", (www) => { Debug.Log("----------Update achievement to server success!------------- " + achievement); })); } else { Debug.Log("----------KHONG CHO UP ACHIEVEMENT VA DIAMOND LEN SERVER------------- " + PlayerPrefs.GetInt(DataMissionControlNew.key_update_mission_data_from_server, 0)); } } } } catch (Exception e) { Debug.Log("------------ERROR ---------------" + e.Message); if (DataMissionControlNew.test) { MobilePlugin.getInstance().ShowToast("ERROR " + e.Message); } } }
void Start() { AudioControl.DPlayMusicInstance("Nhac menu", true, true); if (GoogleAdmob.interstitial.IsLoaded()) { GoogleAdmob.ShowInterstitial(); } GoogleAdmob.RequestBanner(); #if UNITY_ANDROID && !UNITY_EDITOR if (CheckPackage.check()) { Debug.Log("---------------APP HACK CMNR--------------------"); MobilePlugin.getInstance().ShowToast("HACK CMNR"); Application.Quit(); } else { //MobilePlugin.getInstance().ShowToast("-------------APP KO HACK------------"); } #endif }
public void Update() { time += Time.deltaTime; if (time > 5) { time = 0; if (!GetComponent <UIButton>().enabled) { GetComponent <UIButton>().enabled = true; } } if (Input.GetKeyDown(KeyCode.Escape)) { if (CommonObjectScript.isViewPoppup) { dialogLogin.GetComponent <DialogLogin>().HideDialog(() => { }); CommonObjectScript.isViewPoppup = false; } else { #if UNITY_ANDROID //Application.Quit(); MobilePlugin.getInstance().ShowExitConfirm(MissionControl.Language["Quit"], MissionControl.Language["Quit_detail"], MissionControl.Language["Ok"], MissionControl.Language["Cancel"]); #endif } } if (Input.GetKeyDown(KeyCode.X)) { print("Reset all data saved by PlayerPrefs"); PlayerPrefs.DeleteAll(); VariableSystem.AddDiamond(-(VariableSystem.diamond - 8)); } }
void UpdateServerToClient() { try { DialogLoadingFB.ShowFBLoading(); PlayerPrefs.SetInt(DataMissionControlNew.key_update_mission_data_from_server, 0); PlayerPrefs.SetInt(DataMissionControlNew.key_update_achievement_data_from_server, 0); //Them du lieu tam thoi truoc(de phong truong hop ko truy van dc) for (int i = 0; i < currentMissionServer; i++) { DataCache.UpdateMissionScore(0, 0, i + 1, 1); } //Lay du lieu nguoi dung try { AudioControl.getMonoBehaviour().StartCoroutine(DHS.GetMeInfo(FB.UserId, www => { Debug.Log(JsonHelper.FormatJson(www.text)); IDictionary dict = Json.Deserialize(www.text) as IDictionary; if (dict != null && dict["data"] != null) { List <object> lists = dict["data"] as List <object>; if (lists.Count > 0) { Dictionary <string, object> info = lists[0] as Dictionary <string, object>; int diamond = Convert.ToInt32(info["diamond"]); string achievement = Convert.ToString(info["achievement"]); DataCache.RestoreUserData(diamond, achievement); //GameObject.Find("DialogAchievement").GetComponent<DialogAchievement>().CountAchievementFinish(); string data_mission = Convert.ToString(info["mission_data"]); //Phan tich du lieu va chi lay nhung du lieu co score, star > o client string[] dataMission = data_mission.Split(','); for (int i = 0; i < dataMission.Length; i++) { string[] info_mission = dataMission[i].Split('-'); string mission = info_mission[0]; string score = info_mission[1]; string star = info_mission[2]; string open = info_mission[3]; DataCache.UpdateMissionScore(Convert.ToInt32(score), Convert.ToInt16(star), Convert.ToInt16(mission), Convert.ToInt16(open)); } DataCache.SaveMissionDataCache(); PlayerPrefs.SetInt(DataMissionControlNew.key_update_mission_data_from_server, 1); //Debug.Log("------ Update ------ "); ShowStarMission(); ShowCurrentMission(); DialogLoadingFB.HideFBLoading(); } } }, www => { DialogLoadingFB.HideFBLoading(); ShowRetryLoad(() => { UpdateServerToClient(); }); if (debug) { MobilePlugin.getInstance().ShowToast("Loi response CheckDataMissionServer"); } })); } catch (Exception e) { Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message); } } catch (Exception e) { Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message); } }
//Lay current mission server void CheckDataMissionServer() { try { DialogLoadingFB.ShowFBLoading(); //Debug.Log("Truy van toi server iduser = "******"All current mission :" + JsonHelper.FormatJson(www.text)); bool postToServer = true; IDictionary dict = Json.Deserialize(www.text) as IDictionary; if (dict != null && dict["data"] != null) { List <object> lists = dict["data"] as List <object>; string data_save = ""; for (int i = 1; i <= lists.Count; i++) { Dictionary <string, object> info = lists[i - 1] as Dictionary <string, object>; string id = "" + info["fb_id"]; string mission = "" + info["mission"]; string name = "" + info["name"]; if (data_save.Length > 0) { data_save += ","; } if (id.Equals(FB.UserId)) { //Debug.Log("Mission hien tai truoc so sanh " + CurrentMissionFromClient + " mission " + mission); //neu mission tren server > mission o client moi cap nhat mission cua nguoi choi currentMissionServer = Convert.ToInt16(mission); Debug.Log("Current mission on server " + currentMissionServer); if (currentMissionServer > currentMissionClient || PlayerPrefs.GetInt(DataMissionControlNew.key_update_mission_data_from_server, 1) == 0) { //Update new current data data_save += "Me-" + name + "-" + currentMissionServer; UpdateServerToClient(); postToServer = false; if (PlayerPrefs.GetInt(DataMissionControlNew.key_update_mission_data_from_server, 1) == 0) { Debug.Log("---------------Update lai tu server do chua update day du-------------------"); } } else { data_save += "Me-" + name + "-" + currentMissionClient; } } else { data_save += id + "-" + name + "-" + mission; } } //Debug.Log("" + data_save); if (!String.IsNullOrEmpty(data_save)) { DataCache.SaveCurrentMission(data_save); } } Debug.Log("currentMissionServer " + currentMissionServer); if (postToServer && currentMissionServer < currentMissionClient) { UpdateClientToServer(); } else { Debug.Log("Du lieu cu => ko up"); if (!(currentMissionServer > currentMissionClient)) { DialogLoadingFB.HideFBLoading(); } } }, www => { DialogLoadingFB.HideFBLoading(); Debug.Log("Loi response CheckDataMissionServer"); if (debug) { MobilePlugin.getInstance().ShowToast("Loi response CheckDataMissionServer"); } ShowRetryLoad(() => { Debug.Log("Retry CheckDataMissionServer"); CheckDataMissionServer(); }, () => { }); })); } catch (Exception e) { Debug.Log("--------------------catch error StartCoroutine-------------------" + e.Message); } }