SessionPlayerComponentSystem.cs 925 B

12345678910111213141516171819202122232425262728293031323334353637
  1. 
  2. namespace ET.Server
  3. {
  4. [FriendOf(typeof (SessionPlayerComponent))]
  5. public static class SessionPlayerComponentSystem
  6. {
  7. public class SessionPlayerComponentDestroySystem: DestroySystem<SessionPlayerComponent>
  8. {
  9. protected override void Destroy(SessionPlayerComponent self)
  10. {
  11. Player player = self.GetMyPlayer();
  12. if (player == null)
  13. {
  14. return;
  15. }
  16. Log.Info($"玩家断线了, playerId={self.PlayerId}, name={player.Name}");
  17. // 发送断线消息
  18. ActorLocationSenderComponent.Instance?.Send(self.PlayerId, new G2M_SessionDisconnect());
  19. // 销毁玩家实体
  20. player.Dispose();
  21. }
  22. }
  23. /// <summary>
  24. /// 获取玩家实体
  25. /// </summary>
  26. /// <param name="self"></param>
  27. /// <returns></returns>
  28. public static Player GetMyPlayer(this SessionPlayerComponent self)
  29. {
  30. return self.DomainScene().GetComponent<GamePlayerComponent>().Get(self.PlayerId);
  31. }
  32. }
  33. }