M2M_UnitTransferRequestHandler.cs 1.6 KB

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