ActorLocationSenderComponentSystem.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections.Generic;
  2. using ETModel;
  3. namespace ETHotfix
  4. {
  5. [ObjectSystem]
  6. public class ActorLocationSenderComponentSystem : StartSystem<ActorLocationSenderComponent>
  7. {
  8. // 每10s扫描一次过期的actorproxy进行回收,过期时间是1分钟
  9. public override async void Start(ActorLocationSenderComponent self)
  10. {
  11. List<long> timeoutActorProxyIds = new List<long>();
  12. while (true)
  13. {
  14. await Game.Scene.GetComponent<TimerComponent>().WaitAsync(10000);
  15. if (self.IsDisposed)
  16. {
  17. return;
  18. }
  19. timeoutActorProxyIds.Clear();
  20. long timeNow = TimeHelper.Now();
  21. foreach (long id in self.ActorLocationSenders.Keys)
  22. {
  23. ActorLocationSender actorLocationMessageSender = self.ActorLocationSenders[id];
  24. if (actorLocationMessageSender == null)
  25. {
  26. continue;
  27. }
  28. if (timeNow < actorLocationMessageSender.LastSendTime + 60 * 1000)
  29. {
  30. continue;
  31. }
  32. timeoutActorProxyIds.Add(id);
  33. }
  34. foreach (long id in timeoutActorProxyIds)
  35. {
  36. self.Remove(id);
  37. }
  38. }
  39. }
  40. }
  41. }