聊天频道
This commit is contained in:
39
Hotfix/Chat/Helper/ChatChannelHelper.cs
Normal file
39
Hotfix/Chat/Helper/ChatChannelHelper.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Fantasy;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
public static class ChatChannelHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 申请一个频道
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="channelId"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatChannelComponent Apply(Scene scene, long channelId)
|
||||
{
|
||||
return scene.GetComponent<ChatChannelCenterComponent>().Apply(channelId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试获取一个频道
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="channelId"></param>
|
||||
/// <param name="channel"></param>
|
||||
/// <returns></returns>
|
||||
public static bool TryGet(Scene scene, long channelId, out ChatChannelComponent? channel)
|
||||
{
|
||||
return scene.GetComponent<ChatChannelCenterComponent>().TryGet(channelId, out channel);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解散频道
|
||||
/// </summary>
|
||||
/// <param name="scene"></param>
|
||||
/// <param name="channelId"></param>
|
||||
public static void Disband(Scene scene, long channelId)
|
||||
{
|
||||
scene.GetComponent<ChatChannelCenterComponent>().Disband(channelId);
|
||||
}
|
||||
}
|
||||
51
Hotfix/Chat/System/ChatChannelCenterComponentSystem.cs
Normal file
51
Hotfix/Chat/System/ChatChannelCenterComponentSystem.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using Fantasy.Entitas;
|
||||
|
||||
namespace NB.Chat;
|
||||
|
||||
public static class ChatChannelCenterComponentSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 申请
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="channelId"></param>
|
||||
/// <returns></returns>
|
||||
public static ChatChannelComponent Apply(this ChatChannelCenterComponent self, long channelId)
|
||||
{
|
||||
if (self.Channels.TryGetValue(channelId, out var channel))
|
||||
{
|
||||
return 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="channelId"></param>
|
||||
/// <param name="channel"></param>
|
||||
/// <returns></returns>
|
||||
public static bool TryGet(this ChatChannelCenterComponent self, long channelId, out ChatChannelComponent? 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))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
channel?.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
using Fantasy;
|
||||
using System.Diagnostics;
|
||||
using Fantasy;
|
||||
using Fantasy.Async;
|
||||
using Fantasy.Network;
|
||||
using Fantasy.Network.Interface;
|
||||
using Fantasy.PacketParser;
|
||||
|
||||
namespace NB.Gate;
|
||||
|
||||
@@ -10,10 +13,11 @@ public class Chat2G_ChatMessageHandler : Route<Scene, Chat2G_ChatMessage>
|
||||
{
|
||||
var chatMessage = new Chat2C_Message()
|
||||
{
|
||||
Message = message.Message,
|
||||
Message = new ChatMessageInfo(),
|
||||
};
|
||||
|
||||
var gateUnitManage = scene.GetComponent<GateUnitManageComponent>();
|
||||
|
||||
foreach (var session in gateUnitManage.ForEachUnitSession())
|
||||
{
|
||||
session.Send(chatMessage);
|
||||
|
||||
@@ -42,6 +42,7 @@ public class OnSceneCreate_Init : AsyncEventSystem<OnCreateScene>
|
||||
{
|
||||
//用于管理玩家的组件
|
||||
scene.AddComponent<ChatUnitManageComponent>();
|
||||
scene.AddComponent<ChatChannelCenterComponent>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user