81 lines
2.8 KiB
C#
81 lines
2.8 KiB
C#
|
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)
|
|||
|
{
|
|||
|
foreach (var item in self.dic.GetDictionary())
|
|||
|
{
|
|||
|
needRemoveSet.Add(item.Key);
|
|||
|
var 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 (var kv in item.Value)
|
|||
|
{
|
|||
|
Log.Error($"k = {(NumericType)kv.Key}, v ={kv.Value}");
|
|||
|
}
|
|||
|
}
|
|||
|
continue;
|
|||
|
}
|
|||
|
IActorMessage message = null;
|
|||
|
if (list.Count > 1)
|
|||
|
{
|
|||
|
var newMessage = new M2C_SyncUnitAttributeList
|
|||
|
{
|
|||
|
UnitId = unit.Id
|
|||
|
};
|
|||
|
foreach (var kv in list)
|
|||
|
{
|
|||
|
newMessage.NumericMap.Add(new AttributeMap
|
|||
|
{
|
|||
|
Key = kv.Key,
|
|||
|
Value = kv.Value
|
|||
|
});
|
|||
|
}
|
|||
|
message = newMessage;
|
|||
|
}
|
|||
|
else if (list.Count == 1)
|
|||
|
{
|
|||
|
var kv = list[0];
|
|||
|
message = new M2C_SyncUnitAttribute
|
|||
|
{
|
|||
|
UnitId = unit.Id,
|
|||
|
NumericType = kv.Key,
|
|||
|
Value = kv.Value
|
|||
|
};
|
|||
|
}
|
|||
|
if (message != null)
|
|||
|
unit.GetComponent<BrocastComponent>().BrocastInterval(message);
|
|||
|
|
|||
|
}
|
|||
|
foreach (var 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));
|
|||
|
}
|
|||
|
}
|
|||
|
}
|