MailDataManager.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. namespace GFGGame
  6. {
  7. public class MailInfo
  8. {
  9. public long mailId;//邮件id
  10. public string title;//邮件标题
  11. public long timeSec;//邮件时间戳,单位秒
  12. public string content = "";//邮件内容
  13. public List<ItemData> rewards;
  14. public int state;//邮件状态 0未读, 1已读未领取,2已读已领取
  15. public bool hasItem;//是否有奖励
  16. }
  17. public class MailDataManager : SingletonBase<MailDataManager>
  18. {
  19. public int PageCount = 30;//每次请求数量
  20. public int CurPage = 0;//每次请求数量
  21. private int _totolCount = 0;
  22. public int TotolCount//邮件总数
  23. {
  24. get { return _totolCount; }
  25. set
  26. {
  27. _totolCount = value;
  28. }
  29. }
  30. private int _unreadCount = 0;
  31. public int UnreadCount////未读邮件数量
  32. {
  33. get { return _unreadCount; }
  34. set { _unreadCount = value; }
  35. }
  36. private int _startIndex = 0;
  37. public int StartIndex//起始索引,从0开始
  38. {
  39. get { return _startIndex; }
  40. set { _startIndex = value; }
  41. }
  42. public Dictionary<long, MailInfo> _mailInfoDic = new Dictionary<long, MailInfo>();
  43. public Dictionary<long, MailInfo> MailInfoDic
  44. {
  45. get
  46. {
  47. return _mailInfoDic;
  48. }
  49. }
  50. private Dictionary<int, List<long>> _mailIdsDic = new Dictionary<int, List<long>>();
  51. public List<MailInfo> mailInfos = new List<MailInfo>();
  52. public void RefreshMailInfoDic(bool sort)
  53. {
  54. if (sort)
  55. {
  56. _mailInfoDic.Clear();
  57. _mailIdsDic.Clear();
  58. }
  59. }
  60. public void UpdateMainInfoDic(long mailId, MailInfo mailInfo)
  61. {
  62. if (!_mailInfoDic.ContainsKey(mailId))
  63. {
  64. _mailInfoDic.Add(mailId, mailInfo);
  65. }
  66. else
  67. {
  68. _mailInfoDic[mailId] = mailInfo;
  69. }
  70. }
  71. public void UpdateMailIdList(int page, long mailId)
  72. {
  73. if (!_mailIdsDic.ContainsKey(page))
  74. {
  75. _mailIdsDic.Add(page, new List<long>());
  76. }
  77. _mailIdsDic[page].Add(mailId);
  78. }
  79. public void UpdateMailContent(long mailId, int state, string content = "", List<ItemData> rewards = null)
  80. {
  81. _mailInfoDic[mailId].state = state;
  82. if (content != "") _mailInfoDic[mailId].content = content;
  83. if (rewards != null) _mailInfoDic[mailId].rewards = rewards;
  84. }
  85. public long GetMailIdByIndex(int index)
  86. {
  87. int page = index / PageCount;
  88. int pageIndex = index % PageCount;
  89. if (_mailIdsDic.ContainsKey(page) && _mailIdsDic[page].Count > pageIndex)
  90. {
  91. return _mailIdsDic[page][pageIndex];
  92. }
  93. return -1;
  94. }
  95. public List<long> GetMailIdByPage(int page)
  96. {
  97. if (_mailIdsDic.ContainsKey(page))
  98. {
  99. return _mailIdsDic[page];
  100. }
  101. return null;
  102. }
  103. /// <summary>
  104. /// 根据邮件Id获取邮件信息
  105. /// </summary>
  106. /// <param name="mailId"></param>
  107. /// <returns></returns>
  108. public MailInfo GetMailInfoById(long mailId)
  109. {
  110. if (_mailInfoDic.ContainsKey(mailId))
  111. {
  112. return _mailInfoDic[mailId];
  113. }
  114. return null;
  115. }
  116. //0未读,1无奖已读,2有奖未领,3有奖已领
  117. public int GetMailState(MailInfo data)
  118. {
  119. if (data.hasItem == false)
  120. {
  121. if ((ConstMailStatus)data.state == ConstMailStatus.Unread) return 0;
  122. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedButNotGet) return 1;
  123. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedAndGot) return 1;
  124. }
  125. else
  126. {
  127. if ((ConstMailStatus)data.state == ConstMailStatus.Unread) return 2;
  128. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedButNotGet) return 2;
  129. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedAndGot) return 3;
  130. }
  131. return 0;
  132. }
  133. }
  134. }