private IEnumerator PathFindingAnimForSimple(List <SimpleAStar.Point> path, float time, Color pathColor) { for (int i = 0; i < path.Count; i++) { yield return(new WaitForSeconds(time)); SimpleAStar.Point point = path[i]; Transform nodeTrans = mNodeTransArray[point.X, point.Y]; SetColor(nodeTrans, pathColor); } }
private void SimpleAStarPathFinding() { SimpleAStar.Point start = new SimpleAStar.Point(0, 0); SimpleAStar.Point end = new SimpleAStar.Point(MapWidth - 1, MapHeight - 1); List <float> resTimeListIn = new List <float>(); List <float> resTimeListOut = new List <float>(); List <int> seedList = mRandomMapCreator.GetValidSeedList(MapNums, Probability, RandomSeed, MaxTimes); for (int p = 0; p < seedList.Count; p++) { mRandomMapCreator.Create(seedList[p], Probability); List <SimpleAStar.Point> obstacleList = new List <SimpleAStar.Point>(); for (int i = 0; i < MapWidth; i++) { for (int j = 0; j < MapHeight; j++) { if (mMapMgr.Map[i, j].IsConnected == false) { obstacleList.Add(new SimpleAStar.Point(i, j)); } } } SimpleAStar.AStarS aStars = new SimpleAStar.AStarS(MapWidth, MapHeight, obstacleList); for (int j = 0; j < Count; j++) { mTimer.Begin(TIMER_KEY_ASTAR_PF); for (int i = 0; i < LoopTimes; i++) { aStars.FindPath(start, end); } mTimer.End(TIMER_KEY_ASTAR_PF); resTimeListIn.Add(mTimer.GetSumTime(TIMER_KEY_ASTAR_PF)); } resTimeListIn.Sort(); float sumTimeIn = 0.0f; for (int i = 1; i <= resTimeListIn.Count - 2; i++) { sumTimeIn += resTimeListIn[i]; } resTimeListOut.Add((sumTimeIn / (resTimeListIn.Count - 2)) / LoopTimes); mSimplePath = aStars.FindPath(start, end); } resTimeListOut.Sort(); float sumTimeOut = 0.0f; for (int i = 1; i <= resTimeListOut.Count - 2; i++) { sumTimeOut += resTimeListOut[i]; } float time = sumTimeOut / (resTimeListOut.Count - 2); List <Node> pathNodeList = new List <Node>(); for (int i = 0; i < mSimplePath.Count; i++) { SimpleAStar.Point point = mSimplePath[i]; pathNodeList.Add(new Node(point.X, point.Y)); } int cost = CalculatePathConsume(pathNodeList); //float time = mTimer.GetSumTime(TIMER_KEY_ASTAR_PF); //SpawnMap(); HTLogger.Debug(string.Format("(简易 AStar)寻路 {0} 次:{1}毫秒", LoopTimes, time * LoopTimes)); HTLogger.Debug(string.Format("(简易 AStar)寻路 1 次:{0}毫秒", time)); HTLogger.Debug("(简易 AStar)路径消耗:" + cost); }