G2M_CreateUnitHandler.cs 686 B

1234567891011121314151617181920212223242526
  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. Game.Scene.GetComponent<UnitComponent>().Add(unit);
  16. response.UnitId = unit.Id;
  17. reply(response);
  18. }
  19. catch (Exception e)
  20. {
  21. ReplyError(response, e, reply);
  22. }
  23. }
  24. }
  25. }