61 lines
1.9 KiB
C#
61 lines
1.9 KiB
C#
|
namespace ET
|
|||
|
{
|
|||
|
public class MapMonsterComponentDestroySystem:DestroySystem<MapMonsterComponent>
|
|||
|
{
|
|||
|
public override void Destroy(MapMonsterComponent self)
|
|||
|
{
|
|||
|
self.Clear();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static class MapMonsterComponentSystem
|
|||
|
{
|
|||
|
public static void Add(this MapMonsterComponent self,MapMonsterType type, Unit monster)
|
|||
|
{
|
|||
|
if(self.mapMonsterDic.TryGetValue((int) type,out var _monster))
|
|||
|
{
|
|||
|
Game.EventSystem.Publish(new ET.EventType.OnDisposeUnit
|
|||
|
{
|
|||
|
Actor_UnitId = self.Id,
|
|||
|
unitId = _monster.Id
|
|||
|
});
|
|||
|
_monster.Dispose();
|
|||
|
}
|
|||
|
|
|||
|
self.mapMonsterDic[(int) type] = monster;
|
|||
|
}
|
|||
|
public static void Remove(this MapMonsterComponent self,MapMonsterType type)
|
|||
|
{
|
|||
|
if(self.mapMonsterDic.TryGetValue((int) type,out var _monster))
|
|||
|
{
|
|||
|
Game.EventSystem.Publish(new ET.EventType.OnDisposeUnit
|
|||
|
{
|
|||
|
Actor_UnitId = self.Id,
|
|||
|
unitId = _monster.Id
|
|||
|
});
|
|||
|
_monster.Dispose();
|
|||
|
}
|
|||
|
self.mapMonsterDic.Remove((int) type);
|
|||
|
}
|
|||
|
public static bool TryGet(this MapMonsterComponent self,MapMonsterType type,out Unit monster)
|
|||
|
{
|
|||
|
return self.mapMonsterDic.TryGetValue((int) type, out monster);
|
|||
|
}
|
|||
|
|
|||
|
public static void Clear(this MapMonsterComponent self)
|
|||
|
{
|
|||
|
foreach (var keyValuePair in self.mapMonsterDic)
|
|||
|
{
|
|||
|
Game.EventSystem.Publish(new ET.EventType.OnDisposeUnit
|
|||
|
{
|
|||
|
Actor_UnitId = self.Id,
|
|||
|
unitId = keyValuePair.Value.Id
|
|||
|
});
|
|||
|
keyValuePair.Value.Dispose();
|
|||
|
}
|
|||
|
|
|||
|
self.mapMonsterDic.Clear();
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|