66 lines
2.2 KiB
C#
66 lines
2.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace UI.CardSystem.StateMachine.States
|
|
{
|
|
/// <summary>
|
|
/// Optional helper component for handling drag/drop integration with existing DragDrop system.
|
|
/// Can be attached to Card root to bridge between state machine and drag system.
|
|
/// </summary>
|
|
public class CardInteractionHandler : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler
|
|
{
|
|
private CardContext _context;
|
|
private CardDraggingState _draggingState;
|
|
private bool _isDragging;
|
|
|
|
private void Awake()
|
|
{
|
|
_context = GetComponent<CardContext>();
|
|
}
|
|
|
|
public void OnBeginDrag(PointerEventData eventData)
|
|
{
|
|
// Only allow drag from certain states
|
|
var currentState = _context.StateMachine.currentState?.name;
|
|
if (currentState != "RevealedState" && currentState != "PlacedInSlotState")
|
|
{
|
|
return;
|
|
}
|
|
|
|
// Transition to dragging state
|
|
_context.StateMachine.ChangeState("DraggingState");
|
|
_draggingState = _context.StateMachine.currentState?.GetComponent<CardDraggingState>();
|
|
_isDragging = true;
|
|
}
|
|
|
|
public void OnDrag(PointerEventData eventData)
|
|
{
|
|
if (!_isDragging || _draggingState == null) return;
|
|
|
|
// Update drag position
|
|
Vector3 worldPosition;
|
|
RectTransformUtility.ScreenPointToWorldPointInRectangle(
|
|
transform as RectTransform,
|
|
eventData.position,
|
|
eventData.pressEventCamera,
|
|
out worldPosition
|
|
);
|
|
|
|
_draggingState.UpdateDragPosition(worldPosition);
|
|
}
|
|
|
|
public void OnEndDrag(PointerEventData eventData)
|
|
{
|
|
if (!_isDragging || _draggingState == null) return;
|
|
|
|
_isDragging = false;
|
|
|
|
// Check if dropped over a valid slot
|
|
// This would integrate with your existing AlbumCardSlot system
|
|
// For now, just return to revealed state
|
|
_draggingState.OnDroppedOutsideSlot();
|
|
}
|
|
}
|
|
}
|
|
|