Actor_CreateUnitsHandler.cs 811 B

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