Files
AppleHillsProduction/Assets/Scripts/UI/CardSystem/StateMachine/States/CardFlippingState.cs
2025-11-15 20:37:01 +01:00

82 lines
2.3 KiB
C#

using Core.SaveLoad;
using UnityEngine;
namespace UI.CardSystem.StateMachine.States
{
/// <summary>
/// Flipping state - handles the card flip animation from back to front.
/// Owns the CardBackVisual as a child GameObject.
/// </summary>
public class CardFlippingState : AppleState
{
[Header("State-Owned Visuals")]
[SerializeField] private GameObject cardBackVisual;
private CardContext _context;
private void Awake()
{
_context = GetComponentInParent<CardContext>();
}
public override void OnEnterState()
{
// Activate card back, hide card front
if (cardBackVisual != null)
{
cardBackVisual.SetActive(true);
}
if (_context.CardDisplay != null)
{
_context.CardDisplay.gameObject.SetActive(false);
}
// Play flip animation + scale punch
if (_context.Animator != null)
{
_context.Animator.PlayFlip(
cardBack: cardBackVisual.transform,
cardFront: _context.CardDisplay.transform,
onComplete: OnFlipComplete
);
_context.Animator.PlayFlipScalePunch();
}
}
private void OnFlipComplete()
{
// Transition based on whether this is a new card or repeat
if (_context.IsNewCard)
{
_context.StateMachine.ChangeState("EnlargedNewState");
}
else if (_context.RepeatCardCount > 0)
{
_context.StateMachine.ChangeState("EnlargedRepeatState");
}
else
{
_context.StateMachine.ChangeState("RevealedState");
}
}
private void OnDisable()
{
// Hide card back when leaving state
if (cardBackVisual != null)
{
cardBackVisual.SetActive(false);
}
// Ensure card front is visible
if (_context?.CardDisplay != null)
{
_context.CardDisplay.gameObject.SetActive(true);
}
}
}
}