93 lines
3.0 KiB
C#
93 lines
3.0 KiB
C#
|
|
using System;
|
|||
|
|
using UnityEngine;
|
|||
|
|
|
|||
|
|
namespace AppleHills.UI.CardSystem
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// Base class for UI pages that can transition in and out.
|
|||
|
|
/// Extended by specific UI page implementations for the card system.
|
|||
|
|
/// </summary>
|
|||
|
|
public abstract class UIPage : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
[Header("Page Settings")]
|
|||
|
|
public string PageName;
|
|||
|
|
|
|||
|
|
// Events using System.Action instead of UnityEvents
|
|||
|
|
public event Action OnTransitionInStarted;
|
|||
|
|
public event Action OnTransitionInCompleted;
|
|||
|
|
public event Action OnTransitionOutStarted;
|
|||
|
|
public event Action OnTransitionOutCompleted;
|
|||
|
|
|
|||
|
|
// Default duration for transitions
|
|||
|
|
[SerializeField] protected float transitionDuration = 0.3f;
|
|||
|
|
|
|||
|
|
// State flags
|
|||
|
|
protected bool _isTransitioning = false;
|
|||
|
|
protected bool _isVisible = false;
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Called when the page is shown. Handles the transition in animation.
|
|||
|
|
/// </summary>
|
|||
|
|
public virtual void TransitionIn()
|
|||
|
|
{
|
|||
|
|
gameObject.SetActive(true);
|
|||
|
|
_isTransitioning = true;
|
|||
|
|
OnTransitionInStarted?.Invoke();
|
|||
|
|
|
|||
|
|
// Override in child classes for specific transition animations
|
|||
|
|
DoTransitionIn(() => {
|
|||
|
|
_isTransitioning = false;
|
|||
|
|
_isVisible = true;
|
|||
|
|
OnTransitionInCompleted?.Invoke();
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Called when the page is hidden. Handles the transition out animation.
|
|||
|
|
/// </summary>
|
|||
|
|
public virtual void TransitionOut()
|
|||
|
|
{
|
|||
|
|
_isTransitioning = true;
|
|||
|
|
OnTransitionOutStarted?.Invoke();
|
|||
|
|
|
|||
|
|
// Override in child classes for specific transition animations
|
|||
|
|
DoTransitionOut(() => {
|
|||
|
|
_isTransitioning = false;
|
|||
|
|
_isVisible = false;
|
|||
|
|
OnTransitionOutCompleted?.Invoke();
|
|||
|
|
gameObject.SetActive(false);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Called when the back button is pressed while this page is active.
|
|||
|
|
/// Default implementation pops the page from the stack.
|
|||
|
|
/// </summary>
|
|||
|
|
public virtual void OnBackPressed()
|
|||
|
|
{
|
|||
|
|
if (!_isTransitioning)
|
|||
|
|
{
|
|||
|
|
UIPageController.Instance.PopPage();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Implement transition in animation in child classes.
|
|||
|
|
/// </summary>
|
|||
|
|
protected virtual void DoTransitionIn(Action onComplete)
|
|||
|
|
{
|
|||
|
|
// Default implementation - instant transition
|
|||
|
|
onComplete?.Invoke();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// Implement transition out animation in child classes.
|
|||
|
|
/// </summary>
|
|||
|
|
protected virtual void DoTransitionOut(Action onComplete)
|
|||
|
|
{
|
|||
|
|
// Default implementation - instant transition
|
|||
|
|
onComplete?.Invoke();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|