NoticeDataManager.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace GFGGame
  4. {
  5. public class NoticeInfo
  6. {
  7. public int noticeId;
  8. public string title;
  9. public long time;//时间戳,单位秒
  10. public string content = "";
  11. public bool readStatus;//对应的读取状态,true为已读
  12. }
  13. public class NoticeDataManager : SingletonBase<NoticeDataManager>
  14. {
  15. private NoticeInfo _lastNoticeInfo;
  16. public NoticeInfo LastNoticeInfo
  17. {
  18. get
  19. {
  20. return _lastNoticeInfo;
  21. }
  22. set
  23. {
  24. _lastNoticeInfo = value;
  25. }
  26. }
  27. private List<NoticeInfo> _noticeInfos = new List<NoticeInfo>();
  28. public List<NoticeInfo> NoticeInfos
  29. {
  30. get
  31. {
  32. return _noticeInfos;
  33. }
  34. }
  35. private Dictionary<int, NoticeInfo> _noticeInfoDic = new Dictionary<int, NoticeInfo>();
  36. public void UpdateNoticeIdList(NoticeInfo noticeInfo)
  37. {
  38. if (!_noticeInfoDic.ContainsKey(noticeInfo.noticeId))
  39. {
  40. _noticeInfoDic.Add(noticeInfo.noticeId, noticeInfo);
  41. }
  42. else
  43. {
  44. _noticeInfoDic[noticeInfo.noticeId] = noticeInfo;
  45. }
  46. NoticeDicToList();
  47. }
  48. public void UpdateNoticeContent(int noticeId, string content)
  49. {
  50. _noticeInfoDic[noticeId].content = content;
  51. _noticeInfoDic[noticeId].readStatus = true;
  52. NoticeDicToList();
  53. }
  54. public void UpdateSystemNoticeRemove(int noticeId)
  55. {
  56. if (_noticeInfoDic.ContainsKey(noticeId)) _noticeInfoDic.Remove(noticeId);
  57. NoticeDicToList();
  58. }
  59. private void NoticeDicToList()
  60. {
  61. _noticeInfos = _noticeInfoDic.Values.ToList();
  62. _noticeInfos.Sort((NoticeInfo a, NoticeInfo b) =>
  63. {
  64. return b.noticeId.CompareTo(a.noticeId);
  65. });
  66. }
  67. public NoticeInfo GetNoticeInfoById(int noticeId)
  68. {
  69. return _noticeInfoDic[noticeId];
  70. }
  71. }
  72. }