67 lines
2.0 KiB
C#
67 lines
2.0 KiB
C#
using AppleHills.Data.CardSystem;
|
|
using Core.SaveLoad;
|
|
using UnityEngine;
|
|
|
|
namespace UI.CardSystem.StateMachine
|
|
{
|
|
/// <summary>
|
|
/// Shared context for card states.
|
|
/// Provides access to common components and data that states need.
|
|
/// </summary>
|
|
public class CardContext : MonoBehaviour
|
|
{
|
|
[Header("Core Components")]
|
|
[SerializeField] private CardDisplay cardDisplay;
|
|
[SerializeField] private CardAnimator cardAnimator;
|
|
private AppleMachine stateMachine;
|
|
|
|
[Header("Card Data")]
|
|
private CardData cardData;
|
|
|
|
// Public accessors
|
|
public CardDisplay CardDisplay => cardDisplay;
|
|
public CardAnimator Animator => cardAnimator;
|
|
public AppleMachine StateMachine => stateMachine;
|
|
public Transform RootTransform => transform;
|
|
public CardData CardData => cardData;
|
|
|
|
// Runtime state
|
|
public bool IsNewCard { get; set; }
|
|
public int RepeatCardCount { get; set; }
|
|
|
|
private void Awake()
|
|
{
|
|
// Auto-find components if not assigned
|
|
if (cardDisplay == null)
|
|
cardDisplay = GetComponentInChildren<CardDisplay>();
|
|
|
|
if (cardAnimator == null)
|
|
cardAnimator = GetComponent<CardAnimator>();
|
|
|
|
if (stateMachine == null)
|
|
stateMachine = GetComponentInChildren<AppleMachine>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Setup the card with data
|
|
/// </summary>
|
|
public void SetupCard(CardData data, bool isNew = false, int repeatCount = 0)
|
|
{
|
|
cardData = data;
|
|
IsNewCard = isNew;
|
|
RepeatCardCount = repeatCount;
|
|
|
|
if (cardDisplay != null)
|
|
{
|
|
cardDisplay.SetupCard(data);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the card display component
|
|
/// </summary>
|
|
public CardDisplay GetCardDisplay() => cardDisplay;
|
|
}
|
|
}
|
|
|