修改为luban
This commit is contained in:
@@ -1,74 +1,42 @@
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using Fantasy.Helper;
|
||||
|
||||
#pragma warning disable CS8602 // Dereference of a possibly null reference.
|
||||
#pragma warning disable CS8601 // Possible null reference assignment.
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
public class ChatChannelCenterComponentAwakeSystem : AwakeSystem<ChatChannelCenterComponent>
|
||||
{
|
||||
protected override void Awake(ChatChannelCenterComponent self)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class ChatChannelCenterComponentDestroySystem : DestroySystem<ChatChannelCenterComponent>
|
||||
public sealed class ChatChannelCenterComponentDestroySystem : DestroySystem<ChatChannelCenterComponent>
|
||||
{
|
||||
protected override void Destroy(ChatChannelCenterComponent self)
|
||||
{
|
||||
foreach (var chatChannelComponent in self.Channels.Values.ToArray())
|
||||
{
|
||||
chatChannelComponent.Dispose();
|
||||
}
|
||||
self.Channels.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChatChannelCenterComponentSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取一个频道
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="channelId"></param>
|
||||
/// <returns></returns>
|
||||
public static async FTask<ChatChannel?> Get(this ChatChannelCenterComponent self, long channelId)
|
||||
public static ChatChannelComponent Apply(this ChatChannelCenterComponent self, long channelId)
|
||||
{
|
||||
if (self.Channels.TryGetValue(channelId, out var channel))
|
||||
{
|
||||
return channel;
|
||||
}
|
||||
|
||||
//查数据库
|
||||
channel = await self.Scene.World.Database.Query<ChatChannel>(channelId, true);
|
||||
if (channel != null)
|
||||
{
|
||||
self.Channels.Add(channel.Id, channel);
|
||||
}
|
||||
|
||||
channel = Entity.Create<ChatChannelComponent>(self.Scene, channelId, true, true);
|
||||
self.Channels.Add(channelId, channel);
|
||||
return channel;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 申请创建一个频道
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="unit"></param>
|
||||
/// <returns></returns>
|
||||
public static async FTask<ChatChannel> Create(this ChatChannelCenterComponent self, SocialUnit unit)
|
||||
public static bool TryGet(this ChatChannelCenterComponent self, long channelId, out ChatChannelComponent channel)
|
||||
{
|
||||
var channel = Entity.Create<ChatChannel>(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;
|
||||
return self.Channels.TryGetValue(channelId, out channel);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 解散
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="channelId"></param>
|
||||
public static void Disband(this ChatChannelCenterComponent self, long channelId)
|
||||
{
|
||||
if (self.Channels.Remove(channelId, out var channel))
|
||||
@@ -76,6 +44,6 @@ public static class ChatChannelCenterComponentSystem
|
||||
return;
|
||||
}
|
||||
|
||||
channel?.Dispose();
|
||||
channel.Dispose();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user