PlayerComponent.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 : Component
  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. public int A = 1;
  30. public AppType AppType;
  31. private readonly Dictionary<long, Player> idPlayers = new Dictionary<long, Player>();
  32. public void Awake()
  33. {
  34. Instance = this;
  35. }
  36. public void Add(Player player)
  37. {
  38. this.idPlayers.Add(player.Id, player);
  39. player.Parent = this;
  40. }
  41. public Player Get(long id)
  42. {
  43. Player player;
  44. this.idPlayers.TryGetValue(id, out player);
  45. return player;
  46. }
  47. public void Remove(long id)
  48. {
  49. this.idPlayers.Remove(id);
  50. }
  51. public int Count
  52. {
  53. get
  54. {
  55. return this.idPlayers.Count;
  56. }
  57. }
  58. public Player[] GetAll()
  59. {
  60. return this.idPlayers.Values.ToArray();
  61. }
  62. public override void Dispose()
  63. {
  64. if (this.IsDisposed)
  65. {
  66. return;
  67. }
  68. base.Dispose();
  69. foreach (Player player in this.idPlayers.Values)
  70. {
  71. player.Dispose();
  72. }
  73. Instance = null;
  74. }
  75. }
  76. }