G2M_CreateUnitHandler.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using UnityEngine;
  3. namespace ET
  4. {
  5. [ActorMessageHandler]
  6. public class G2M_CreateUnitHandler : AMActorRpcHandler<Scene, G2M_CreateUnit, M2G_CreateUnit>
  7. {
  8. protected override async ETTask Run(Scene scene, G2M_CreateUnit request, M2G_CreateUnit response, Action reply)
  9. {
  10. UnitComponent unitComponent = scene.GetComponent<UnitComponent>();
  11. Unit unit = unitComponent.AddChildWithId<Unit, int>(IdGenerater.Instance.GenerateId(), 1001);
  12. unit.AddComponent<MoveComponent>();
  13. unit.AddComponent<PathfindingComponent, string>("solo");
  14. unit.Position = new Vector3(-10, 0, -10);
  15. NumericComponent numericComponent = unit.AddComponent<NumericComponent>();
  16. numericComponent.Set(NumericType.Speed, 6f); // 速度是6米每秒
  17. numericComponent.Set(NumericType.AOI, 15000); // 视野15米
  18. unit.AddComponent<MailBoxComponent>();
  19. await unit.AddLocation();
  20. unit.AddComponent<UnitGateComponent, long>(request.GateSessionId);
  21. unitComponent.Add(unit);
  22. // 加入aoi
  23. unit.AddComponent<AOIEntity, int, Vector3>(9 * 1000, unit.Position);
  24. M2C_CreateUnits m2CCreateUnits = new M2C_CreateUnits();
  25. m2CCreateUnits.Units.Add(UnitHelper.CreateUnitInfo(unit));
  26. MessageHelper.SendToClient(unit, m2CCreateUnits);
  27. response.MyId = unit.Id;
  28. reply();
  29. }
  30. }
  31. }