public List <Point> GetPathToTarget(Directness _directness) { List <Point> Path = new List <Point>(); string currentKey = m_TargetIndex; Path.Insert(0, m_Database.Database[currentKey]); while (currentKey != m_SourceIndex && m_ShortestPath[currentKey] != null) { currentKey = m_ShortestPath[currentKey].Start.Index; Path.Insert(0, m_Database.Database[currentKey]); } int PossibleSmoothing = Mathf.CeilToInt(Path.Count / 2); int smoothingAmount = PossibleSmoothing; int CalculateAmount = 0; //smooth 25%, 50%, 75% accordingly if (_directness == Directness.Low) { CalculateAmount = PossibleSmoothing / 2; } else if (_directness == Directness.Mid) { CalculateAmount = PossibleSmoothing / 4 * 3; } else if (_directness == Directness.High) { CalculateAmount = PossibleSmoothing; } smoothingAmount = (CalculateAmount > 0 && CalculateAmount < 1) ? 1 : Mathf.CeilToInt(PossibleSmoothing); int smoothDone = 0; for (int i = 0; i < Path.Count; i++) { if (i + 2 < Path.Count && IsTwoPointsFreeToMove(Path[i], Path[i + 2])) { Path.Remove(Path[i + 1]); smoothDone++; if (smoothDone >= smoothingAmount) { break; } } } Path = RemoveExcessWallPoints(Path); return(Path); }
public List<Point> GetPathToTarget(Directness _directness) { List<Point> Path = new List<Point>(); string currentKey = m_TargetIndex; Path.Insert(0,m_Database.Database[currentKey]); while(currentKey != m_SourceIndex && m_ShortestPath[currentKey] != null) { currentKey = m_ShortestPath[currentKey].Start.Index; Path.Insert(0,m_Database.Database[currentKey]); } int PossibleSmoothing = Mathf.CeilToInt(Path.Count/2); int smoothingAmount = PossibleSmoothing; int CalculateAmount = 0; //smooth 25%, 50%, 75% accordingly if(_directness == Directness.Low) { CalculateAmount = PossibleSmoothing/2; } else if(_directness == Directness.Mid) { CalculateAmount = PossibleSmoothing/4 * 3; } else if(_directness == Directness.High) { CalculateAmount = PossibleSmoothing; } smoothingAmount = (CalculateAmount > 0 && CalculateAmount < 1) ? 1 : Mathf.CeilToInt(PossibleSmoothing); int smoothDone = 0; for(int i = 0; i < Path.Count; i++) { if(i + 2 < Path.Count && IsTwoPointsFreeToMove(Path[i],Path[i + 2])) { Path.Remove(Path[i + 1]); smoothDone++; if(smoothDone >= smoothingAmount) { break; } } } Path = RemoveExcessWallPoints(Path); return Path; }