2021-04-08 20:09:59 +08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace ET
|
|
|
|
|
{
|
|
|
|
|
public class DelaySendSyncAttributeComponentAwakeSystem : AwakeSystem<DelaySendSyncAttributeComponent>
|
|
|
|
|
{
|
|
|
|
|
public override void Awake(DelaySendSyncAttributeComponent self)
|
|
|
|
|
{
|
|
|
|
|
DelaySendSyncAttributeComponent.instance = self;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public class DelaySendSyncAttributeComponentUpdateSystem : UpdateSystem<DelaySendSyncAttributeComponent>
|
|
|
|
|
{
|
|
|
|
|
private HashSet<long> needRemoveSet = new HashSet<long>();
|
|
|
|
|
public override void Update(DelaySendSyncAttributeComponent self)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (KeyValuePair<long, List<KeyValuePair<int, float>>> item in self.dic.GetDictionary())
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
needRemoveSet.Add(item.Key);
|
2021-04-11 19:50:39 +08:00
|
|
|
|
List<KeyValuePair<int, float>> list = item.Value;
|
2021-04-08 20:09:59 +08:00
|
|
|
|
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} ");
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (KeyValuePair<int, float> kv in item.Value)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
Log.Error($"k = {(NumericType)kv.Key}, v ={kv.Value}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
IActorMessage message = null;
|
|
|
|
|
if (list.Count > 1)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
M2C_SyncUnitAttributeList newMessage = new M2C_SyncUnitAttributeList
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
UnitId = unit.Id
|
|
|
|
|
};
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (KeyValuePair<int, float> kv in list)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
newMessage.NumericMap.Add(new AttributeMap
|
|
|
|
|
{
|
|
|
|
|
Key = kv.Key,
|
|
|
|
|
Value = kv.Value
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
message = newMessage;
|
|
|
|
|
}
|
|
|
|
|
else if (list.Count == 1)
|
|
|
|
|
{
|
2021-04-11 19:50:39 +08:00
|
|
|
|
KeyValuePair<int, float> kv = list[0];
|
2021-04-08 20:09:59 +08:00
|
|
|
|
message = new M2C_SyncUnitAttribute
|
|
|
|
|
{
|
|
|
|
|
UnitId = unit.Id,
|
|
|
|
|
NumericType = kv.Key,
|
|
|
|
|
Value = kv.Value
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
if (message != null)
|
|
|
|
|
unit.GetComponent<BrocastComponent>().BrocastInterval(message);
|
|
|
|
|
|
|
|
|
|
}
|
2021-04-11 19:50:39 +08:00
|
|
|
|
foreach (long item in needRemoveSet)
|
2021-04-08 20:09:59 +08:00
|
|
|
|
{
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|