Files
HX_MapEditor/Assets/Scripts/Map/MapManager.Path.cs

62 lines
1.5 KiB
C#
Raw Normal View History

2025-06-14 13:46:24 +08:00
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("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч");
return;
}
if (endCell == null)
{
UIWindow.Instance.ShowMessage("<22>յ<EFBFBD><D5B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч");
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);
CreateSpecialPoint(cell.X, cell.Y, EditCellType.PathNodeCell);
Debug.Log("<22><><EFBFBD><EFBFBD> <20><>" + route[i]);
}
}
private int OnCrossCellNode(int cellIndex)
{
Debug.Log("<22><><EFBFBD><EFBFBD> <20><>" + cellIndex);
return 1;
}
}