You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.9 KiB
72 lines
1.9 KiB
using System; |
|
using System.Threading; |
|
|
|
namespace ET |
|
{ |
|
[ObjectSystem] |
|
public class NetThreadComponentAwakeSystem: AwakeSystem<NetThreadComponent> |
|
{ |
|
public override void Awake(NetThreadComponent self) |
|
{ |
|
NetThreadComponent.Instance = self; |
|
|
|
self.ThreadSynchronizationContext = ThreadSynchronizationContext.Instance; |
|
|
|
self.foreachAction = service => service.Update(); |
|
} |
|
} |
|
|
|
[ObjectSystem] |
|
public class NetThreadComponentUpdateSystem: LateUpdateSystem<NetThreadComponent> |
|
{ |
|
public override void LateUpdate(NetThreadComponent self) |
|
{ |
|
self.Services.Foreach(self.foreachAction); |
|
} |
|
} |
|
|
|
[ObjectSystem] |
|
public class NetThreadComponentDestroySystem: DestroySystem<NetThreadComponent> |
|
{ |
|
public override void Destroy(NetThreadComponent self) |
|
{ |
|
self.Stop(); |
|
} |
|
} |
|
|
|
[FriendClass(typeof(NetThreadComponent))] |
|
public static class NetThreadComponentSystem |
|
{ |
|
|
|
public static void Stop(this NetThreadComponent self) |
|
{ |
|
} |
|
|
|
public static void Add(this NetThreadComponent self, AService kService) |
|
{ |
|
// 这里要去下一帧添加,避免foreach错误 |
|
self.ThreadSynchronizationContext.PostNext(() => |
|
{ |
|
if (kService.IsDispose()) |
|
{ |
|
return; |
|
} |
|
self.Services.Add(kService); |
|
}); |
|
} |
|
|
|
public static void Remove(this NetThreadComponent self, AService kService) |
|
{ |
|
// 这里要去下一帧删除,避免foreach错误 |
|
self.ThreadSynchronizationContext.PostNext(() => |
|
{ |
|
if (kService.IsDispose()) |
|
{ |
|
return; |
|
} |
|
self.Services.Remove(kService); |
|
}); |
|
} |
|
|
|
} |
|
} |