UnitComponent.cs 666 字节
Newer Older
1 2
using System.Collections.Generic;

T
tanghai 已提交
3
namespace Hotfix
4
{
5
	[EntityEvent(EntityEventId.UnitComponent)]
T
tanghai 已提交
6
	public class UnitComponent: HotfixComponent
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
	{
		private readonly Dictionary<long, Unit> idUnits = new Dictionary<long, Unit>();

		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)
		{
			this.idUnits.Remove(id);
		}

		public override void Dispose()
		{
			if (this.Id == 0)
			{
				return;
			}
			base.Dispose();

			foreach (Unit unit in this.idUnits.Values)
			{
				unit.Dispose();
			}
		}
	}
}