PathfindingComponent.cs 1.6 KB

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