UnitFactory.cs 883 B

1234567891011121314151617181920212223242526
  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. NumericComponent numericComponent = unit.AddComponent<NumericComponent>();
  12. for (int i = 0; i < unitInfo.Ks.Count; ++i)
  13. {
  14. numericComponent.Set((NumericType)unitInfo.Ks[i], unitInfo.Vs[i]);
  15. }
  16. UnitComponent unitComponent = domain.GetComponent<UnitComponent>();
  17. unitComponent.Add(unit);
  18. Game.EventSystem.Publish(new EventType.AfterUnitCreate() {Unit = unit});
  19. return unit;
  20. }
  21. }
  22. }