예제 #1
0
        public List <Vector3> FindPath(Vector3 from, Vector3 to, int bodysize)
        {
            List <Vector3> result = new List <Vector3>();
            CellPos        start, end;
            ICellMapView   view = cell_manager_.GetCellMapView(bodysize);
            CellPos        start0;

            view.GetCell(from, out start0.row, out start0.col);
            view.GetCell(to, out end.row, out end.col);
            start = view.GetFirstWalkableCell(from, to);
            if (start.row >= 0 && start.col >= 0)
            {
                List <CellPos> path = PathFinder.FindPath(cell_manager_.GetCellMapView(bodysize), start, end);
                if (start0.row != start.row || start0.col != start.col)
                {
                    result.Add(view.GetCellCenter(start0.row, start0.col));
                }
                for (int ix = path.Count - 1; ix >= 0; --ix)
                {
                    CellPos pos = path[ix];
                    result.Add(view.GetCellCenter(pos.row, pos.col));
                }
            }
            else
            {
                result.Add(view.GetCellCenter(start0.row, start0.col));
                result.Add(view.GetCellCenter(end.row, end.col));
            }
            return(result);
        }
예제 #2
0
        public List <Vector3> FindPath(Vector3 from, Vector3 to, int scope, int bodysize)
        {
            List <Vector3> result = new List <Vector3>();
            CellPos
                start           = new CellPos(),
                end             = new CellPos(),
                minCell         = new CellPos(),
                maxCell         = new CellPos();
            ICellMapView view   = cell_manager_.GetCellMapView(bodysize);
            CellPos      start0 = new CellPos();

            view.GetCell(from, out start0.row, out start0.col);
            view.GetCell(to, out end.row, out end.col);
            start = view.GetFirstWalkableCell(from, to);
            if (start.row >= 0 && start.col >= 0)
            {
                minCell.row = Math.Min(start.row, end.row) - scope;
                minCell.col = Math.Min(start.col, end.col) - scope;
                maxCell.row = Math.Max(start.row, end.row) + scope;
                maxCell.col = Math.Max(start.col, end.col) + scope;
                if (minCell.row < 0)
                {
                    minCell.row = 0;
                }
                if (minCell.col < 0)
                {
                    minCell.col = 0;
                }
                if (maxCell.row >= view.MaxRowCount)
                {
                    maxCell.row = view.MaxRowCount - 1;
                }
                if (maxCell.col >= view.MaxColCount)
                {
                    maxCell.col = view.MaxColCount - 1;
                }
                List <CellPos> path = PathFinder.FindPath(cell_manager_.GetCellMapView(bodysize), start, end, minCell, maxCell);
                if (start0.row != start.row || start0.col != start.col)
                {
                    result.Add(view.GetCellCenter(start0.row, start0.col));
                }
                for (int ix = path.Count - 1; ix >= 0; --ix)
                {
                    CellPos pos = path[ix];
                    result.Add(view.GetCellCenter(pos.row, pos.col));
                }
            }
            return(result);
        }