zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Server/Model/Game/Entity/GateUserComponent.cs

68 lines
1.4 KiB
C#

using System;
using System.Collections.Generic;
namespace ET
{
public class GateUserComponent:Entity
{
public static GateUserComponent Instance { get; private set; }
public readonly Dictionary<long, User> idPlayers = new Dictionary<long, User>();
public void Awake()
{
Instance = this;
}
public void Add(User user)
{
this.idPlayers.Add(user.Id, user);
}
/// <summary>
/// 从缓存获取
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
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<User> 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;
}
}
}