ServerFrameComponentSystem.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Model;
  2. namespace Hotfix
  3. {
  4. [ObjectSystem]
  5. public class ServerFrameComponentSystem : ObjectSystem<ServerFrameComponent>, IAwake
  6. {
  7. public void Awake()
  8. {
  9. this.Get().Awake();
  10. }
  11. }
  12. public static class ServerFrameComponentEx
  13. {
  14. public static void Awake(this ServerFrameComponent self)
  15. {
  16. self.Frame = 0;
  17. self.FrameMessage = new FrameMessage() {Frame = self.Frame};
  18. self.UpdateFrameAsync();
  19. }
  20. public static async void UpdateFrameAsync(this ServerFrameComponent self)
  21. {
  22. TimerComponent timerComponent = Game.Scene.GetComponent<TimerComponent>();
  23. while (true)
  24. {
  25. if (self.Id == 0)
  26. {
  27. return;
  28. }
  29. await timerComponent.WaitAsync(40);
  30. MessageHelper.Broadcast(self.FrameMessage);
  31. ++self.Frame;
  32. self.FrameMessage = new FrameMessage() { Frame = self.Frame };
  33. }
  34. }
  35. public static void Add(this ServerFrameComponent self, AFrameMessage message)
  36. {
  37. self.FrameMessage.Messages.Add(message);
  38. }
  39. }
  40. }