UnitFactory.cs 741 B

1234567891011121314151617181920212223
  1. using UnityEngine;
  2. namespace ET
  3. {
  4. public static class UnitFactory
  5. {
  6. public static Unit Create(Entity domain, UnitInfo unitInfo)
  7. {
  8. Unit unit = EntityFactory.CreateWithId<Unit, int>(domain, unitInfo.UnitId, unitInfo.ConfigId);
  9. unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);
  10. unit.AddComponent<MoveComponent>();
  11. unit.AddComponent<TurnComponent>();
  12. unit.AddComponent<UnitPathComponent>();
  13. UnitComponent unitComponent = domain.GetComponent<UnitComponent>();
  14. unitComponent.Add(unit);
  15. Game.EventSystem.Publish(new EventType.AfterUnitCreate() {Unit = unit});
  16. return unit;
  17. }
  18. }
  19. }