public ArrayList OnFindPathFromNoWayPointPaths() { GameObject startPos = GameObject.Find("StartPos"); GameObject endPos = GameObject.Find("EndPos"); Vector3 startPosVec = CUtility.RoundVector3(startPos.transform.position); Vector3 endPosVec = CUtility.RoundVector3(endPos.transform.position); CAStar AStar = new CAStar(); AStar.InitTiles(ref Tiles); int StartIdx = (int)(startPosVec.y * Size + startPosVec.x); int EndIdx = (int)(endPosVec.y * Size + endPosVec.x); ArrayList InitTiles = AStar.GetTiles(); PathIdxs = AStar.FindPaths(StartIdx, EndIdx, 0); ArrayList PathTiles = new ArrayList(); for (int i = 0; i < PathIdxs.Count; ++i) { Tile CurTile = InitTiles[(int)PathIdxs[i]] as Tile; PathTiles.Add(CurTile); } return(PathTiles); }
public void OnBuildWayPointPaths() { CTimeCheck.Start(0); OnMakeWayPoints(); CAStar AStar = new CAStar(); AStar.InitTiles(ref Tiles); for (int i = WayPoints.Count / 2; i < WayPoints.Count; ++i) { for (int j = WayPoints.Count / 2 - 1; 0 <= j; --j) { int StartPosIndex = (int)WayPoints[i]; int EndPosIndex = (int)WayPoints[j]; if (StartPosIndex == EndPosIndex) { continue; } int Key = StartPosIndex < EndPosIndex ? StartPosIndex * 10000 + EndPosIndex : EndPosIndex * 10000 + StartPosIndex; if (WayPointPaths.ContainsKey(Key)) { continue; } ArrayList FindedPaths = AStar.FindPaths(StartPosIndex, EndPosIndex, 0); ArrayList RemoveIndexs = new ArrayList(); for (int k = 0; k < FindedPaths.Count; ++k) { if (!WayPoints.Contains(FindedPaths[k])) { RemoveIndexs.Add(FindedPaths[k]); } } for (int a = 0; a < RemoveIndexs.Count; ++a) { FindedPaths.Remove(RemoveIndexs[a]); } if (3 < FindedPaths.Count) { int PathCount = FindedPaths.Count / 2; for (int count = 1; count < PathCount; ++count) { int NewStartIndex = (int)FindedPaths[count]; int NewEndIndex = (int)FindedPaths[FindedPaths.Count - 1 - count]; int NewKey = NewStartIndex < NewEndIndex ? NewStartIndex * 10000 + NewEndIndex : NewEndIndex * 10000 + NewStartIndex; if (WayPointPaths.ContainsKey(NewKey)) { continue; } ArrayList clone = (ArrayList)FindedPaths.Clone(); clone.RemoveAt(FindedPaths.Count - count); clone.RemoveAt(count - 1); //clone = clone.GetRange(count, FindedPaths.Count - 1 - count); WayPointPaths.Add(NewKey, clone); } } WayPointPaths.Add(Key, FindedPaths); } } for (int i = 0; i < WayPoints.Count; ++i) { for (int j = i + 1; j < WayPoints.Count; ++j) { int StartPosIndex = (int)WayPoints[i]; int EndPosIndex = (int)WayPoints[j]; if (StartPosIndex == EndPosIndex) { continue; } int Key = StartPosIndex < EndPosIndex ? StartPosIndex * 10000 + EndPosIndex : EndPosIndex * 10000 + StartPosIndex; if (WayPointPaths.ContainsKey(Key)) { continue; } ArrayList FindedPaths = AStar.FindPaths(StartPosIndex, EndPosIndex, 0); ArrayList RemoveIndexs = new ArrayList(); for (int k = 0; k < FindedPaths.Count; ++k) { if (!WayPoints.Contains(FindedPaths[k])) { RemoveIndexs.Add(FindedPaths[k]); } } for (int a = 0; a < RemoveIndexs.Count; ++a) { FindedPaths.Remove(RemoveIndexs[a]); } if (3 < FindedPaths.Count) { int PathCount = FindedPaths.Count / 2; for (int count = 1; count < PathCount; ++count) { int NewStartIndex = (int)FindedPaths[count]; int NewEndIndex = (int)FindedPaths[FindedPaths.Count - 1 - count]; int NewKey = NewStartIndex < NewEndIndex ? NewStartIndex * 10000 + NewEndIndex : NewEndIndex * 10000 + NewStartIndex; if (WayPointPaths.ContainsKey(NewKey)) { continue; } ArrayList clone = (ArrayList)FindedPaths.Clone(); clone.RemoveAt(FindedPaths.Count - count); clone.RemoveAt(count - 1); //clone = clone.GetRange(count, FindedPaths.Count - 1 - count); WayPointPaths.Add(NewKey, clone); } } WayPointPaths.Add(Key, FindedPaths); } } CTimeCheck.End(ELogType.MapGenerator, "BuildFastPaths"); }