Files
HX_MapEditor/Assets/Scripts/Map/MapManager.Path.cs
2025-07-18 22:28:40 +08:00

59 lines
1.5 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}