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> messageDic = new Dictionary>(); public static ChatMessageComponent Instance; public const int MaxMessage = 100; } public class ChatMessageComponentAwakeSystem : AwakeSystem { 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(100); } if (list.Count - 1 >= MaxMessage) { list.RemoveAt(0); } list.Add(info); } } }