PathfindingManager.GetPath C# (CSharp) Method

GetPath() public method

public GetPath ( PathNode, start, PathNode, end ) : List
start PathNode,
end PathNode,
return List
    public List<PathNode> GetPath(PathNode start, PathNode end)
    {
        WaypointManager wg = GameObject.Find ("WaypointManager").GetComponent<WaypointManager>();
        var sources = wg.pathNodes;

        if(start == null || end == null)
        {
            if (sources != null && sources.Count >= 2)
            {
                start 	= sources[PathNode.startNode]/*.GetComponent<PathNode>()*/;//.GetInnerObject();
                end 	= sources[PathNode.endNode]/*.GetComponent<PathNode>()*/;//.GetInnerObject();
            }

            if (start == null || end == null)
            {
                Debug.LogWarning("Need 'start' and or 'end' defined!");
                enabled = false;
                return null;
            }
        }

        startIndex = Closest(sources, start.position);

        endIndex = Closest(sources, end.position);

        return AStarHelper.Calculate(sources[startIndex]/*.GetComponent<PathNode>()*/, sources[endIndex]/*.GetComponent<PathNode>()*/);
    }

Usage Example

コード例 #1
0
        public void GetPath_ManagerNotStarted_ThrowsException()
        {
            using var gate = new AutoResetEvent(false);
            var callback = new PathfindingCallback(gate);
            IPathfindingManager manager = new PathfindingManager();

            try {
                Assert.That(() => {
                    manager.GetPath(_map, ref _map.GetCell(0, 0), ref _map.GetCell(_map.Columns - 1, _map.Rows - 1), Locomotion.Walk, callback, 0);
                }, Throws.InvalidOperationException);
            } finally {
                manager.Stop();
            }
        }
All Usage Examples Of PathfindingManager::GetPath