G2M_CreateUnitHandler.cs 757 B

123456789101112131415161718192021222324252627
  1. using System;
  2. using Model;
  3. namespace Hotfix
  4. {
  5. [MessageHandler(AppType.Map)]
  6. public class G2M_CreateUnitHandler : AMRpcHandler<G2M_CreateUnit, M2G_CreateUnit>
  7. {
  8. protected override void Run(Session session, G2M_CreateUnit message, Action<M2G_CreateUnit> reply)
  9. {
  10. M2G_CreateUnit response = new M2G_CreateUnit();
  11. try
  12. {
  13. Unit unit = ObjectFactory.Create<Unit, UnitType>(UnitType.Hero);
  14. unit.AddComponent<ActorComponent, IEntityActorHandler>(new CommonEntityActorHandler());
  15. unit.AddComponent<UnitGateComponent, long>(message.GateSessionId);
  16. Game.Scene.GetComponent<UnitComponent>().Add(unit);
  17. response.UnitId = unit.Id;
  18. reply(response);
  19. }
  20. catch (Exception e)
  21. {
  22. ReplyError(response, e, reply);
  23. }
  24. }
  25. }
  26. }