Actor_CreateUnitsHandler.cs 1002 B

123456789101112131415161718192021222324252627282930313233343536
  1. using Model;
  2. using UnityEngine;
  3. namespace Hotfix
  4. {
  5. [MessageHandler]
  6. public class Actor_CreateUnitsHandler : AMHandler<Actor_CreateUnits>
  7. {
  8. protected override void Run(Session session, Actor_CreateUnits message)
  9. {
  10. // 加载Unit资源
  11. ResourcesComponent resourcesComponent = Model.Game.Scene.GetComponent<ResourcesComponent>();
  12. resourcesComponent.LoadBundle($"Unit.unity3d");
  13. UnitComponent unitComponent = Model.Game.Scene.GetComponent<UnitComponent>();
  14. foreach (UnitInfo unitInfo in message.Units)
  15. {
  16. if (unitComponent.Get(unitInfo.UnitId) != null)
  17. {
  18. continue;
  19. }
  20. Unit unit = UnitFactory.Create(unitInfo.UnitId);
  21. unit.Position = new Vector3(unitInfo.X / 1000f, 0, unitInfo.Z / 1000f);
  22. unit.IntPos = new VInt3(unitInfo.X, 0, unitInfo.Z);
  23. if (PlayerComponent.Instance.MyPlayer.UnitId == unit.Id)
  24. {
  25. Model.Game.Scene.GetComponent<CameraComponent>().Unit = unit;
  26. }
  27. }
  28. Game.Scene.AddComponent<OperaComponent>();
  29. }
  30. }
  31. }