IndieGame/client/Assets/Scripts/System/AStar/AStarNode.cs
DOBEST\zhaoyingjie f242607587 初始化工程
2024-10-11 10:12:15 +08:00

36 lines
977 B
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 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;
}
}
}