Пример #1
0
        void IUpdatable.Update()
        {
            // on left click set our path end time
            if (Input.LeftMouseButtonPressed)
            {
                _end = _tilemap.WorldToTilePosition(Input.MousePosition);
            }

            // on right click set our path start time
            if (Input.RightMouseButtonPressed)
            {
                _start = _tilemap.WorldToTilePosition(Input.MousePosition);
            }

            // regenerate the path on either click
            if (Input.LeftMouseButtonPressed || Input.RightMouseButtonPressed)
            {
                // time both path generations
                var first = Debug.TimeAction(() => { _breadthSearchPath = _gridGraph.Search(_start, _end); });

                var second = Debug.TimeAction(() => { _weightedSearchPath = _weightedGraph.Search(_start, _end); });

                var third = Debug.TimeAction(() => { _astarSearchPath = _astarGraph.Search(_start, _end); });

                // debug draw the times
                Debug.DrawText("Breadth First: {0}\nDijkstra: {1}\nAstar: {2}", first, second, third);
                Debug.Log("\nBreadth First: {0}\nDijkstra: {1}\nAstar: {2}", first, second, third);
            }
        }
Пример #2
0
        public Pathfinder(TmxMap tilemap)
        {
            _tilemap = tilemap;
            var layer = tilemap.GetLayer <TmxLayer>("main");

            _start = new Point(1, 1);
            _end   = new Point(10, 10);

            _gridGraph         = new UnweightedGridGraph(layer);
            _breadthSearchPath = _gridGraph.Search(_start, _end);

            _weightedGraph      = new WeightedGridGraph(layer);
            _weightedSearchPath = _weightedGraph.Search(_start, _end);

            _astarGraph      = new AstarGridGraph(layer);
            _astarSearchPath = _astarGraph.Search(_start, _end);

            Debug.DrawTextFromBottom = true;
        }