Пример #1
0
        public NodePath FindPath(IPathfindNodeNetwork <AstarNode> nodeNetwork, IPathRequest pathRequest, out bool succes)
        {
            var pathfindingNetwork = nodeNetwork.GetCollisionLayerNetwork(pathRequest.CollisionCategory);
            var startNode          = NodePointer.Dereference(pathRequest.PathStart.Index, pathfindingNetwork);
            var endNode            = NodePointer.Dereference(pathRequest.PathEnd.Index, pathfindingNetwork);
            var path = FindPath(pathfindingNetwork, startNode, endNode, pathRequest.AgentSize, pathRequest.CollisionCategory);

            if (path == null)
            {
                succes = false;
                return(new NodePath(new[] { startNode.DefinitionNode }, nodeNetwork.DefinitionNodeNetwork.Transformer));
            }
            succes = true;
            switch (nodeNetwork.DefinitionNodeNetwork)
            {
            case IDefinitionNodeGrid definitionNodeGrid:
                var offset = GridClearanceHelper.GridNodeOffset(pathRequest.AgentSize, definitionNodeGrid.Transformer.Scale);
                return(new NodePath(path.ToArray(), definitionNodeGrid.Transformer));

            case IDefinitionNodeNetwork definitionNodeNetwork:
                return(new NodePath(path.ToArray(), definitionNodeNetwork.Transformer));

            default:
                throw new NotSupportedException($"{nodeNetwork.DefinitionNodeNetwork.GetType()} is not supported");
            }
        }
Пример #2
0
        public NodePath FindPath(IPathfindNodeNetwork <AstarNode> nodeNetwork, IPathRequest pathRequest, out bool succes)
        {
            if (pathRequest.PathStart == pathRequest.PathEnd)
            {
                succes = true;
                return(NodePath.GetEmptyPath(nodeNetwork, pathRequest.PathStart));
            }
            var pathfindingNetwork = nodeNetwork.GetCollisionLayerNetwork(pathRequest.CollisionCategory);

            if (!(pathfindingNetwork[pathRequest.PathStart].Clearance >= pathRequest.AgentSize) || !(pathfindingNetwork[pathRequest.PathEnd].Clearance >= pathRequest.AgentSize))
            {
                succes = false;
                return(NodePath.GetEmptyPath(nodeNetwork, pathRequest.PathStart));
            }

            StartFindPath(pathfindingNetwork, nodeNetwork.DefinitionNodeNetwork.NodeArray, pathRequest.PathStart);
            if (FindPath(pathfindingNetwork, nodeNetwork.DefinitionNodeNetwork.NodeArray, pathRequest.PathEnd, pathRequest.AgentSize, pathRequest.CollisionCategory))
            {
                var path = _pathRetracer.RetracePath(pathfindingNetwork, nodeNetwork.DefinitionNodeNetwork.NodeArray, pathRequest.PathStart, pathRequest.PathEnd);

                succes = true;
                return(new NodePath(nodeNetwork.DefinitionNodeNetwork.NodeArray, path, nodeNetwork.DefinitionNodeNetwork.Transformer));
            }

            succes = false;
            return(NodePath.GetEmptyPath(nodeNetwork, pathRequest.PathStart));
        }
Пример #3
0
        public WaypointPath FindPath(IPathfindNodeNetwork <DijkstraNode> nodeNetwork, IPathRequest pathRequest)
        {
            if (pathRequest.PathStart == pathRequest.PathEnd)
            {
                return(GetDefaultPath(nodeNetwork, pathRequest));
            }
            var pathfindingNetwork = nodeNetwork.GetCollisionLayerNetwork(pathRequest.CollisionCategory);

            if (!(pathfindingNetwork[pathRequest.PathStart].Clearance >= pathRequest.AgentSize) || !(pathfindingNetwork[pathRequest.PathEnd].Clearance >= pathRequest.AgentSize))
            {
                return(null);
            }

            Start(pathfindingNetwork, nodeNetwork.DefinitionNodeNetwork.NodeArray, pathRequest.PathStart, pathRequest.PathEnd, pathRequest.AgentSize, pathRequest.CollisionCategory);
            if (Step(-1))
            {
                var path = GetPath();
                return(new WaypointPath(nodeNetwork.DefinitionNodeNetwork.NodeArray, path, nodeNetwork.DefinitionNodeNetwork.Transformer));
            }

            return(null);
        }
Пример #4
0
 public WaypointPath GetDefaultPath(IPathfindNodeNetwork <DijkstraNode> nodeNetwork, IPathRequest pathRequest) => WaypointPath.GetEmptyPath(nodeNetwork, pathRequest.PathStart);
Пример #5
0
 public bool ValidatePath(IPathfindNodeNetwork <DijkstraNode> nodeNetwork, IPathRequest pathRequest, WaypointPath path) => true;
Пример #6
0
 public static WaypointPath GetEmptyPath(IPathfindNodeNetwork nodeNetwork, int pathStart)
 {
     return(new WaypointPath(nodeNetwork.DefinitionNodeNetwork.NodeArray, new[] { pathStart }, nodeNetwork.DefinitionNodeNetwork.Transformer));
 }