| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System.Collections.Generic;
- using System.Linq;
- namespace ETModel
- {
- [ObjectSystem]
- public class PlayerComponentSystem : AwakeSystem<PlayerComponent>
- {
- public override void Awake(PlayerComponent self)
- {
- self.Awake();
- }
- }
-
- public class PlayerComponent : Component
- {
- public static PlayerComponent Instance { get; private set; }
- public Player MyPlayer;
-
- private readonly Dictionary<long, Player> idPlayers = new Dictionary<long, Player>();
- public void Awake()
- {
- Instance = this;
- }
-
- public void Add(Player player)
- {
- this.idPlayers.Add(player.Id, player);
- }
- public Player Get(long id)
- {
- this.idPlayers.TryGetValue(id, out Player gamer);
- return gamer;
- }
- public void Remove(long id)
- {
- this.idPlayers.Remove(id);
- }
- public int Count
- {
- get
- {
- return this.idPlayers.Count;
- }
- }
- public Player[] GetAll()
- {
- return this.idPlayers.Values.ToArray();
- }
- public override void Dispose()
- {
- if (this.IsDisposed)
- {
- return;
- }
-
- base.Dispose();
- foreach (Player player in this.idPlayers.Values)
- {
- player.Dispose();
- }
- Instance = null;
- }
- }
- }
|