支持设置门的朝向
1 parent b975ddf commit 393e310a07a151717e53c67212e1c6ecf64fdd4b
@小李xl 小李xl authored on 25 Jul 2023
Showing 2 changed files
View
76
DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragArea.cs
 
//错误时的颜色
private static Color _errorColor = new Color(1, 0, 0, 0.1882353F);
 
/// <summary>
/// 朝向
/// </summary>
public DoorDirection Direction { get; private set; }
private MapEditorTools.DoorToolTemplate _node;
private Vector2 _startTempPos;
private Vector2 _endTempPos;
//默认颜色
//拖拽松手后是否可以提交
private bool _canComment = true;
//开始拖拽时的区域
private Vector2I _startDragRange;
//原始缩放
private Vector2 _originScale;
 
public void SetDoorDragAreaNode(MapEditorTools.DoorToolTemplate node)
{
_node = node;
_originScale = Scale;
_defaultColor = _node.L_DoorArea.Instance.Color;
_node.L_StartBtn.Instance.DragEvent += OnStartAreaDrag;
_node.L_EndBtn.Instance.DragEvent += OnEndAreaDrag;
SetDoorAreaSize(GameConfig.TileCellSize * 4);
}
 
SetDoorAreaDirection(DoorDirection.N);
}
 
/// <summary>
/// 设置门区域的方向
/// </summary>
public void SetDoorAreaDirection(DoorDirection direction)
{
Direction = direction;
if (direction == DoorDirection.N)
{
_originScale = new Vector2(1, 1);
RotationDegrees = 0;
}
else if (direction == DoorDirection.E)
{
_originScale = new Vector2(1, 1);
RotationDegrees = 90;
}
else if (direction == DoorDirection.S)
{
_originScale = new Vector2(-1, 1);
RotationDegrees = 180;
}
else
{
_originScale = new Vector2(-1, 1);
RotationDegrees = 270;
}
}
/// <summary>
/// 设置位置和缩放, 用于跟随地图
/// </summary>
public void SetDoorAreaTransform(Vector2 pos, Vector2 scale)
{
Position = pos;
Scale = scale;
Scale = _originScale * scale;
}
/// <summary>
/// 获取门区域所占范围, 单位: 像素, 返回的 Vector2I 的 x 代表起始坐标, y 代表结束坐标
View
14
DungeonShooting_Godot/src/game/ui/mapEditorTools/DoorDragButton.cs
{
if (DragEvent != null)
{
var offset = Utils.Adsorption((GetGlobalMousePosition() - _startPos) / _parent.Scale, _stepValue);
//处理朝向问题
if (_parent.Direction == DoorDirection.E)
{
offset = new Vector2(offset.Y, offset.X);
}
else if (_parent.Direction == DoorDirection.S)
{
offset = new Vector2(-offset.X, offset.Y);
}
else if (_parent.Direction == DoorDirection.W)
{
offset = new Vector2(offset.Y, -offset.X);
}
if (offset != _prevPos)
{
_prevPos = offset;
DragEvent(DragState.DragMove, offset);