| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System.Collections.Generic;
- using System.Linq;
- namespace ETModel
- {
- [ObjectSystem]
- public class UnitComponentSystem : AwakeSystem<UnitComponent>
- {
- public override void Awake(UnitComponent self)
- {
- self.Awake();
- }
- }
-
- public class UnitComponent: Component
- {
- public static UnitComponent Instance { get; private set; }
- public Unit MyUnit;
-
- private readonly Dictionary<long, Unit> idUnits = new Dictionary<long, Unit>();
- public void Awake()
- {
- Instance = this;
- }
- public override void Dispose()
- {
- if (this.IsDisposed)
- {
- return;
- }
- base.Dispose();
- foreach (Unit unit in this.idUnits.Values)
- {
- unit.Dispose();
- }
- this.idUnits.Clear();
- Instance = null;
- }
- public void Add(Unit unit)
- {
- this.idUnits.Add(unit.Id, unit);
- }
- public Unit Get(long id)
- {
- Unit unit;
- this.idUnits.TryGetValue(id, out unit);
- return unit;
- }
- public void Remove(long id)
- {
- Unit unit;
- this.idUnits.TryGetValue(id, out unit);
- this.idUnits.Remove(id);
- unit?.Dispose();
- }
- public void RemoveNoDispose(long id)
- {
- this.idUnits.Remove(id);
- }
- public int Count
- {
- get
- {
- return this.idUnits.Count;
- }
- }
- public Unit[] GetAll()
- {
- return this.idUnits.Values.ToArray();
- }
- }
- }
|