2025-11-06 11:11:15 +01:00
|
|
|
|
using AppleHills.Data.CardSystem;
|
|
|
|
|
|
using UI.DragAndDrop.Core;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace UI.CardSystem.DragDrop
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Visual representation for CardDraggable.
|
|
|
|
|
|
/// Uses the existing CardDisplay component to render the card.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class CardDraggableVisual : DraggableVisual
|
|
|
|
|
|
{
|
|
|
|
|
|
[Header("Card Visual Components")]
|
|
|
|
|
|
[SerializeField] private CardDisplay cardDisplay;
|
|
|
|
|
|
[SerializeField] private Transform shadowTransform;
|
|
|
|
|
|
[SerializeField] private float shadowOffset = 20f;
|
|
|
|
|
|
|
|
|
|
|
|
private Vector3 _shadowInitialPosition;
|
|
|
|
|
|
private CardDraggable _cardDraggable;
|
|
|
|
|
|
|
|
|
|
|
|
public CardDisplay CardDisplay => cardDisplay;
|
|
|
|
|
|
|
|
|
|
|
|
public override void Initialize(DraggableObject parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize(parent);
|
|
|
|
|
|
|
|
|
|
|
|
_cardDraggable = parent as CardDraggable;
|
|
|
|
|
|
|
|
|
|
|
|
// Get CardDisplay component if not assigned
|
|
|
|
|
|
if (cardDisplay == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
cardDisplay = GetComponentInChildren<CardDisplay>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Initialize shadow
|
|
|
|
|
|
if (shadowTransform != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_shadowInitialPosition = shadowTransform.localPosition;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Subscribe to card data changes
|
|
|
|
|
|
if (_cardDraggable != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_cardDraggable.OnCardDataChanged += HandleCardDataChanged;
|
|
|
|
|
|
|
|
|
|
|
|
// Initial card setup
|
|
|
|
|
|
if (_cardDraggable.CardData != null && cardDisplay != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
cardDisplay.SetupCard(_cardDraggable.CardData);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void UpdateVisualContent()
|
|
|
|
|
|
{
|
|
|
|
|
|
// CardDisplay handles its own rendering, no need to update every frame
|
|
|
|
|
|
// This is called every frame but we only update when card data changes
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Refresh the card display with current data
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public void RefreshCardDisplay()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (cardDisplay != null && _cardDraggable != null && _cardDraggable.CardData != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
cardDisplay.SetupCard(_cardDraggable.CardData);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void HandleCardDataChanged(CardDraggable draggable, CardData data)
|
|
|
|
|
|
{
|
|
|
|
|
|
RefreshCardDisplay();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnPointerDownVisual()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnPointerDownVisual();
|
|
|
|
|
|
|
|
|
|
|
|
// Move shadow down when pressed
|
|
|
|
|
|
if (shadowTransform != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
shadowTransform.localPosition = _shadowInitialPosition + (-Vector3.up * shadowOffset);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnPointerUpVisual(bool longPress)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnPointerUpVisual(longPress);
|
|
|
|
|
|
|
|
|
|
|
|
// Restore shadow position
|
|
|
|
|
|
if (shadowTransform != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
shadowTransform.localPosition = _shadowInitialPosition;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnDragStartedVisual()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnDragStartedVisual();
|
|
|
|
|
|
// Card-specific visual effects when dragging starts
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void OnDragEndedVisual()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnDragEndedVisual();
|
|
|
|
|
|
// Card-specific visual effects when dragging ends
|
|
|
|
|
|
}
|
2025-11-11 13:20:06 +01:00
|
|
|
|
|
|
|
|
|
|
protected override void OnDestroy()
|
2025-11-06 11:11:15 +01:00
|
|
|
|
{
|
2025-11-11 13:20:06 +01:00
|
|
|
|
base.OnDestroy();
|
|
|
|
|
|
|
2025-11-06 11:11:15 +01:00
|
|
|
|
if (_cardDraggable != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
_cardDraggable.OnCardDataChanged -= HandleCardDataChanged;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|