Files
aibis-dream/Assets/Scripts/MiniGame/BlockPuzzle/Class/ShapeRecycleSlot.cs
T
2026-01-22 18:16:11 +08:00

113 lines
3.1 KiB
C#

using UnityEngine;
namespace AibisDream
{
public class ShapeRecycleSlot : MonoBehaviour
{
public PositionState CurrentState => mover.GetCurrentState();
[SerializeField] private ThreeStatePositionMover mover;
[SerializeField] private BoxArea halfArea;
[SerializeField] private BoxArea openArea;
// ----------------------- 回收逻辑 -----------------------
public void PreRecycle()
{
// 回收槽半弹出
mover.SetToHalf();
// TODO: 边缘发光提示
}
public void OpenForRecycle()
{
// TODO: 回收槽完全弹出
mover.SetToOpen();
// TODO: 边缘发光提示
}
public void CloseForRecycle()
{
// TODO: 回收槽回到半关闭
mover.SetToHalf();
// TODO: 边缘发光提示
}
public void RecycleShape(BlockShape shape)
{
// 将 shape 放到回收槽
PutShapeInSlot(shape);
// TODO: 播放回收动画
// TODO: 销毁Shape
}
// ----------------------- 添加逻辑 -----------------------
public void PopUpShape(BlockShape shape)
{
// 将 shape 添加到回收槽
PutShapeInSlot(shape);
// TODO: 播放弹出动画
}
// ----------------------- 状态校验 -----------------------
private bool _isRecycleAvaliable = false;
public void SetRecycleAvaliable(bool isAvaliable)
{
_isRecycleAvaliable = isAvaliable;
}
/// <summary>
/// 当物体拖动时,更新回收槽状态
/// </summary>
public void UpdateSlotState(IBlockShape shape)
{
// 如果回收槽不可用或者正在移动,则不更新状态
if (!_isRecycleAvaliable || mover.IsMoving) return;
// 开启状态下的判断
if (mover.GetCurrentState() == PositionState.Open)
{
if (!openArea.Contains(shape.GetGlobalCenterPosition()))
{
// TODO: 回到半关闭状态
CloseForRecycle();
}
return;
}
// 半关闭状态下的判断
if (mover.GetCurrentState() == PositionState.Half)
{
Debug.Log("Half: " + halfArea.Contains(shape.GetGlobalCenterPosition()));
if (halfArea.Contains(shape.GetGlobalCenterPosition()))
{
// TODO: 回到开启状态
OpenForRecycle();
}
}
}
private void PutShapeInSlot(BlockShape shape)
{
shape.transform.SetParent(transform);
Vector3 centerPosition = shape.GetCenterPosition();
shape.transform.localPosition = -centerPosition;
}
private void SetMoverState(ShapeRecycleSlotState state)
{
}
}
public enum ShapeRecycleSlotState
{
Close,
Half,
Open
}
}