UnitFactory.cs 972 B

123456789101112131415161718192021222324252627282930
  1. using UnityEngine;
  2. namespace ET
  3. {
  4. public static class UnitFactory
  5. {
  6. public static Unit Create(Entity domain, UnitInfo unitInfo)
  7. {
  8. UnitComponent unitComponent = domain.GetComponent<UnitComponent>();
  9. Unit unit = unitComponent.AddChildWithId<Unit, int>(unitInfo.UnitId, unitInfo.ConfigId);
  10. unitComponent.Add(unit);
  11. unit.Position = new Vector3(unitInfo.X, unitInfo.Y, unitInfo.Z);
  12. unit.AddComponent<MoveComponent>();
  13. NumericComponent numericComponent = unit.AddComponent<NumericComponent>();
  14. for (int i = 0; i < unitInfo.Ks.Count; ++i)
  15. {
  16. numericComponent.Set((NumericType)unitInfo.Ks[i], unitInfo.Vs[i]);
  17. }
  18. unit.AddComponent<ObjectWait>();
  19. unit.AddComponent<XunLuoPathComponent>();
  20. Game.EventSystem.Publish(new EventType.AfterUnitCreate() {Unit = unit});
  21. return unit;
  22. }
  23. }
  24. }