public class Node
{
public Node(bool _isWall, int _x, int _y) { isWall = _isWall; x = _x; y = _y; }
public bool isWall;
public Node ParentNode;
// G : 시작으로부터 이동했던 거리, H : |가로|+|세로| 장애물 무시하여 목표까지의 거리, F : G + H
public int x, y, G, H;
public int F { get { return G + H; } }
}
노드(이름 Tile로 다시 짜기)
bool이 아닌 int를 받아와야함
for (int i = 0; i < this.mapData.sizeX; i++)
{
for (int j = 0; j < this.mapData.sizeY; j++)
{
bool isWall = false;
foreach (Collider2D col in Physics2D.OverlapCircleAll(new Vector2(i + bottomLeft.x, j + bottomLeft.y), 0.3f))
if (col.gameObject.layer == LayerMask.NameToLayer("Water")) isWall = true;
this.mapData.NodeArray[i, j] = new Node(isWall, i + bottomLeft.x, j + bottomLeft.y);
}
}
스캔 하는 내용
좌표에다가 원형 레이 하나씩 쏴서 레이어가 Water일경우 isWall이라는 bool값을 true로 만듬
int로 바꿔야함
public class MapData
{
public Vector2Int bottomLeft, topRight;
public int sizeX, sizeY;
public Node[,] NodeArray;
public Node StartNode, TargetNode;
}
그 후 이 맵 데이터에 있는 노드 2차원 배열에 isWall이라는 bool값과 스캔한 좌표값을 이용해서 초기화 시켜서 넣어놓음
그렇게 맵 전체로
맵 크기는
public GameObject hero;
private float span;
public MapData mapData = new MapData();
public Vector2Int bottomLeft, topRight;
// Start is called before the first frame update
void Start()
{
this.mapData.bottomLeft = this.bottomLeft;
this.mapData.topRight = this.topRight;
this.mapData.sizeX = topRight.x - bottomLeft.x + 1;
this.mapData.sizeY = topRight.y - bottomLeft.y + 1;
this.mapData.NodeArray = new Node[this.mapData.sizeX, this.mapData.sizeY];
}
Vector2 를 public으로 뚫어서 미리 입력해둠
이건 생각해봐야할듯

각은 잡힘
'C# > 문제해결' 카테고리의 다른 글
| 1005 공격구현 (0) | 2022.10.05 |
|---|---|
| 0930 공격 구현 (1) | 2022.09.30 |
| 0916 발표용 (0) | 2022.09.16 |
| 0908 UI스크롤뷰의 비율 (0) | 2022.09.08 |
| 0906 DoTween (0) | 2022.09.06 |