PathfindingComponent.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using PF;
  2. namespace ET
  3. {
  4. public class PathfindingComponentAwakeSystem : AwakeSystem<PathfindingComponent>
  5. {
  6. public override void Awake(PathfindingComponent self)
  7. {
  8. self.PathReturnQueue = new PathReturnQueue(self);
  9. self.PathProcessor = new PathProcessor(self.PathReturnQueue, 1, false);
  10. // 读取寻路配置
  11. self.AStarConfig = new AStarConfig(); //MongoHelper.FromJson<AStarConfig>(File.ReadAllText("./pathfinding.config"));
  12. self.AStarConfig.pathProcessor = self.PathProcessor;
  13. // 读取地图数据
  14. self.AStarConfig.graphs = DeserializeHelper.Load("../Config/graph.bytes");
  15. }
  16. }
  17. public class PathfindingComponent: Entity
  18. {
  19. public PathReturnQueue PathReturnQueue;
  20. public PathProcessor PathProcessor;
  21. public AStarConfig AStarConfig;
  22. public bool Search(ABPathWrap path)
  23. {
  24. this.PathProcessor.queue.Push(path.Path);
  25. while (this.PathProcessor.CalculatePaths().MoveNext())
  26. {
  27. if (path.Path.CompleteState != PathCompleteState.NotCalculated)
  28. {
  29. break;
  30. }
  31. }
  32. if (path.Path.CompleteState != PathCompleteState.Complete)
  33. {
  34. return false;
  35. }
  36. PathModifyHelper.StartEndModify(path.Path);
  37. PathModifyHelper.FunnelModify(path.Path);
  38. return true;
  39. }
  40. }
  41. }