using System.Collections; using System.Collections.Generic; using UnityEngine; namespace Ether { public class AStarGrid { private int width; private int height; private AStarNode[,] gridNode; /// /// 构造函数初始化节点范围数组 /// public AStarGrid(int gridWidth, int gridHeight) { SetData(gridWidth, gridHeight); } private void SetData(int gridWidth, int gridHeight) { this.width = gridWidth; this.height = gridHeight; gridNode = new AStarNode[gridWidth, gridHeight]; for (int x = 0; x < gridWidth; x++) { for (int y = 0; y < gridHeight; y++) { gridNode[x, y] = new AStarNode(new Vector2Int(x, y)); } } } public AStarNode GetGridNode(int xPos, int yPos) { if (xPos < width && yPos < height) { return gridNode[xPos, yPos]; } Debug.Log("超出寻路网格范围"); return null; } public void Reset(int gridWidth, int gridHeight) { SetData(gridWidth, gridHeight); } } }