예제 #1
0
        static void DrawLine(NavGrid grid, Vector2i start, Vector2i end)
        {
            Vector2 startPosition = grid.GetCasePosition(start);
            Vector2 endPosition   = grid.GetCasePosition(end);

            Gizmos.color = grid.Color;
            Gizmos.DrawLine(startPosition, endPosition);
        }
예제 #2
0
        private void ConstructPath()
        {
            _path.Clear();
            _smoothPath.Clear();

            _currentNodeIndex = 0;

            if (!_target.isSet)
            {
                return;
            }

            NavGrid navGrid = Map.instance.navGrid;

            // We first try to see if we can reach the target straightly without
            // needed a pathfinding

            // to see that, we look for a clear line between the character and the target
            if (CanReachTargetDirectly())
            {
                return;
            }

            Profiler.BeginSample("A*");
            _coordPath = Pathfinder.A_Star(_character.position, _target.position);
            Profiler.EndSample();

            for (int i = 0; i < _coordPath.Count; i++)
            {
                _path.Add(navGrid.GetCasePosition(_coordPath[i]));
            }

            Profiler.BeginSample("smooth");
            _smoothCoordPath = PathSmoother.SmoothPath(_coordPath);
            Profiler.EndSample();

            for (int i = 0; i < _smoothCoordPath.Count; i++)
            {
                _smoothPath.Add(navGrid.GetCasePosition(_smoothCoordPath[i]));
            }
        }
예제 #3
0
        void ConstructTestLists()
        {
            int     testToDo = 10000;
            NavGrid navgrid  = Map.instance.navGrid;

            for (int i = 0; i < testToDo; i++)
            {
                Vector2i startCoord = GetRandomPointOnNavgrid(navgrid);
                Vector2i endCoord   = GetRandomPointOnNavgrid(navgrid);

                //Vector2i startCoord = new Vector2i(0, 0);
                //Vector2i endCoord = new Vector2i(navgrid.width-1, navgrid.height-1);

                coords.Add(startCoord);
                coords.Add(endCoord);

                Vector2 startPosition = navgrid.GetCasePosition(startCoord);
                Vector2 endPosition   = navgrid.GetCasePosition(endCoord);

                points.Add(startPosition);
                points.Add(endPosition);
            }
        }