UnitFactory.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. using System;
  2. using UnityEngine;
  3. namespace ET
  4. {
  5. public static class UnitFactory
  6. {
  7. public static Unit Create(Scene scene, long id, UnitType unitType)
  8. {
  9. UnitComponent unitComponent = scene.GetComponent<UnitComponent>();
  10. switch (unitType)
  11. {
  12. case UnitType.Player:
  13. {
  14. Unit unit = unitComponent.AddChildWithId<Unit, int>(id, 1001);
  15. unit.AddComponent<MoveComponent>();
  16. unit.AddComponent<PathfindingComponent, string>("solo");
  17. unit.Position = new Vector3(-10, 0, -10);
  18. NumericComponent numericComponent = unit.AddComponent<NumericComponent>();
  19. numericComponent.Set(NumericType.Speed, 6f); // 速度是6米每秒
  20. numericComponent.Set(NumericType.AOI, 15000); // 视野15米
  21. unitComponent.Add(unit);
  22. // 加入aoi
  23. unit.AddComponent<AOIEntity, int, Vector3>(9 * 1000, unit.Position);
  24. return unit;
  25. }
  26. default:
  27. throw new Exception($"not such unit type: {unitType}");
  28. }
  29. }
  30. }
  31. }