Actor_CreateUnitsHandler.cs 1001 B

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