First go at the card UI
This commit is contained in:
committed by
Michal Adam Pikulski
parent
7f3dccf1ea
commit
ed9f2d6c6d
@@ -20,22 +20,32 @@ namespace AppleHills.UI.CardSystem
|
||||
[SerializeField] private GameObject cardPrefab;
|
||||
[SerializeField] private Button openBoosterButton;
|
||||
[SerializeField] private Button continueButton;
|
||||
[SerializeField] private CanvasGroup canvasGroup;
|
||||
|
||||
[Header("Animation Settings")]
|
||||
[SerializeField] private float cardRevealDelay = 0.5f;
|
||||
[SerializeField] private float cardMoveToBackpackDelay = 1.0f;
|
||||
[SerializeField] private Transform backpackTargetTransform;
|
||||
[SerializeField] private AudioSource cardRevealSound;
|
||||
[SerializeField] private AudioSource rareCardSound;
|
||||
[SerializeField] private ParticleSystem cardRevealParticles;
|
||||
[SerializeField] private ParticleSystem rareCardParticles;
|
||||
|
||||
// State tracking
|
||||
private enum OpeningState
|
||||
{
|
||||
BoosterReady,
|
||||
CardsRevealing,
|
||||
CardsRevealed,
|
||||
MovingToBackpack,
|
||||
Completed
|
||||
}
|
||||
|
||||
private OpeningState _currentState = OpeningState.BoosterReady;
|
||||
private List<CardUIElement> _revealedCards = new List<CardUIElement>();
|
||||
private CardSystemManager _cardManager;
|
||||
private Coroutine _revealCoroutine;
|
||||
private Coroutine _moveToBackpackCoroutine;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -52,6 +62,12 @@ namespace AppleHills.UI.CardSystem
|
||||
continueButton.onClick.AddListener(OnContinueClicked);
|
||||
continueButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
// Make sure we have a CanvasGroup for transitions
|
||||
if (canvasGroup == null)
|
||||
canvasGroup = GetComponent<CanvasGroup>();
|
||||
if (canvasGroup == null)
|
||||
canvasGroup = gameObject.AddComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
@@ -66,6 +82,13 @@ namespace AppleHills.UI.CardSystem
|
||||
{
|
||||
continueButton.onClick.RemoveListener(OnContinueClicked);
|
||||
}
|
||||
|
||||
// Stop any running coroutines
|
||||
if (_revealCoroutine != null)
|
||||
StopCoroutine(_revealCoroutine);
|
||||
|
||||
if (_moveToBackpackCoroutine != null)
|
||||
StopCoroutine(_moveToBackpackCoroutine);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -86,7 +109,8 @@ namespace AppleHills.UI.CardSystem
|
||||
// Clear any previously revealed cards
|
||||
foreach (var card in _revealedCards)
|
||||
{
|
||||
Destroy(card.gameObject);
|
||||
if (card != null && card.gameObject != null)
|
||||
Destroy(card.gameObject);
|
||||
}
|
||||
_revealedCards.Clear();
|
||||
|
||||
@@ -117,6 +141,8 @@ namespace AppleHills.UI.CardSystem
|
||||
{
|
||||
if (_currentState != OpeningState.BoosterReady) return;
|
||||
|
||||
_currentState = OpeningState.CardsRevealing;
|
||||
|
||||
// Open the booster pack and get the cards
|
||||
List<CardData> newCards = _cardManager.OpenBoosterPack();
|
||||
|
||||
@@ -125,7 +151,10 @@ namespace AppleHills.UI.CardSystem
|
||||
// Hide the booster pack and open button
|
||||
if (boosterPackObject != null)
|
||||
{
|
||||
boosterPackObject.SetActive(false);
|
||||
// Animate the booster pack opening
|
||||
Tween.LocalScale(boosterPackObject.transform, Vector3.zero, 0.3f, 0f, Tween.EaseInBack, Tween.LoopType.None, null, () => {
|
||||
boosterPackObject.SetActive(false);
|
||||
});
|
||||
}
|
||||
|
||||
if (openBoosterButton != null)
|
||||
@@ -134,7 +163,7 @@ namespace AppleHills.UI.CardSystem
|
||||
}
|
||||
|
||||
// Start revealing cards
|
||||
StartCoroutine(RevealCards(newCards));
|
||||
_revealCoroutine = StartCoroutine(RevealCards(newCards));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -173,6 +202,38 @@ namespace AppleHills.UI.CardSystem
|
||||
// Call card's show animation
|
||||
cardUI.OnShowAnimation();
|
||||
|
||||
// Play appropriate sound and particles based on rarity
|
||||
if (cardData.Rarity >= CardRarity.Rare)
|
||||
{
|
||||
// Play rare card sound
|
||||
if (rareCardSound != null)
|
||||
{
|
||||
rareCardSound.Play();
|
||||
}
|
||||
|
||||
// Play rare card particles
|
||||
if (rareCardParticles != null)
|
||||
{
|
||||
rareCardParticles.transform.position = cardObj.transform.position;
|
||||
rareCardParticles.Play();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Play regular card sound
|
||||
if (cardRevealSound != null)
|
||||
{
|
||||
cardRevealSound.Play();
|
||||
}
|
||||
|
||||
// Play regular particles
|
||||
if (cardRevealParticles != null)
|
||||
{
|
||||
cardRevealParticles.transform.position = cardObj.transform.position;
|
||||
cardRevealParticles.Play();
|
||||
}
|
||||
}
|
||||
|
||||
// Wait for animation delay
|
||||
yield return new WaitForSeconds(cardRevealDelay);
|
||||
}
|
||||
@@ -183,6 +244,10 @@ namespace AppleHills.UI.CardSystem
|
||||
if (continueButton != null)
|
||||
{
|
||||
continueButton.gameObject.SetActive(true);
|
||||
|
||||
// Animate button appearance
|
||||
continueButton.transform.localScale = Vector3.zero;
|
||||
Tween.LocalScale(continueButton.transform, Vector3.one, 0.3f, 0f, Tween.EaseOutBack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,8 +258,15 @@ namespace AppleHills.UI.CardSystem
|
||||
{
|
||||
if (_currentState != OpeningState.CardsRevealed) return;
|
||||
|
||||
_currentState = OpeningState.MovingToBackpack;
|
||||
|
||||
if (continueButton != null)
|
||||
{
|
||||
continueButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
// Start moving cards to backpack animation
|
||||
StartCoroutine(MoveCardsToBackpack());
|
||||
_moveToBackpackCoroutine = StartCoroutine(MoveCardsToBackpack());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -202,48 +274,46 @@ namespace AppleHills.UI.CardSystem
|
||||
/// </summary>
|
||||
private IEnumerator MoveCardsToBackpack()
|
||||
{
|
||||
// Hide continue button
|
||||
if (continueButton != null)
|
||||
// If no backpack target, use a default position (lower-right corner)
|
||||
Vector3 targetPosition = (backpackTargetTransform != null)
|
||||
? backpackTargetTransform.position
|
||||
: new Vector3(Screen.width * 0.9f, Screen.height * 0.1f, 0f);
|
||||
|
||||
// Move each card to backpack with animation
|
||||
foreach (var cardUI in _revealedCards)
|
||||
{
|
||||
continueButton.gameObject.SetActive(false);
|
||||
if (cardUI != null)
|
||||
{
|
||||
// Call card's move to backpack animation
|
||||
cardUI.OnMoveToBackpackAnimation();
|
||||
|
||||
// Animate movement to backpack
|
||||
Tween.Position(cardUI.transform, targetPosition, 0.5f, 0f, Tween.EaseInBack);
|
||||
Tween.LocalScale(cardUI.transform, Vector3.zero, 0.5f, 0f, Tween.EaseInBack);
|
||||
|
||||
// Wait for delay between cards
|
||||
yield return new WaitForSeconds(0.2f);
|
||||
}
|
||||
}
|
||||
|
||||
// Get corner position for backpack (bottom left)
|
||||
Vector3 cornerPosition = new Vector3(-Screen.width/2 + 50, -Screen.height/2 + 50, 0);
|
||||
// Wait for final animation
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
|
||||
// Animate each card moving to the backpack
|
||||
foreach (var card in _revealedCards)
|
||||
{
|
||||
// Play move to backpack animation using Pixelplacement.Tween
|
||||
Tween.Position(card.transform, cornerPosition, 0.5f, 0f, Tween.EaseInBack);
|
||||
Tween.LocalScale(card.transform, Vector3.zero, 0.5f, 0f, Tween.EaseInBack);
|
||||
|
||||
// Call card's move to backpack animation
|
||||
card.OnMoveToBackpackAnimation();
|
||||
|
||||
// Wait for animation delay
|
||||
yield return new WaitForSeconds(cardMoveToBackpackDelay);
|
||||
}
|
||||
|
||||
// Wait a moment before completing
|
||||
yield return new WaitForSeconds(0.3f);
|
||||
|
||||
// Complete the process and return to previous page
|
||||
// Update state to completed
|
||||
_currentState = OpeningState.Completed;
|
||||
|
||||
// Return to previous page
|
||||
UIPageController.Instance.PopPage();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override for transition in animation using Pixelplacement.Tween
|
||||
/// </summary>
|
||||
// Override for transition animations
|
||||
protected override void DoTransitionIn(System.Action onComplete)
|
||||
{
|
||||
// Scale in animation for the booster pack
|
||||
if (boosterPackObject != null)
|
||||
// Simple fade in animation
|
||||
if (canvasGroup != null)
|
||||
{
|
||||
boosterPackObject.transform.localScale = Vector3.zero;
|
||||
Tween.LocalScale(boosterPackObject.transform, Vector3.one, transitionDuration, 0f,
|
||||
Tween.EaseOutBack, Tween.LoopType.None, null, onComplete);
|
||||
canvasGroup.alpha = 0f;
|
||||
Tween.Value(0f, 1f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -251,17 +321,12 @@ namespace AppleHills.UI.CardSystem
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Override for transition out animation using Pixelplacement.Tween
|
||||
/// </summary>
|
||||
protected override void DoTransitionOut(System.Action onComplete)
|
||||
{
|
||||
// Fade out animation using a CanvasGroup if available
|
||||
CanvasGroup canvasGroup = GetComponent<CanvasGroup>();
|
||||
// Simple fade out animation
|
||||
if (canvasGroup != null)
|
||||
{
|
||||
Tween.Value(canvasGroup.alpha, 0f, (value) => canvasGroup.alpha = value,
|
||||
transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete);
|
||||
Tween.Value(canvasGroup.alpha, 0f, (value) => canvasGroup.alpha = value, transitionDuration, 0f, Tween.EaseInOut, Tween.LoopType.None, null, onComplete);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user