zxl
/
CTT
forked from Cal/CTT
1
0
Fork 0
CTT/Unity/Assets/Hotfix/Logic/Model/Game/Entity/User/PlayerComponent.cs

90 lines
1.4 KiB
C#

using ET;
using System.Collections.Generic;
using System.Linq;
namespace ET
{
public class PlayerComponentAwakeSystem : AwakeSystem<PlayerComponent>
{
public override void Awake(PlayerComponent self)
{
self.Awake();
}
}
public class PlayerComponent : Entity
{
public static PlayerComponent Instance { get; private set; }
private ClientUser myPlayer;
public ClientUser MyPlayer
{
get
{
return this.myPlayer;
}
set
{
this.myPlayer = value;
this.myPlayer.Parent = this;
}
}
private readonly Dictionary<long, ClientUser> idPlayers = new Dictionary<long, ClientUser>();
public void Awake()
{
Instance = this;
}
public void Add(ClientUser player)
{
this.idPlayers.Add(player.Id, player);
player.Parent = this;
}
public ClientUser Get(long id)
{
ClientUser player;
this.idPlayers.TryGetValue(id, out player);
return player;
}
public void Remove(long id)
{
this.idPlayers.Remove(id);
}
public int Count
{
get
{
return this.idPlayers.Count;
}
}
public ClientUser[] GetAll()
{
return this.idPlayers.Values.ToArray();
}
public override void Dispose()
{
if (this.IsDisposed)
{
return;
}
base.Dispose();
foreach (ClientUser player in this.idPlayers.Values)
{
player.Dispose();
}
Instance = null;
}
}
}