102 lines
3.3 KiB
C#
102 lines
3.3 KiB
C#
using Core.SaveLoad;
|
|
using UnityEngine;
|
|
|
|
namespace UI.CardSystem.StateMachine.States
|
|
{
|
|
/// <summary>
|
|
/// Card is in pending face-down state in corner, awaiting drag.
|
|
/// On drag start, triggers data assignment, flip animation, and page navigation.
|
|
/// </summary>
|
|
public class CardPendingFaceDownState : AppleState
|
|
{
|
|
[Header("State-Owned Visuals")]
|
|
[SerializeField] private GameObject cardBackVisual;
|
|
|
|
private CardContext _context;
|
|
private bool _isFlipping;
|
|
|
|
private void Awake()
|
|
{
|
|
_context = GetComponentInParent<CardContext>();
|
|
}
|
|
|
|
public override void OnEnterState()
|
|
{
|
|
if (_context == null) return;
|
|
|
|
_isFlipping = false;
|
|
|
|
// Show card back, hide card front
|
|
if (cardBackVisual != null)
|
|
{
|
|
cardBackVisual.SetActive(true);
|
|
cardBackVisual.transform.localRotation = Quaternion.Euler(0, 0, 0);
|
|
}
|
|
|
|
if (_context.CardDisplay != null)
|
|
{
|
|
_context.CardDisplay.gameObject.SetActive(false);
|
|
_context.CardDisplay.transform.localRotation = Quaternion.Euler(0, 180, 0);
|
|
}
|
|
|
|
// Scale down for corner display
|
|
_context.RootTransform.localScale = _context.OriginalScale * 0.8f;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called by Card.OnDragStartedHook when user starts dragging.
|
|
/// This triggers the smart selection, page navigation, and flip animation.
|
|
/// </summary>
|
|
public void OnDragStarted()
|
|
{
|
|
if (_isFlipping) return; // Already flipping
|
|
|
|
// Start flip animation (data should be assigned by listeners by now)
|
|
StartFlipAnimation();
|
|
}
|
|
|
|
private void StartFlipAnimation()
|
|
{
|
|
_isFlipping = true;
|
|
|
|
// Scale up from corner size to normal dragging size
|
|
if (_context.Animator != null)
|
|
{
|
|
_context.Animator.AnimateScale(_context.OriginalScale * 1.15f, 0.3f);
|
|
}
|
|
|
|
// Play flip animation
|
|
if (_context.Animator != null)
|
|
{
|
|
_context.Animator.PlayFlip(
|
|
cardBack: cardBackVisual != null ? cardBackVisual.transform : null,
|
|
cardFront: _context.CardDisplay != null ? _context.CardDisplay.transform : null,
|
|
onComplete: OnFlipComplete
|
|
);
|
|
}
|
|
else
|
|
{
|
|
// No animator, just switch visibility immediately
|
|
if (cardBackVisual != null) cardBackVisual.SetActive(false);
|
|
if (_context.CardDisplay != null) _context.CardDisplay.gameObject.SetActive(true);
|
|
OnFlipComplete();
|
|
}
|
|
}
|
|
|
|
private void OnFlipComplete()
|
|
{
|
|
// Transition to dragging revealed state
|
|
_context.StateMachine.ChangeState("DraggingRevealedState");
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
// Hide card back when leaving state
|
|
if (cardBackVisual != null)
|
|
{
|
|
cardBackVisual.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
}
|