ActorLocationSenderComponentSystem.cs 1.6 KB

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