//public int UnReadMailnum = 0; public override void Initialize(Config config) { Instance.Api = new MailAPI(); Instance.Api.ErrorHandler += ErrorHandler; MailList = GameDataSparxManager.Instance.Register <MailList>(ListDataId); }
private void OnMailListListener(string path, INodeData data) { MailList mails = data as MailList; if (mails == null || !mails.DataUpdated) { return; } mails.DataUpdated = false; if (mFirstOpen && mails.Mails != null) { for (int i = 0; i < mails.Mails.Count - 1; i++) { for (int j = 0; j < mails.Mails.Count - 1 - i; j++) { if (mails.Mails[j].Time < mails.Mails[j + 1].Time) { var bottle = mails.Mails[j]; mails.Mails[j] = mails.Mails[j + 1]; mails.Mails[j + 1] = bottle; } } } for (int i = 0; i < mails.Mails.Count - 1; i++) { for (int j = 0; j < mails.Mails.Count - 1 - i; j++) { if (mails.Mails[j].HasRead == true && mails.Mails[j + 1].HasRead == false) { var bottle = mails.Mails[j]; mails.Mails[j] = mails.Mails[j + 1]; mails.Mails[j + 1] = bottle; } } } } if (mails.Mails != null) { System.Array sourceArr = mails.Mails.ToArray(); int sourceLength = sourceArr.Length; int copyLength = sourceLength > MailBoxManager.Instance.CapacityNum ? MailBoxManager.Instance.CapacityNum : sourceLength; MailItemData[] targetArr = new MailItemData[copyLength]; System.Array.Copy(sourceArr, targetArr, copyLength); if (targetArr.Length > 0) { //如果在邮件界面 服务器主动推送就不会刷新右侧界面的Bug if (mFirstOpen || targetArr.Length == 1) { OnClickMailCell(targetArr[0]); } if (MailListScroll != null) { MailListScroll.SetItemDatas(targetArr); } LTUIUtil.SetText(controller.UiLabels["UnReadLabel"], mails.Mails.FindAll(m => !m.HasRead).Count.ToString()); LTUIUtil.SetText(controller.UiLabels["MailCapacityLabel"], string.Format("{0}/{1}", mails.Mails.Count, MailBoxManager.Instance.CapacityNum)); controller.GObjects["ContentFrame"].gameObject.SetActive(true); } else { controller.GObjects["ContentFrame"].gameObject.SetActive(false); } } bool HaveUnReceivedMail = false; if (MailBoxManager.Instance.MailList != null && MailBoxManager.Instance.MailList.Mails != null) { for (var i = 0; i < MailBoxManager.Instance.MailList.Mails.Count; i++) { var mail = MailBoxManager.Instance.MailList.Mails[i]; if (!mail.HasReceived && mail.ItemCount > 0) { HaveUnReceivedMail = true; } } } controller.GObjects["OneKeyRec"].SetActive(HaveUnReceivedMail); controller.GObjects["OneKeyDel"].SetActive(!HaveUnReceivedMail); mFirstOpen = false; }