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() { // 回收槽完全弹出 mover.SetToOpen(); // TODO: 边缘发光提示 } public void CloseForRecycle() { // 回收槽回到半关闭 mover.SetToHalf(); // TODO: 边缘发光提示 } public void RecycleShape(BlockShape shape) { // 将 shape 放到回收槽 PutShapeInSlot(shape); // 播放回收动画 mover.SetToClose(); // TODO: 销毁Shape } // ----------------------- 添加逻辑 ----------------------- public void PopUpShape(BlockShape shape) { // 将 shape 添加到回收槽 PutShapeInSlot(shape); // TODO: 播放弹出动画 mover.SetToOpen(); } // ----------------------- 状态校验 ----------------------- private bool _isRecycleAvaliable = false; public void SetRecycleAvaliable(bool isAvaliable) { _isRecycleAvaliable = isAvaliable; } /// /// 当物体拖动时,更新回收槽状态 /// public void UpdateSlotState(IBlockShape shape) { // 如果回收槽不可用或者正在移动,则不更新状态 if (!_isRecycleAvaliable || mover.IsMoving) return; // 开启状态下的判断 if (mover.GetCurrentState() == PositionState.Open) { if (!openArea.Contains(shape.GetGlobalCenterPosition())) { CloseForRecycle(); } return; } // 半关闭状态下的判断 if (mover.GetCurrentState() == PositionState.Half) { if (halfArea.Contains(shape.GetGlobalCenterPosition())) { OpenForRecycle(); } } } private void PutShapeInSlot(BlockShape shape) { shape.transform.SetParent(mover.transform); Vector3 centerPosition = shape.GetCenterPosition(); shape.transform.localPosition = -centerPosition; } } }