Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity3D[中间版]如何将列表转换为阵列?(寻路)_C#_Unity3d_Multidimensional Array_Path Finding - Fatal编程技术网

C# Unity3D[中间版]如何将列表转换为阵列?(寻路)

C# Unity3D[中间版]如何将列表转换为阵列?(寻路),c#,unity3d,multidimensional-array,path-finding,C#,Unity3d,Multidimensional Array,Path Finding,[编辑]我的问题不是通过转换列表来解决的。toArray,但在@KBaker给出的答案中找不到解决方法。祝你好运 ------------------------------------------------------------------ 我一直在这里和Unity网站上寻找主题和解决方案,我没有找到与我的问题类似的内容,两周以来我一直在努力,所以请不要免费为这个主题打分。提前谢谢你 如下图所示,我的装置只有正交运动: 来自我的寻路脚本中的SymplifyPath: IEnumerator

[编辑]我的问题不是通过转换列表来解决的。toArray,但在@KBaker给出的答案中找不到解决方法。祝你好运

------------------------------------------------------------------

我一直在这里和Unity网站上寻找主题和解决方案,我没有找到与我的问题类似的内容,两周以来我一直在努力,所以请不要免费为这个主题打分。提前谢谢你

如下图所示,我的装置只有正交运动:

来自我的寻路脚本中的SymplifyPath:

IEnumerator FindPath(Vector3 startPos, Vector3 targetPos){
    Vector3[] finalPath = new Vector3[0];
    bool pathSuccess = false;
    [...]//body
    yield return null;
    if (pathSuccess){
        finalPath = RetracePath(startNode, targetNode);
    }
    pathQueue.FinishedProcessingPath(finalPath, pathSuccess);
}

Vector3[] RetracePath(Nodes startNode, Nodes endNode){
    List<Node> path = new List<Node>();
    Node currentNode = endNode;
    while (currentNode != startNode){
        path.Add(currentNode);
        currentNode = currentNode.parent;
    }
    Vector3[] finalPath = SymplifyPath(path);
    Array.Reverse(finalPath);
    return finalPath;
}

Vector3[] SymplifyPath(List<Nodes> path){
    List<Vector3> finalPath = new List<Vector3>();
    Vector2 directionOld = Vector2.zero;
    for(int i = 1; i < path.Count; i++){
        Vector2 directionNew = new Vector2(path[i - 1].gridX - path[i].gridX, path[i - 1].gridZ - path[i].gridZ);{
            finalPath.Add(path[i - 1].worldPosition);
        }
        directionOld = directionNew;
    }
    return finalPath.ToArray();
}

有什么想法吗?

您可以签出或将列表转换为数组。

我现在就试试,希望能奏效,再次感谢您的回答;
Vector3[] SymplifyPath(List<Nodes> path){
    List<Vector3> finalPath = new List<Vector3>();
    Vector2 nodesListPath = Vector2.zero;
    for(int i = 1; i < path.Count; i++)
        {
            finalPath(path[i].worldPosition)
        }
        finalPath = nodesListPath;
    }
    return finalPath.ToArray();
}