using System; using System.Collections.Generic; namespace ET { public class GateUserComponent:Entity { public static GateUserComponent Instance { get; private set; } public readonly Dictionary idPlayers = new Dictionary(); public void Awake() { Instance = this; } public void Add(User user) { this.idPlayers.Add(user.Id, user); } /// /// 从缓存获取 /// /// /// public User Get(long id) { this.idPlayers.TryGetValue(id, out User user); return user; } public bool Remove(long id) { return this.idPlayers.Remove(id); } public int Count { get { return this.idPlayers.Count; } } public IEnumerable GetAll() { return this.idPlayers.Values; } public override void Dispose() { if (this.IsDisposed) { return; } base.Dispose(); foreach (User player in this.idPlayers.Values) { player.Dispose(); } Instance = null; } } }