RedDotWidget.cs 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System.Linq;
  2. using Core.Event.Event;
  3. using Excel2Json;
  4. using Fort23.Core;
  5. using Fort23.UTool;
  6. using UnityEngine;
  7. public class RedDotWidget : MonoBehaviour
  8. {
  9. public int RedDotConfigId;
  10. public int GroupId;
  11. public int Layer;
  12. public int[] LinkGroupIds;
  13. public int UnlockId;
  14. public GameObject RedDotRoot;
  15. [ContextMenu("test")]
  16. public void Test()
  17. {
  18. RedDotUpdate(new DefaultEventData(){eventData = 0});
  19. }
  20. public void Start()
  21. {
  22. EventManager.Instance.RemoveEventListener(CustomEventType.RedDotUpdate, RedDotUpdate);
  23. EventManager.Instance.AddEventListener(CustomEventType.RedDotUpdate, RedDotUpdate);
  24. EventManager.Instance.RemoveEventListener(CustomEventType.RedDotChangeState, RedDotChangeState);
  25. EventManager.Instance.AddEventListener(CustomEventType.RedDotChangeState, RedDotChangeState);
  26. ReddotConfig reddotConfig = ConfigComponent.Instance.Get<ReddotConfig>(RedDotConfigId);
  27. RedDotRoot.SetActive(false);
  28. GroupId = reddotConfig.GroupID;
  29. Layer = reddotConfig.Layer;
  30. LinkGroupIds = reddotConfig.LinkGroupID;
  31. RedDotUpdate(new DefaultEventData(){eventData = 0});
  32. }
  33. private void RedDotChangeState(IEventData e)
  34. {
  35. if (UnlockId != 0)
  36. {
  37. if (!ULockManager.Instance.IsULock(UnlockId))
  38. {
  39. return;
  40. }
  41. }
  42. ReddotConfig reddotConfig = ConfigComponent.Instance.Get<ReddotConfig>(RedDotConfigId);
  43. DefaultEventData data = (DefaultEventData)e;
  44. int[] eventData = data.eventData as int[];
  45. if (eventData[0] == RedDotConfigId)
  46. {
  47. if (eventData[1] == 0)
  48. {
  49. // if (reddotConfig.Visible == 1)
  50. {
  51. RedDotRoot.SetActive(false);
  52. }
  53. }
  54. else
  55. {
  56. RedDotRoot.SetActive(true);
  57. }
  58. }
  59. }
  60. public void CustomInit(int reddDotConfigId)
  61. {
  62. RedDotConfigId = reddDotConfigId;
  63. EventManager.Instance.RemoveEventListener(CustomEventType.RedDotUpdate, RedDotUpdate);
  64. EventManager.Instance.AddEventListener(CustomEventType.RedDotUpdate, RedDotUpdate);
  65. EventManager.Instance.RemoveEventListener(CustomEventType.RedDotChangeState, RedDotChangeState);
  66. EventManager.Instance.AddEventListener(CustomEventType.RedDotChangeState, RedDotChangeState);
  67. ReddotConfig reddotConfig = ConfigComponent.Instance.Get<ReddotConfig>(RedDotConfigId);
  68. RedDotRoot.SetActive(false);
  69. GroupId = reddotConfig.GroupID;
  70. Layer = reddotConfig.Layer;
  71. LinkGroupIds = reddotConfig.LinkGroupID;
  72. RedDotUpdate(new DefaultEventData(){eventData = 0});
  73. }
  74. private void RedDotUpdate(IEventData e)
  75. {
  76. DefaultEventData data = (DefaultEventData)e;
  77. if ((int)data.eventData != 0 && (int)data.eventData != GroupId)
  78. {
  79. return;
  80. }
  81. if (UnlockId != 0)
  82. {
  83. if (ULockManager.Instance.IsULock(UnlockId))
  84. {
  85. if (RedDotManager.Instance.TargetRedDotIsEnable(RedDotConfigId))
  86. {
  87. RedDotRoot.SetActive(true);
  88. ReddotConfig reddotConfig = ConfigComponent.Instance.Get<ReddotConfig>(RedDotConfigId);
  89. if (reddotConfig.EnableForTarget != 0)
  90. {
  91. bool isEnable = RedDotManager.Instance.TargetRedDotIsEnable2(reddotConfig.EnableForTarget);
  92. if (isEnable)
  93. {
  94. RedDotRoot.SetActive(true);
  95. }
  96. else
  97. {
  98. RedDotRoot.SetActive(false);
  99. }
  100. }
  101. }
  102. else
  103. {
  104. RedDotRoot.SetActive(false);
  105. }
  106. }
  107. }
  108. else
  109. {
  110. if (RedDotManager.Instance.TargetRedDotIsEnable(RedDotConfigId))
  111. {
  112. RedDotRoot.SetActive(true);
  113. ReddotConfig reddotConfig = ConfigComponent.Instance.Get<ReddotConfig>(RedDotConfigId);
  114. if (reddotConfig.EnableForTarget != 0)
  115. {
  116. bool isEnable = RedDotManager.Instance.TargetRedDotIsEnable2(reddotConfig.EnableForTarget);
  117. if (isEnable)
  118. {
  119. RedDotRoot.SetActive(true);
  120. }
  121. else
  122. {
  123. RedDotRoot.SetActive(false);
  124. }
  125. }
  126. }
  127. else
  128. {
  129. RedDotRoot.SetActive(false);
  130. }
  131. }
  132. }
  133. public void OnDestroy()
  134. {
  135. EventManager.Instance.RemoveEventListener(CustomEventType.RedDotUpdate, RedDotUpdate);
  136. EventManager.Instance.RemoveEventListener(CustomEventType.RedDotChangeState, RedDotChangeState);
  137. }
  138. }