MailDataManager.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. private int _totolCount = 0;
  20. public int TotolCount//邮件总数
  21. {
  22. get { return _totolCount; }
  23. set { _totolCount = value; }
  24. }
  25. private int _unreadCount = 0;
  26. public int UnreadCount////未读邮件数量
  27. {
  28. get { return _unreadCount; }
  29. set { _unreadCount = value; }
  30. }
  31. public const int Count = 20;//每次请求个数
  32. private int _startIndex = 0;
  33. public int StartIndex//起始索引,从0开始
  34. {
  35. get { return _startIndex; }
  36. set { _startIndex = value; }
  37. }
  38. public Dictionary<long, MailInfo> mailInfoDic = new Dictionary<long, MailInfo>();
  39. public List<MailInfo> mailInfos = new List<MailInfo>();
  40. public void RefreshMailInfoDic(bool sort)
  41. {
  42. if (sort)
  43. {
  44. mailInfoDic.Clear();
  45. }
  46. }
  47. public void UpdateMainInfoDic(long mailId, MailInfo mailInfo)
  48. {
  49. if (!mailInfoDic.ContainsKey(mailId))
  50. {
  51. mailInfoDic.Add(mailId, mailInfo);
  52. }
  53. else
  54. {
  55. mailInfoDic[mailId] = mailInfo;
  56. }
  57. }
  58. public void UpdateMailContent(long mailId, int state, string content = "", List<ItemData> rewards = null)
  59. {
  60. mailInfoDic[mailId].state = state;
  61. if (content != "") mailInfoDic[mailId].content = content;
  62. if (rewards != null) mailInfoDic[mailId].rewards = rewards;
  63. }
  64. public List<MailInfo> GetMailInfos(int index, int count)
  65. {
  66. List<MailInfo> mailInfos = new List<MailInfo>();
  67. for (int i = 0; i < count; i++)
  68. {
  69. if (index + i + 1 > mailInfoDic.Count) break;
  70. MailInfo mailInfo = mailInfoDic.ElementAt(index + i).Value;
  71. mailInfos.Add(mailInfo);
  72. }
  73. return mailInfos;
  74. }
  75. /// <summary>
  76. /// 根据邮件Id获取邮件信息
  77. /// </summary>
  78. /// <param name="mailId"></param>
  79. /// <returns></returns>
  80. public MailInfo GetMailInfoById(long mailId)
  81. {
  82. // for (int i = 0; i < mailInfos.Count; i++)
  83. // {
  84. // if (mailInfos[i].mailId == mailId)
  85. // {
  86. // return mailInfos[i];
  87. // }
  88. // }
  89. if (mailInfoDic.ContainsKey(mailId)) return mailInfoDic[mailId];
  90. return null;
  91. }
  92. //0未读,1无奖已读,2有奖未领,3有奖已领
  93. public int GetMailState(MailInfo data)
  94. {
  95. if (data.hasItem == false)
  96. {
  97. if ((ConstMailStatus)data.state == ConstMailStatus.Unread) return 0;
  98. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedButNotGet) return 1;
  99. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedAndGot) return 1;
  100. }
  101. else
  102. {
  103. if ((ConstMailStatus)data.state == ConstMailStatus.Unread) return 2;
  104. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedButNotGet) return 2;
  105. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedAndGot) return 3;
  106. }
  107. return 0;
  108. }
  109. }
  110. }