RedDotGroupData.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. using System;
  2. using System.Linq;
  3. using Excel2Json;
  4. using Fort23.UTool;
  5. using Utility;
  6. namespace Fort23.Mono
  7. {
  8. public class RedDotGroupData
  9. {
  10. public int Id;
  11. /// <summary>
  12. /// 红点组ID
  13. /// </summary>
  14. public int GroupId;
  15. /// <summary>
  16. /// key层级 value id和红点信息
  17. /// </summary>
  18. public Map<int, Map<int, RedDotData>> AllRedDotData = new Map<int, Map<int, RedDotData>>();
  19. public void Init(int id)
  20. {
  21. Id = id;
  22. GroupId = ConfigComponent.Instance.Get<ReddotConfig>(id).GroupID;
  23. AddRedDotData(id);
  24. // Update();
  25. }
  26. public void AddRedDotData(int id)
  27. {
  28. ReddotConfig reddotConfig = ConfigComponent.Instance.Get<ReddotConfig>(id);
  29. if (AllRedDotData.ContainsKey(reddotConfig.Layer))
  30. {
  31. RedDotData redDotData = new RedDotData();
  32. redDotData.Id = id;
  33. redDotData.GroupId = GroupId;
  34. redDotData.Layer = reddotConfig.Layer;
  35. redDotData.EnableId = reddotConfig.Enable;
  36. AllRedDotData[reddotConfig.Layer].Add(redDotData.Id, redDotData);
  37. }
  38. else
  39. {
  40. Map<int, RedDotData> redDotDatas = new Map<int, RedDotData>();
  41. RedDotData redDotData = new RedDotData();
  42. redDotData.Id = id;
  43. redDotData.GroupId = GroupId;
  44. redDotData.Layer = reddotConfig.Layer;
  45. redDotData.EnableId = reddotConfig.Enable;
  46. redDotDatas.Add(redDotData.Id, redDotData);
  47. AllRedDotData.Add(redDotData.Layer, redDotDatas);
  48. }
  49. }
  50. public bool TargetLayerIsEnable(int layer)
  51. {
  52. bool isEnable = false;
  53. int count = AllRedDotData.Keys.Count;
  54. for (int i = count - 1; i >= 0; i--) //优先更新最底层红点
  55. {
  56. try
  57. {
  58. int key = AllRedDotData.Keys.ToArray()[i];
  59. Map<int, RedDotData> redDotDatas = AllRedDotData[key];
  60. foreach (var redDotData in redDotDatas)
  61. {
  62. if (redDotData.Value.Layer >= layer)
  63. {
  64. if (redDotData.Value.isEnable)
  65. {
  66. isEnable = true;
  67. break;
  68. }
  69. }
  70. }
  71. }
  72. catch (Exception e)
  73. {
  74. LogTool.Log(e);
  75. return false;
  76. }
  77. }
  78. // foreach (var keyValuePair in AllRedDotData)
  79. return isEnable;
  80. }
  81. public void Update()
  82. {
  83. int count = AllRedDotData.Keys.Count;
  84. for (int i = count - 1; i >= 0; i--) //有限更新最底层红点
  85. {
  86. try
  87. {
  88. int key = AllRedDotData.Keys.ToArray()[i];
  89. Map<int, RedDotData> redDotDatas = AllRedDotData[key];
  90. foreach (var keyValuePair in redDotDatas)
  91. {
  92. keyValuePair.Value.Update();
  93. }
  94. }
  95. catch (Exception e)
  96. {
  97. LogTool.Log(e);
  98. }
  99. }
  100. }
  101. }
  102. }