IndieGame/client/Assets/Scripts/System/AStar/AStarNode.cs

36 lines
977 B
C#
Raw Normal View History

2024-10-11 10:12:15 +08:00

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Ether
{
public class AStarNode : IComparable<AStarNode>
{
public Vector2Int gridPosition; //网格坐标
public int gCost = 0; //距离Start格子的距离
public int hCost = 0; //距离Target格子的距离
public int FCost => gCost + hCost; //当前格子的值
public bool isObstacle = false; //当前格子是否是障碍
public AStarNode parentNode;
public AStarNode(Vector2Int pos)
{
gridPosition = pos;
parentNode = null;
}
public int CompareTo(AStarNode other)
{
//比较选出最低的F值返回-101
int result = FCost.CompareTo(other.FCost);
if (result == 0)
{
result = hCost.CompareTo(other.hCost);
}
return result;
}
}
}