MailDataManager.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 List<MailInfo> mailInfos = new List<MailInfo>();
  39. public void UpdateMailInfoList(List<MailInfo> list)
  40. {
  41. mailInfos.Clear();
  42. mailInfos = list;
  43. }
  44. public void UpdateMailContent(long mailId, int state, string content = "", List<ItemData> rewards = null)
  45. {
  46. for (int i = 0; i < mailInfos.Count; i++)
  47. {
  48. if (mailInfos[i].mailId == mailId)
  49. {
  50. mailInfos[i].state = state;
  51. if (content != "") mailInfos[i].content = content;
  52. if (rewards != null) mailInfos[i].rewards = rewards;
  53. break;
  54. }
  55. }
  56. }
  57. /// <summary>
  58. /// 根据邮件Id获取邮件信息
  59. /// </summary>
  60. /// <param name="mailId"></param>
  61. /// <returns></returns>
  62. public MailInfo GetMailInfoById(long mailId)
  63. {
  64. for (int i = 0; i < mailInfos.Count; i++)
  65. {
  66. if (mailInfos[i].mailId == mailId)
  67. {
  68. return mailInfos[i];
  69. }
  70. }
  71. return null;
  72. }
  73. //0未读,1无奖已读,2有奖未领,3有奖已领
  74. public int GetMailState(MailInfo data)
  75. {
  76. if (data.hasItem == false)
  77. {
  78. if ((ConstMailStatus)data.state == ConstMailStatus.Unread) return 0;
  79. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedButNotGet) return 1;
  80. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedAndGot) return 1;
  81. }
  82. else
  83. {
  84. if ((ConstMailStatus)data.state == ConstMailStatus.Unread) return 2;
  85. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedButNotGet) return 2;
  86. if ((ConstMailStatus)data.state == ConstMailStatus.ReadedAndGot) return 3;
  87. }
  88. return 0;
  89. }
  90. }
  91. }