Files
HX_MapEditor/Assets/Scripts/Map/CellNode.cs
2025-06-15 20:14:45 +08:00

72 lines
1.6 KiB
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 UnityEngine;
namespace HxGame
{
public enum CELL_SIDE
{
TopLeft = 0,
Top = 1,
TopRight = 2,
BottomRight = 3,
Bottom = 4,
BottomLeft = 5,
Left = 6,
Right = 7
}
public class CellNode
{
//格子坐标
//private readonly int _row;
//private readonly int _column;
private readonly int _x;
private readonly int _y;
private readonly int _index;
//格子类型, 可移动、阻挡、隐藏
public CellType cellType = CellType.Obstacle;
public int X { get { return _x; } }
public int Y { get { return _y; } }
public int index { get { return _index; } }
float[] _crossCost;
/// <summary>
/// 格子的消耗默认1.
/// </summary>
public float[] crossCost
{
get { return _crossCost; }
set { _crossCost = value; }
}
/// <summary>
/// 此单元格的组。可以指定不同的组与FindPath cellGroupMask参数一起使用
/// </summary>
public int group = 1;
//由于编辑器格子宽高可能不固定,所以动态换算
public Vector3 GetPos(float width, float height)
{
float x = _x * width + width / 2;
float z = _y * height + height / 2;
return new Vector3(x, 0.03f, z);
}
public CellNode(int x, int y, int index, CellType type)
{
_x = x;
_y = y;
_index = index;
if (type == CellType.Safe)
cellType |= CellType.Safe;
else
cellType = type;
}
}
}