public void initNodes() { nodesMap.Clear(); for (int i = 0; i < grid.NumberOfCells; i++) { nodesMap[i] = new CLAStarNode(i, grid.GetCellCenter(i)); } //设置每个节点的左右上下一周的节点 for (int i = 0; i < grid.NumberOfCells; i++) { CLAStarNode left = null; nodesMap.TryGetValue(grid.LeftIndex(i), out left); CLAStarNode right = null; nodesMap.TryGetValue(grid.RightIndex(i), out right); CLAStarNode up = null; nodesMap.TryGetValue(grid.UpIndex(i), out up); CLAStarNode down = null; nodesMap.TryGetValue(grid.DownIndex(i), out down); CLAStarNode leftUp = null; nodesMap.TryGetValue(grid.LeftUpIndex(i), out leftUp); CLAStarNode leftDown = null; nodesMap.TryGetValue(grid.LeftDownIndex(i), out leftDown); CLAStarNode rightUp = null; nodesMap.TryGetValue(grid.RightUpIndex(i), out rightUp); CLAStarNode rightDown = null; nodesMap.TryGetValue(grid.RightDownIndex(i), out rightDown); if (nodesMap[i] != null) { nodesMap[i].init(left, right, up, down, leftUp, leftDown, rightUp, rightDown); } } }