M2M_UnitTransferRequestHandler.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using System;
  2. using UnityEngine;
  3. namespace ET.Server
  4. {
  5. [ActorMessageHandler]
  6. public class M2M_UnitTransferRequestHandler : AMActorRpcHandler<Scene, M2M_UnitTransferRequest, M2M_UnitTransferResponse>
  7. {
  8. protected override async ETTask Run(Scene scene, M2M_UnitTransferRequest request, M2M_UnitTransferResponse response, Action reply)
  9. {
  10. await ETTask.CompletedTask;
  11. UnitComponent unitComponent = scene.GetComponent<UnitComponent>();
  12. Unit unit = request.Unit;
  13. unitComponent.AddChild(unit);
  14. unitComponent.Add(unit);
  15. foreach (Entity entity in request.Entitys)
  16. {
  17. unit.AddComponent(entity);
  18. }
  19. unit.AddComponent<MoveComponent>();
  20. unit.AddComponent<PathfindingComponent, string>(scene.Name);
  21. unit.Position = new Vector3(-10, 0, -10);
  22. unit.AddComponent<MailBoxComponent>();
  23. // 通知客户端创建My Unit
  24. M2C_CreateMyUnit m2CCreateUnits = new M2C_CreateMyUnit();
  25. m2CCreateUnits.Unit = Server.UnitHelper.CreateUnitInfo(unit);
  26. MessageHelper.SendToClient(unit, m2CCreateUnits);
  27. // 加入aoi
  28. unit.AddComponent<AOIEntity, int, Vector3>(9 * 1000, unit.Position);
  29. response.NewInstanceId = unit.InstanceId;
  30. reply();
  31. }
  32. }
  33. }