12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.Threading;
- namespace ET
- {
- [FriendOf(typeof(NetThreadComponent))]
- public static class NetThreadComponentSystem
- {
- [ObjectSystem]
- public class AwakeSystem: AwakeSystem<NetThreadComponent>
- {
- protected override void Awake(NetThreadComponent self)
- {
- NetThreadComponent.Instance = self;
-
- self.thread = new Thread(self.NetThreadUpdate);
- self.thread.Start();
- }
- }
-
- [ObjectSystem]
- public class LateUpdateSystem: LateUpdateSystem<NetThreadComponent>
- {
- protected override void LateUpdate(NetThreadComponent self)
- {
- self.MainThreadUpdate();
- }
- }
-
- [ObjectSystem]
- public class DestroySystem: DestroySystem<NetThreadComponent>
- {
- protected override void Destroy(NetThreadComponent self)
- {
- NetThreadComponent.Instance = null;
- self.isStop = true;
- self.thread.Join(1000);
- }
- }
-
- private static void MainThreadUpdate(this NetThreadComponent self)
- {
- NetServices.Instance.UpdateInMainThread();
- }
-
- private static void NetThreadUpdate(this NetThreadComponent self)
- {
- while (!self.isStop)
- {
- NetServices.Instance.UpdateInNetThread();
- Thread.Sleep(1);
- }
- }
- }
- }
|