M2M_UnitTransferRequestHandler.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using Unity.Mathematics;
  3. namespace ET.Server
  4. {
  5. [ActorMessageHandler(SceneType.Map)]
  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. reply();
  11. UnitComponent unitComponent = scene.GetComponent<UnitComponent>();
  12. Unit unit = MongoHelper.Deserialize<Unit>(request.Unit);
  13. unitComponent.AddChild(unit);
  14. unitComponent.Add(unit);
  15. foreach (byte[] bytes in request.Entitys)
  16. {
  17. Entity entity = MongoHelper.Deserialize<Entity>(bytes);
  18. unit.AddComponent(entity);
  19. }
  20. unit.AddComponent<MoveComponent>();
  21. unit.AddComponent<PathfindingComponent, string>(scene.Name);
  22. unit.Position = new float3(-10, 0, -10);
  23. unit.AddComponent<MailBoxComponent>();
  24. // 通知客户端开始切场景
  25. M2C_StartSceneChange m2CStartSceneChange = new M2C_StartSceneChange() {SceneInstanceId = scene.InstanceId, SceneName = scene.Name};
  26. MessageHelper.SendToClient(unit, m2CStartSceneChange);
  27. // 通知客户端创建My Unit
  28. M2C_CreateMyUnit m2CCreateUnits = new M2C_CreateMyUnit();
  29. m2CCreateUnits.Unit = UnitHelper.CreateUnitInfo(unit);
  30. MessageHelper.SendToClient(unit, m2CCreateUnits);
  31. // 加入aoi
  32. unit.AddComponent<AOIEntity, int, float3>(9 * 1000, unit.Position);
  33. // 解锁location,可以接收发给Unit的消息
  34. await LocationProxyComponent.Instance.UnLock(unit.Id, request.OldInstanceId, unit.InstanceId);
  35. }
  36. }
  37. }