Updates to testing scene
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using AppleHills.Data.CardSystem;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Input;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -13,7 +15,7 @@ namespace UI.CardSystem.Testing
|
||||
/// Test controller for card state machine testing.
|
||||
/// Provides UI controls to manually test state transitions, animations, and flows.
|
||||
/// </summary>
|
||||
public class CardTestController : MonoBehaviour
|
||||
public class CardTestController : ManagedBehaviour
|
||||
{
|
||||
[Header("Test Card")]
|
||||
[SerializeField] private Card testCard;
|
||||
@@ -31,6 +33,8 @@ namespace UI.CardSystem.Testing
|
||||
private List<string> _eventLog = new List<string>();
|
||||
private CardContext _cardContext;
|
||||
private Vector3 _originalCardPosition;
|
||||
private Vector3 _originalCardScale;
|
||||
private Vector2 _originalAnchoredPosition;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -38,6 +42,14 @@ namespace UI.CardSystem.Testing
|
||||
{
|
||||
_cardContext = testCard.GetComponent<CardContext>();
|
||||
_originalCardPosition = testCard.transform.position;
|
||||
_originalCardScale = testCard.transform.localScale;
|
||||
|
||||
// Store original anchored position if it's a RectTransform
|
||||
RectTransform rectTransform = testCard.GetComponent<RectTransform>();
|
||||
if (rectTransform != null)
|
||||
{
|
||||
_originalAnchoredPosition = rectTransform.anchoredPosition;
|
||||
}
|
||||
|
||||
// Subscribe to all card events
|
||||
if (_cardContext != null)
|
||||
@@ -64,7 +76,14 @@ namespace UI.CardSystem.Testing
|
||||
isClickableToggle.onValueChanged.AddListener(OnIsClickableToggled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
InputManager.Instance.SetInputMode(InputMode.UI);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// Initialize card with test data
|
||||
@@ -88,38 +107,72 @@ namespace UI.CardSystem.Testing
|
||||
|
||||
#region State Transition Buttons
|
||||
|
||||
/// <summary>
|
||||
/// Reset card to default state (position, scale) before transitioning to a new state.
|
||||
/// This prevents accumulation of tweens and ensures animations play correctly.
|
||||
/// </summary>
|
||||
private void ResetCardToDefault()
|
||||
{
|
||||
if (testCard == null || _cardContext == null) return;
|
||||
|
||||
// Stop all animations
|
||||
if (_cardContext.Animator != null)
|
||||
{
|
||||
_cardContext.Animator.StopAllAnimations();
|
||||
}
|
||||
|
||||
// Reset transform immediately
|
||||
testCard.transform.localScale = _originalCardScale;
|
||||
testCard.transform.position = _originalCardPosition;
|
||||
|
||||
// Reset anchored position if it's a RectTransform
|
||||
RectTransform rectTransform = testCard.GetComponent<RectTransform>();
|
||||
if (rectTransform != null)
|
||||
{
|
||||
rectTransform.anchoredPosition = _originalAnchoredPosition;
|
||||
}
|
||||
|
||||
LogEvent("Card reset to default state");
|
||||
}
|
||||
|
||||
public void TransitionToIdleState()
|
||||
{
|
||||
ResetCardToDefault();
|
||||
_cardContext?.StateMachine.ChangeState("IdleState");
|
||||
LogEvent("Transitioned to IdleState");
|
||||
}
|
||||
|
||||
public void TransitionToRevealedState()
|
||||
{
|
||||
ResetCardToDefault();
|
||||
_cardContext?.StateMachine.ChangeState("RevealedState");
|
||||
LogEvent("Transitioned to RevealedState");
|
||||
}
|
||||
|
||||
public void TransitionToEnlargedNewState()
|
||||
{
|
||||
ResetCardToDefault();
|
||||
_cardContext?.StateMachine.ChangeState("EnlargedNewState");
|
||||
LogEvent("Transitioned to EnlargedNewState");
|
||||
}
|
||||
|
||||
public void TransitionToEnlargedRepeatState()
|
||||
{
|
||||
ResetCardToDefault();
|
||||
_cardContext?.StateMachine.ChangeState("EnlargedRepeatState");
|
||||
LogEvent("Transitioned to EnlargedRepeatState");
|
||||
}
|
||||
|
||||
public void TransitionToDraggingState()
|
||||
{
|
||||
ResetCardToDefault();
|
||||
_cardContext?.StateMachine.ChangeState("DraggingState");
|
||||
LogEvent("Transitioned to DraggingState");
|
||||
}
|
||||
|
||||
public void TransitionToAlbumEnlargedState()
|
||||
{
|
||||
ResetCardToDefault();
|
||||
_cardContext?.StateMachine.ChangeState("AlbumEnlargedState");
|
||||
LogEvent("Transitioned to AlbumEnlargedState");
|
||||
}
|
||||
@@ -222,6 +275,9 @@ namespace UI.CardSystem.Testing
|
||||
|
||||
public void PlayFlipAnimation()
|
||||
{
|
||||
// Reset card first to prevent accumulation
|
||||
ResetCardToDefault();
|
||||
|
||||
// Transition to IdleState and programmatically trigger flip
|
||||
TransitionToIdleState();
|
||||
|
||||
@@ -238,7 +294,8 @@ namespace UI.CardSystem.Testing
|
||||
{
|
||||
if (_cardContext?.Animator != null)
|
||||
{
|
||||
_cardContext.Animator.PlayEnlarge(2.5f);
|
||||
ResetCardToDefault();
|
||||
_cardContext.Animator.PlayEnlarge(1.5f);
|
||||
LogEvent("Playing enlarge animation");
|
||||
}
|
||||
}
|
||||
@@ -247,6 +304,7 @@ namespace UI.CardSystem.Testing
|
||||
{
|
||||
if (_cardContext?.Animator != null)
|
||||
{
|
||||
// Don't reset for shrink - we want to shrink from current state
|
||||
_cardContext.Animator.PlayShrink(Vector3.one, null);
|
||||
LogEvent("Playing shrink animation");
|
||||
}
|
||||
@@ -256,15 +314,21 @@ namespace UI.CardSystem.Testing
|
||||
{
|
||||
if (_cardContext?.Animator != null)
|
||||
{
|
||||
_cardContext.Animator.StartIdleHover(10f, 1.5f);
|
||||
// Reset card position first to prevent accumulation
|
||||
ResetCardToDefault();
|
||||
|
||||
_cardContext.Animator.StartIdleHover(10f, 1.5f, restartIfActive: true);
|
||||
LogEvent("Started idle hover animation");
|
||||
}
|
||||
}
|
||||
|
||||
public void StopIdleHoverAnimation()
|
||||
{
|
||||
// Stopping hover is handled by IdleState's OnDisable
|
||||
LogEvent("Idle hover stopped (change state to stop)");
|
||||
if (_cardContext?.Animator != null)
|
||||
{
|
||||
_cardContext.Animator.StopIdleHover(_originalAnchoredPosition);
|
||||
LogEvent("Stopped idle hover animation");
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -276,7 +340,15 @@ namespace UI.CardSystem.Testing
|
||||
if (testCard != null)
|
||||
{
|
||||
testCard.transform.position = _originalCardPosition;
|
||||
testCard.transform.localScale = Vector3.one;
|
||||
testCard.transform.localScale = _originalCardScale;
|
||||
|
||||
// Reset anchored position if it's a RectTransform
|
||||
RectTransform rectTransform = testCard.GetComponent<RectTransform>();
|
||||
if (rectTransform != null)
|
||||
{
|
||||
rectTransform.anchoredPosition = _originalAnchoredPosition;
|
||||
}
|
||||
|
||||
LogEvent("Card position reset");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user