70 lines
2.0 KiB
C#
70 lines
2.0 KiB
C#
using ET.EventType;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace ET
|
|
{
|
|
public class MapUnitComponentAeakeSystem : AwakeSystem<MapUnitComponent>
|
|
{
|
|
public override void Awake(MapUnitComponent self)
|
|
{
|
|
self.Awake();
|
|
}
|
|
}
|
|
public class MapUnitComponentDestroySystem : DestroySystem<MapUnitComponent>
|
|
{
|
|
public override void Destroy(MapUnitComponent self)
|
|
{
|
|
self.onLineIds.Clear();
|
|
}
|
|
}
|
|
public static class MapUnitComponentSystem
|
|
{
|
|
public static void Awake(this MapUnitComponent self)
|
|
{
|
|
MapUnitComponent.Instance = self;
|
|
}
|
|
public static void Add(this MapUnitComponent self, Unit unit)
|
|
{
|
|
self.idUnits[unit.Id] = unit;
|
|
}
|
|
|
|
public static Unit Get(this MapUnitComponent self, long id)
|
|
{
|
|
self.idUnits.TryGetValue(id, out Unit unit);
|
|
return unit;
|
|
}
|
|
public static IEnumerable<Unit> GetAll(this MapUnitComponent self)
|
|
{
|
|
return self.idUnits.Values;
|
|
}
|
|
public static void Remove(this MapUnitComponent self, long id)
|
|
{
|
|
self.idUnits.Remove(id);
|
|
}
|
|
public static void OnLine(this MapUnitComponent self, long id)
|
|
{
|
|
self.onLineIds.Add(id);
|
|
}
|
|
public static bool IsOnLine(this MapUnitComponent self, long id) =>self. onLineIds.Contains(id);
|
|
public static void OffLine(this MapUnitComponent self, long id)
|
|
{
|
|
self.onLineIds.Remove(id);
|
|
}
|
|
public static async ETTask<Unit> Query(this MapUnitComponent self,long unitId)
|
|
{
|
|
Unit unit = self.Get(unitId);
|
|
if (unit != null)
|
|
{
|
|
return unit;
|
|
}
|
|
return await UnitHelper.Query(self.Domain, unitId);
|
|
}
|
|
public static async ETVoid Save(this MapUnitComponent self, Unit unit)
|
|
{
|
|
await DBComponent.Instance.Save(unit);
|
|
}
|
|
}
|
|
}
|