public virtual bool CanAddAdjacentToReachable(PathFinding search, CellData adjacent) { // 如果已经在关闭集 if (search.IsCellInExplored(adjacent)) { return(false); } // 已经加入过开放集 if (search.IsCellInReachable(adjacent)) { return(false); } // 计算消耗 = 当前 cell 的消耗 + 邻居 cell 的消耗 float g = search.currentCell.G + CalcGPerCell(search, adjacent); // 不在范围内 if (g < 0f || g > search.range.y) { return(false); } adjacent.G = g; return(true); }
public override bool CanAddAdjacentToReachable(PathFinding search, CellData adjacent) { // 是否可移动 if (!adjacent.CanMove) { return(false); } // 如果已经在关闭集 if (search.IsCellInExplored(adjacent)) { return(false); } // 计算消耗 = 当前 cell 的消耗 + 邻居 cell 的消耗 float g = search.currentCell.G + CalcGPerCell(search, adjacent); // 已经加入过开放集 if (search.IsCellInReachable(adjacent)) { // 如果新消耗更低 if (g < adjacent.G) { adjacent.G = g; adjacent.Previous = search.currentCell; } return(false); } adjacent.G = g; adjacent.H = CalcH(search, adjacent); adjacent.Previous = search.currentCell; return(true); }