UnitFactory.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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.Position = new Vector3(-10, 0, -10);
  17. NumericComponent numericComponent = unit.AddComponent<NumericComponent>();
  18. numericComponent.Set(NumericType.Speed, 6f); // 速度是6米每秒
  19. numericComponent.Set(NumericType.AOI, 15000); // 视野15米
  20. unitComponent.Add(unit);
  21. // 加入aoi
  22. unit.AddComponent<AOIEntity, int, Vector3>(9 * 1000, unit.Position);
  23. return unit;
  24. }
  25. default:
  26. throw new Exception($"not such unit type: {unitType}");
  27. }
  28. }
  29. }
  30. }