添加聊天频道假如 聊天频道退出
This commit is contained in:
parent
5d0f1791a5
commit
3db55540ae
@ -4,5 +4,5 @@ using Fantasy.Entitas;
|
||||
|
||||
public class ChatChannel : Entity
|
||||
{
|
||||
public readonly HashSet<EntityReference<ChatUnit>> ChatUnits = new HashSet<EntityReference<ChatUnit>>();
|
||||
public readonly HashSet<long> ChatUnits = new HashSet<long>();
|
||||
}
|
@ -2,7 +2,7 @@
|
||||
|
||||
using Fantasy.Entitas;
|
||||
|
||||
public class ChatComponent : Entity
|
||||
public class ChatManageComponent : Entity
|
||||
{
|
||||
public readonly Dictionary<long,ChatUnit> ChatUnits = new Dictionary<long, ChatUnit>();
|
||||
}
|
@ -22,7 +22,8 @@ public class OnCreateScene_InitEvent : AsyncEventSystem<OnCreateScene>
|
||||
break;
|
||||
|
||||
case SceneType.Chat:
|
||||
scene.AddComponent<ChatComponent>();
|
||||
scene.AddComponent<ChatManageComponent>();
|
||||
scene.AddComponent<ChatChannelCenterComponent>();
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,58 @@
|
||||
namespace Hotfix;
|
||||
using Fantasy;
|
||||
|
||||
namespace Hotfix;
|
||||
|
||||
|
||||
|
||||
|
||||
public class ChatChannelSystem
|
||||
public static class ChatChannelSystem
|
||||
{
|
||||
|
||||
|
||||
public static void SendMessage(this ChatChannel self, string message)
|
||||
{
|
||||
var chatUnitManage = self.Scene.GetComponent<ChatManageComponent>();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 进入聊天频道
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="chatUnitId"></param>
|
||||
/// <returns></returns>
|
||||
public static bool JoinChatChannel(this ChatChannel self, long chatUnitId)
|
||||
{
|
||||
var chatUnitManage = self.Scene.GetComponent<ChatManageComponent>();
|
||||
|
||||
if (!chatUnitManage.ChatUnits.TryGetValue(chatUnitId,out _))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
self.ChatUnits.Add(chatUnitId);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 退出聊天频道
|
||||
/// </summary>
|
||||
/// <param name="self"></param>
|
||||
/// <param name="chatUnitId"></param>
|
||||
public static void ExitChatChannel(this ChatChannel self, long chatUnitId)
|
||||
{
|
||||
var chatUnitManage = self.Scene.GetComponent<ChatManageComponent>();
|
||||
|
||||
if (!self.ChatUnits.Contains(chatUnitId))
|
||||
{
|
||||
return;
|
||||
}
|
||||
self.ChatUnits.Remove(chatUnitId);
|
||||
|
||||
if (self.ChatUnits.Count == 0)
|
||||
{
|
||||
self.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -2,9 +2,9 @@
|
||||
using Fantasy.Entitas.Interface;
|
||||
|
||||
namespace Hotfix;
|
||||
public class ChatComponentDestroySystem : DestroySystem<ChatComponent>
|
||||
public class ChatManageComponentDestroySystem : DestroySystem<ChatManageComponent>
|
||||
{
|
||||
protected override void Destroy(ChatComponent self)
|
||||
protected override void Destroy(ChatManageComponent self)
|
||||
{
|
||||
foreach (var chatUnit in self.ChatUnits.Values.ToArray())
|
||||
{
|
||||
@ -15,9 +15,9 @@ public class ChatComponentDestroySystem : DestroySystem<ChatComponent>
|
||||
}
|
||||
}
|
||||
|
||||
public static class ChatComponentSystem
|
||||
public static class ChatManageComponentSystem
|
||||
{
|
||||
public static void AddChatUnit(this ChatComponent self,ChatUnit chatUnit)
|
||||
public static void AddChatUnit(this ChatManageComponent self,ChatUnit chatUnit)
|
||||
{
|
||||
if (self.ChatUnits.ContainsKey(chatUnit.RuntimeId))
|
||||
{
|
||||
@ -27,7 +27,7 @@ public static class ChatComponentSystem
|
||||
self.ChatUnits.Add(chatUnit.RuntimeId, chatUnit);
|
||||
}
|
||||
|
||||
public static void RemoveChatUnit(this ChatComponent self, long accountId)
|
||||
public static void RemoveChatUnit(this ChatManageComponent self, long accountId)
|
||||
{
|
||||
if (!self.ChatUnits.Remove(accountId,out var chatUnit))
|
||||
{
|
@ -0,0 +1,22 @@
|
||||
using Fantasy;
|
||||
|
||||
namespace Hotfix;
|
||||
|
||||
public static class ChatChannelCenterComponentHelper
|
||||
{
|
||||
public static ChatChannel Apply(Scene scene, long chatChannelId)
|
||||
{
|
||||
return scene.GetComponent<ChatChannelCenterComponent>().Apply(chatChannelId);
|
||||
}
|
||||
|
||||
|
||||
public static bool TryGetChannel(Scene scene, long chatChannelId,out ChatChannel channel)
|
||||
{
|
||||
return scene.GetComponent<ChatChannelCenterComponent>().TryGetChannel(chatChannelId,out channel);
|
||||
}
|
||||
|
||||
public static bool RemoveChannel(Scene scene, long chatChannelId)
|
||||
{
|
||||
return scene.GetComponent<ChatChannelCenterComponent>().RemoveChannel(chatChannelId);
|
||||
}
|
||||
}
|
@ -6,12 +6,12 @@ public class ChatComponentHelper
|
||||
{
|
||||
public static void AddChatUnit(Scene scene,ChatUnit chatUnit)
|
||||
{
|
||||
scene.GetComponent<ChatComponent>().AddChatUnit(chatUnit);
|
||||
scene.GetComponent<ChatManageComponent>().AddChatUnit(chatUnit);
|
||||
}
|
||||
|
||||
public static void RemoveChatUnit(Scene scene,long accountId)
|
||||
{
|
||||
scene.GetComponent<ChatComponent>().RemoveChatUnit(accountId);
|
||||
scene.GetComponent<ChatManageComponent>().RemoveChatUnit(accountId);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user