using Fantasy.Async; using Fantasy.Entitas; using Fantasy.Entitas.Interface; using Fantasy.Helper; namespace NB.Chat; public class ChatChannelCenterComponentAwakeSystem : AwakeSystem { protected override void Awake(ChatChannelCenterComponent self) { } } public class ChatChannelCenterComponentDestroySystem : DestroySystem { protected override void Destroy(ChatChannelCenterComponent self) { self.Channels.Clear(); } } public static class ChatChannelCenterComponentSystem { /// /// 获取一个频道 /// /// /// /// public static async FTask Get(this ChatChannelCenterComponent self, long channelId) { if (self.Channels.TryGetValue(channelId, out var channel)) { return channel; } //查数据库 channel = await self.Scene.World.DataBase.Query(channelId, true); if (channel != null) { self.Channels.Add(channel.Id, channel); } return channel; } /// /// 申请创建一个频道 /// /// /// /// public static async FTask Create(this ChatChannelCenterComponent self, ChatUnit unit) { var channel = Entity.Create(self.Scene, true, true); channel.Creator = unit.Role.RoleId; channel.CreateTime = TimeHelper.Now; self.Channels.Add(channel.Id, channel); //保存到数据库 await self.Scene.World.DataBase.Save(channel); return channel; } /// /// 解散 /// /// /// public static void Disband(this ChatChannelCenterComponent self, long channelId) { if (self.Channels.Remove(channelId, out var channel)) { return; } channel?.Dispose(); } }