zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Unity/Assets/Hotfix/Logic/Model/Game/Entity/Common/ChatMessageComponent.cs

43 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using static ET.ChatMessageComponent;
namespace ET
{
public class ChatMessageComponent:Entity
{
public struct MessageInfo
{
public string time;
public string name;
public string content;
public ChatType type;
}
public Dictionary<ChatType, List<MessageInfo>> messageDic = new Dictionary<ChatType, List<MessageInfo>>();
public static ChatMessageComponent Instance;
public const int MaxMessage = 100;
}
public class ChatMessageComponentAwakeSystem : AwakeSystem<ChatMessageComponent>
{
public override void Awake(ChatMessageComponent self)
{
ChatMessageComponent.Instance = self;
}
}
public static class ChatMessageComponentSystem
{
public static void Add(this ChatMessageComponent self,MessageInfo info)
{
if(!self.messageDic.TryGetValue(info.type,out var list))
{
self.messageDic[info.type] =list= new List<MessageInfo>(100);
}
if (list.Count - 1 >= MaxMessage)
{
list.RemoveAt(0);
}
list.Add(info);
}
}
}