using System; using System.Collections.Generic; namespace ET { public class DelaySendSyncAttributeComponentAwakeSystem : AwakeSystem { public override void Awake(DelaySendSyncAttributeComponent self) { DelaySendSyncAttributeComponent.instance = self; } } public class DelaySendSyncAttributeComponentUpdateSystem : UpdateSystem { private HashSet needRemoveSet = new HashSet(); public override void Update(DelaySendSyncAttributeComponent self) { foreach (KeyValuePair>> item in self.dic.GetDictionary()) { needRemoveSet.Add(item.Key); List> list = item.Value; Unit unit = MapUnitComponent.Instance.Get(item.Key); if (!unit) { if (unit!=null && Math.Abs(unit.Id) < 100000) { Log.Error($"unit is invalid where id = {item.Key} "); foreach (KeyValuePair kv in item.Value) { Log.Error($"k = {(NumericType)kv.Key}, v ={kv.Value}"); } } continue; } IActorMessage message = null; if (list.Count > 1) { M2C_SyncUnitAttributeList newMessage = new M2C_SyncUnitAttributeList { UnitId = unit.Id }; foreach (KeyValuePair kv in list) { newMessage.NumericMap.Add(new AttributeMap { Key = kv.Key, Value = kv.Value }); } message = newMessage; } else if (list.Count == 1) { KeyValuePair kv = list[0]; message = new M2C_SyncUnitAttribute { UnitId = unit.Id, NumericType = kv.Key, Value = kv.Value }; } if (message != null) unit.GetComponent().BrocastInterval(message); } foreach (long item in needRemoveSet) { self.dic.Remove(item); } needRemoveSet.Clear(); } } public static class DelaySendSyncAttributeComponentSystem { public static void Add(this DelaySendSyncAttributeComponent self, Unit unit, NumericType numericType, float value) { self.dic.Add(unit.Id, KeyValuePair.Create((int)numericType, value)); } } }