mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] 接入ET8服务端
[+] 接入ET8服务端
This commit is contained in:
50
Assets/GameScripts/DotNet/Core/Fiber/MailBoxComponent.cs
Normal file
50
Assets/GameScripts/DotNet/Core/Fiber/MailBoxComponent.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
namespace ET
|
||||
{
|
||||
[EntitySystemOf(typeof(MailBoxComponent))]
|
||||
[FriendOf(typeof(MailBoxComponent))]
|
||||
public static partial class MailBoxComponentSystem
|
||||
{
|
||||
[EntitySystem]
|
||||
private static void Awake(this MailBoxComponent self, MailBoxType mailBoxType)
|
||||
{
|
||||
Fiber fiber = self.Fiber();
|
||||
self.MailBoxType = mailBoxType;
|
||||
self.ParentInstanceId = self.Parent.InstanceId;
|
||||
fiber.Mailboxes.Add(self);
|
||||
self.CoroutineLockComponent = fiber.CoroutineLockComponent;
|
||||
}
|
||||
|
||||
[EntitySystem]
|
||||
private static void Destroy(this MailBoxComponent self)
|
||||
{
|
||||
self.Fiber().Mailboxes.Remove(self.ParentInstanceId);
|
||||
}
|
||||
|
||||
// 加到mailbox
|
||||
public static void Add(this MailBoxComponent self, Address fromAddress, MessageObject messageObject)
|
||||
{
|
||||
// 根据mailboxType进行分发处理
|
||||
EventSystem.Instance.Invoke((long)self.MailBoxType, new MailBoxInvoker() {MailBoxComponent = self, MessageObject = messageObject, FromAddress = fromAddress});
|
||||
}
|
||||
}
|
||||
|
||||
public struct MailBoxInvoker
|
||||
{
|
||||
public Address FromAddress;
|
||||
public MessageObject MessageObject;
|
||||
public MailBoxComponent MailBoxComponent;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 挂上这个组件表示该Entity是一个Actor,接收的消息将会队列处理
|
||||
/// </summary>
|
||||
[ComponentOf]
|
||||
public class MailBoxComponent: Entity, IAwake<MailBoxType>, IDestroy
|
||||
{
|
||||
public long ParentInstanceId { get; set; }
|
||||
// Mailbox的类型
|
||||
public MailBoxType MailBoxType { get; set; }
|
||||
|
||||
public CoroutineLockComponent CoroutineLockComponent { get; set; }
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user