/// <summary> /// 鎖定郵件 - 取得回應 /// </summary> void OnSetMailLockOrNotFinished(HTTPRequest originalRequest, HTTPResponse response) { mask.SetActive(false); if (response == null || response.StatusCode != 200) { Debug.LogError("與伺服器端連接失敗" + response.StatusCode); if (mMessageBoxEvent != null) { mMessageBoxEvent("與伺服器端連接失敗"); } return; } Debug.Log(response.DataAsText); JObject jsonResponse = JsonConvert.DeserializeObject <JObject>(response.DataAsText); if (!jsonResponse.GetValue("result").ToString().Contains("000")) { Debug.LogError("異常錯誤,請聯絡客服單位"); if (mMessageBoxEvent != null) { mMessageBoxEvent("異常錯誤,請聯絡客服單位"); } return; } MailBean bean = currentMail.GetComponent <MailBean>(); bean.isLock = (bool)jsonResponse.GetValue("isLock"); currentMail.transform.Find("UIBtn_Unlock").gameObject.SetActive(bean.isLock); currentMail.transform.Find("UIBtn_Lock").gameObject.SetActive(!bean.isLock); }
/// <summary> /// 領取獎勵或刪除郵件 - 發送要求 /// </summary> public void GetMailRewardOrDelete(GameObject _mail) { SlotSoundManager.bSndRef.PlaySoundEffect(ReferenceCenter.Ref.CommonMu.Container, SlotSoundManager.eAudioClip.Snd_ComClick1.ToString()); currentMail = _mail; MailBean bean = currentMail.GetComponent <MailBean>(); //先檢查有沒有上鎖,如果有上鎖且type為0,則不允許刪除 if (bean.type == 0 && bean.isLock == true) { if (mMessageBoxEvent != null) { mMessageBoxEvent("郵件已上鎖"); } return; } Uri path = new Uri(uri_GetReward); HTTPRequest request = new HTTPRequest(path, HTTPMethods.Post, OnGetMailRewardFinished); Dictionary <string, object> req = new Dictionary <string, object>(); req.Add("AccountName", mAccount); req.Add("guid", mGuid); req.Add("mailNumber", currentMail.GetComponent <MailBean>().mailNumber); request.AddHeader("Content-Type", "application/json"); request.RawData = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(req)); request.Send(); mask.SetActive(true); }
/// <summary> /// 領取獎勵或刪除郵件 - 取得回應 /// </summary> void OnGetMailRewardFinished(HTTPRequest originalRequest, HTTPResponse response) { mask.SetActive(false); if (response == null || response.StatusCode != 200) { Debug.LogError("與伺服器端連接失敗" + response.StatusCode); if (mMessageBoxEvent != null) { mMessageBoxEvent("與伺服器端連接失敗"); } return; } Debug.Log(response.DataAsText); JObject jsonResponse = JsonConvert.DeserializeObject <JObject>(response.DataAsText); if (!jsonResponse.GetValue("result").ToString().Contains("000")) { Debug.LogError("異常錯誤,請聯絡客服單位"); if (mMessageBoxEvent != null) { mMessageBoxEvent("異常錯誤,請聯絡客服單位"); } return; } MailBean bean = currentMail.GetComponent <MailBean>(); switch (bean.type) { case 0: Destroy(currentMail); currentMail = null; break; case 1: bean.type = 0; currentMail.transform.Find("UIBtn_Collect/Text").GetComponent <Text>().text = "刪除"; if (mGetRewardEvent != null) { mGetRewardEvent(1, jsonResponse.GetValue("playerMoney").ToString()); } break; case 2: bean.type = 0; currentMail.transform.Find("UIBtn_Collect/Text").GetComponent <Text>().text = "刪除"; if (mGetRewardEvent != null) { mGetRewardEvent(2, jsonResponse.GetValue("playerExp").ToString()); } break; case 3: bean.type = 0; currentMail.transform.Find("UIBtn_Collect/Text").GetComponent <Text>().text = "刪除"; if (mGetRewardEvent != null) { mGetRewardEvent(3, jsonResponse.GetValue("playerDp").ToString()); } break; } }
/// <summary> /// 取得所有郵件資訊 - 取得回應 /// </summary> private void OnGetAllMailsFinished(HTTPRequest originalRequest, HTTPResponse response) { mask.SetActive(false); if (response == null || response.StatusCode != 200) { Debug.LogError("與伺服器端連接失敗" + response.StatusCode); if (mMessageBoxEvent != null) { mMessageBoxEvent("與伺服器端連接失敗"); } return; } Debug.Log(response.DataAsText); //========= 1. 解析所有信件內容,把他轉成List JObject jsonResponse = JsonConvert.DeserializeObject <JObject>(response.DataAsText); List <Dictionary <string, object> > allMails = JsonConvert.DeserializeObject <List <Dictionary <string, object> > >(jsonResponse.GetValue("mails").ToString()); //========= 2. 開始生成信件(先要判斷是系統信件還是私人信件) bool isSystemMail = false; foreach (Dictionary <string, object> mailDic in allMails) { GameObject mail; if (mailDic["Sender"] == null || mailDic["Sender"].ToString().Equals("系統") || string.IsNullOrEmpty(mailDic["Sender"].ToString())) { mailDic["Sender"] = "系統"; mail = Instantiate(prefab_SystemMail, trans_SystemContent); isSystemMail = true; } else { mail = Instantiate(prefab_PrivateMail, trans_PrivateContent); isSystemMail = false; } //========= 3.將所有的值塞到Bean中 MailBean bean = mail.GetComponent <MailBean>(); bean.mailNumber = mailDic["MailNumber"].ToString(); bean.sender = mailDic["Sender"].ToString(); bean.senderFbId = (mailDic["SenderFbId"] == null)? string.Empty : mailDic["SenderFbId"].ToString(); bean.senderNickName = mailDic["SenderNickName"].ToString(); if (mailDic["SenderIcon"] == null || string.IsNullOrEmpty(mailDic["SenderIcon"].ToString())) { bean.senderIcon = -1; } else { bean.senderIcon = Convert.ToInt32(mailDic["SenderIcon"]); } bean.sendingTime = (DateTime)mailDic["SendingTime"]; bean.deleteTime = (DateTime)mailDic["DeleteTime"]; bean.type = Convert.ToInt32(mailDic["Type"]); bean.eventName = mailDic["EventName"].ToString(); bean.reward = mailDic["Reward"].ToString(); bean.title = mailDic["Title"].ToString(); bean.title_EN = mailDic["Title_EN"].ToString(); bean.content = mailDic["Content"].ToString(); bean.content_EN = mailDic["Content_EN"].ToString(); bean.isRead = Convert.ToBoolean(mailDic["IsRead"]); bean.isHide = Convert.ToBoolean(mailDic["IsHide"]); bean.isLock = Convert.ToBoolean(mailDic["IsLock"]); //========= 4.填到UI中 if (isSystemMail) { mail.transform.Find("UIScroll_Name/Viewport/Content/UITxt_Name").GetComponent <Text>().text = bean.senderNickName; mail.transform.Find("UITxt_Date").GetComponent <Text>().text = bean.sendingTime.ToString("yyyy.MM.dd"); mail.transform.Find("UITxt_Title").GetComponent <Text>().text = bean.title; mail.transform.Find("UIScroll_Content/Viewport/Content/UITxt_Content").GetComponent <Text>().text = bean.content; mail.transform.Find("UIBtn_Lock").gameObject.SetActive(!bean.isLock); mail.transform.Find("UIBtn_Unlock").gameObject.SetActive(bean.isLock); if (bean.type == 0) { mail.transform.Find("UIBtn_Collect/Text").GetComponent <Text>().text = "刪除"; } else { mail.transform.Find("UIBtn_Collect/Text").GetComponent <Text>().text = "領取"; } mail.transform.Find("UIImg_Icon").GetComponent <Image>().sprite = Resources.Load <Sprite>("ScriptImg/Portrait_Icon/Portrait_System"); } else { mail.transform.Find("UIScroll_Name/Viewport/Content/UITxt_Name").GetComponent <Text>().text = bean.senderNickName; mail.transform.Find("UITxt_Date").GetComponent <Text>().text = bean.sendingTime.ToString("yyyy.MM.dd"); JObject jobj = null; int money; if (int.TryParse(bean.reward, out money)) { //mail.transform.Find("Gobj_Money/UITxt_Money").GetComponent<Text>().text = money.ToString(); mail.transform.Find("Gobj_Money/UITxt_Money").GetComponent <Text>().text = string.Format(CultureInfo.InvariantCulture, "{0:#,#}", money); } else { jobj = JsonConvert.DeserializeObject <JObject>(bean.reward); //mail.transform.Find("Gobj_Money/UITxt_Money").GetComponent<Text>().text = jobj.GetValue("money").ToString(); mail.transform.Find("Gobj_Money/UITxt_Money").GetComponent <Text>().text = string.Format(CultureInfo.InvariantCulture, "{0:#,#}", (int)jobj.GetValue("money")); } mail.transform.Find("UIBtn_Lock").gameObject.SetActive(!bean.isLock); mail.transform.Find("UIBtn_Unlock").gameObject.SetActive(bean.isLock); if (bean.type == 0) { mail.transform.Find("UIBtn_Collect/Text").GetComponent <Text>().text = "刪除"; } else { mail.transform.Find("UIBtn_Collect/Text").GetComponent <Text>().text = "領取"; } Generic.IconFetcher.SetIcon(mail.transform.Find("UIImg_Icon").GetComponent <Image>(), bean.senderIcon, bean.senderFbId); } mail.SetActive(true); } }