示例#1
0
        public IEnumerator Create1000by1000andPathFrom0_0to999_999AndWriteToPNGFile()
        {
            float size           = 1000f;
            var   mapRect        = new Rect(-size / 2f, -size / 2f, size, size);
            var   map            = new ArrayGrid <int>(mapRect.size.ToInt());
            var   start          = new Vector2Int(0, 0);
            var   end            = map.MaxValidPosition;
            bool  searchDiagonal = true;
            bool  debug          = false;

            AStar pathFinder = new AStar();

            yield return(pathFinder.FindPath(map, start, end, null, searchDiagonal, debug));

            Assert.That(pathFinder.result != null, Is.True, "Path failed to generate.");

            var path = pathFinder.result;

            map.SetElements(path, 3);
            Texture2D mapTex;

            mapTex = map.ToTexture(WriteColor);
            yield return(WriteToFile(mapTex, testOutputPath + "1000by1000BasicTestOutputPath.png"));

            Assert.That(File.Exists(testOutputPath + "1000by1000BasicTestOutputPath.png"), Is.True, "Failed to write test output to file.");

            yield break;
        }
示例#2
0
    IEnumerator Start()
    {
        //yield return ReadFromFile(Application.dataPath + "/TestMap.png");

        if (mapTex == null)
        {
            float size = 100f;
            mapRect = new Rect(-size / 2f, -size / 2f, size, size);

            List <Vector2Int> startPositions = new List <Vector2Int>()
            {
                new Vector2Int(10, 0), new Vector2Int(50, 98)
            };

            yield return(Setup(mapRect, startPositions));

            yield return(Map());

            //path finding code
            //if(false)
            {
                List <Vector2Int> path = new List <Vector2Int>();
                //FindAPath<int> pathFinder = new FindAPath<int>();

                //Node start = new Node(startPositions[0], (int)startPositions[0].x, (int)startPositions[0].y, 1f);
                //Node end = new Node(startPositions[1], (int)startPositions[1].x, (int)startPositions[1].y, 1f);

                debugMap = new ArrayGrid <int>(map);

                //path = pathFinder.GetPath(map, start, end).Select(x=> x.localPosition).ToList();
                AStar pathFinder = new AStar();
                pathFinder.throttle = 100;

                //pathFinder.throttleIterations = 100;
                IEnumerator runningPathFinder = pathFinder.FindPath(map, startPositions[0], startPositions[1], null, true, true);
                runningPathFinder.MoveNext();
                while (pathFinder.result == null)
                {
                    //clear previous path
                    //map.SetElements(path, 0);

                    //get next path
                    runningPathFinder.MoveNext();

                    if (pathFinder.debugPath != null)
                    {
                        mapTex = debugMap.ToTexture(WriteColor);
                        debugMap.SetElements(pathFinder.debugPath, 2);
                        UpdateSprite();
                    }

                    yield return(new WaitForEndOfFrame());
                }

                path = pathFinder.result;

                map.SetElements(path, 3);
            }

            mapTex = map.ToTexture(WriteColor);

            //yield return WriteToFile(Application.dataPath + "/TestMap.png");
        }

        UpdateSprite();

        yield break;
    }