59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
using HxGame;
|
||
using HxGame.PathFinding;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
|
||
public partial class MapManager : MonoBehaviour
|
||
{
|
||
PathFinderHelper _pathFinderHelper = null;
|
||
|
||
public void FindPath(Vector2Int startPos, Vector2Int endPos)
|
||
{
|
||
CellNode startCell = GetCell(startPos.x, startPos.y);
|
||
CellNode endCell = GetCell(endPos.x, endPos.y);
|
||
|
||
if (startCell == null)
|
||
{
|
||
UIWindow.Instance.ShowMessage("起点坐标无效");
|
||
return;
|
||
}
|
||
|
||
if (endCell == null)
|
||
{
|
||
UIWindow.Instance.ShowMessage("终点坐标无效");
|
||
return;
|
||
}
|
||
|
||
if (_pathFinderHelper == null)
|
||
{
|
||
_pathFinderHelper = new PathFinderHelper(cellsNode, _cellRows, _cellCols);
|
||
}
|
||
|
||
GetSpecialName(EditCellType.PathNodeCell, out int size);
|
||
|
||
for(int i=1; i<=size; i++)
|
||
{
|
||
SetCurPathNodePointIdx(i);
|
||
RemoveSpecialPoint(EditCellType.PathNodeCell);
|
||
}
|
||
_pathNodePointSize = 0;
|
||
|
||
List<int> route = _pathFinderHelper.FindPath(startCell.index, endCell.index, 0, 0, 1);
|
||
|
||
for (int i = 0; i < route.Count; i++)
|
||
{
|
||
CellNode cell = GetCell(route[i]);
|
||
size = AddPathNodePointSize();
|
||
SetCurPathNodePointIdx(size);
|
||
Debug.Log("经过 :" + route[i]);
|
||
}
|
||
}
|
||
|
||
private int OnCrossCellNode(int cellIndex)
|
||
{
|
||
Debug.Log("经过 :" + cellIndex);
|
||
return 1;
|
||
}
|
||
|
||
}
|