Assets/Scripts/Heros/PartySpawner.cs
/// <summary>
/// Get shortest way from point A to B following nodes
/// </summary>
/// <param name="path">Current path</param>
/// <param name="currNode">Next node</param>
Get shortest way from point A to B following nodes
Get shortest way from point A to B following nodes
private List<Node> GetShortestWay(List<Node> path, Node currNode)
    {
        if (path == null) 
            return null;
        List<Node> currPath = new List<Node>(path); 
        currPath.Add(currNode); 
        if (currNode == finalNode) 
            return currPath;
        List<Node> addPath = null; 
        foreach (var l in currNode.nodes) 
        {
            if (!currPath.Contains(l)) 
            {
                var newPath = GetShortestWay(currPath, l); 
                if (newPath != null && (addPath == null || newPath.Count < addPath.Count)) 
                    addPath = newPath;
            }
        }
        return addPath;
    }
private List < Node > GetShortestWay ( List < Node > path , Node currNode ) { if ( path == null ) return null ; List < Node > currPath = new List < Node > ( path ) ; currPath . Add ( currNode ) ; if ( currNode == finalNode ) return currPath ; List < Node > addPath = null ; foreach ( var l in currNode . nodes ) { if ( ! currPath . Contains ( l ) ) { var newPath = GetShortestWay ( currPath , l ) ; if ( newPath != null && ( addPath == null || newPath . Count < addPath . Count ) ) addPath = newPath ; } } return addPath ; }
Get shortest way from point A to B following nodes
Get shortest way from point A to B following nodes
// If path is null we ignore it // Create a new path // Add current node to path // If we reach first node then it's okay // Final path // We go through each nodes // If current path contains the node, that means we are looping // Get path // If it's the shortest path
path
List<Node>
None
currNode
Node
None