PlayerComponent.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. namespace ETModel
  4. {
  5. [ObjectSystem]
  6. public class PlayerComponentAwakeSystem : AwakeSystem<PlayerComponent>
  7. {
  8. public override void Awake(PlayerComponent self)
  9. {
  10. self.Awake();
  11. }
  12. }
  13. public class PlayerComponent : Entity
  14. {
  15. public static PlayerComponent Instance { get; private set; }
  16. private Player myPlayer;
  17. public Player MyPlayer
  18. {
  19. get
  20. {
  21. return this.myPlayer;
  22. }
  23. set
  24. {
  25. this.myPlayer = value;
  26. this.myPlayer.Parent = this;
  27. }
  28. }
  29. private readonly Dictionary<long, Player> idPlayers = new Dictionary<long, Player>();
  30. public void Awake()
  31. {
  32. Instance = this;
  33. }
  34. public void Add(Player player)
  35. {
  36. this.idPlayers.Add(player.Id, player);
  37. player.Parent = this;
  38. }
  39. public Player Get(long id)
  40. {
  41. Player player;
  42. this.idPlayers.TryGetValue(id, out player);
  43. return player;
  44. }
  45. public void Remove(long id)
  46. {
  47. this.idPlayers.Remove(id);
  48. }
  49. public int Count
  50. {
  51. get
  52. {
  53. return this.idPlayers.Count;
  54. }
  55. }
  56. public Player[] GetAll()
  57. {
  58. return this.idPlayers.Values.ToArray();
  59. }
  60. public override void Dispose()
  61. {
  62. if (this.IsDisposed)
  63. {
  64. return;
  65. }
  66. base.Dispose();
  67. foreach (Player player in this.idPlayers.Values)
  68. {
  69. player.Dispose();
  70. }
  71. Instance = null;
  72. }
  73. }
  74. }