Make cards use settings
This commit is contained in:
committed by
Michal Pikulski
parent
4fdbbb0aa8
commit
a6471ede45
@@ -2,6 +2,8 @@
|
||||
using Pixelplacement.TweenSystem;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using AppleHills.Core.Settings;
|
||||
using Core;
|
||||
|
||||
namespace UI.CardSystem.StateMachine
|
||||
{
|
||||
@@ -12,16 +14,15 @@ namespace UI.CardSystem.StateMachine
|
||||
/// </summary>
|
||||
public class CardAnimator : MonoBehaviour
|
||||
{
|
||||
[Header("Animation Settings")]
|
||||
[SerializeField] private float defaultDuration = 0.3f;
|
||||
|
||||
private Transform _transform;
|
||||
private RectTransform _rectTransform;
|
||||
private ICardSystemSettings _settings;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_transform = transform;
|
||||
_rectTransform = GetComponent<RectTransform>();
|
||||
_settings = GameManager.GetSettingsObject<ICardSystemSettings>();
|
||||
}
|
||||
|
||||
#region Scale Animations
|
||||
@@ -31,7 +32,7 @@ namespace UI.CardSystem.StateMachine
|
||||
/// </summary>
|
||||
public TweenBase AnimateScale(Vector3 targetScale, float? duration = null, Action onComplete = null)
|
||||
{
|
||||
return Tween.LocalScale(_transform, targetScale, duration ?? defaultDuration, 0f,
|
||||
return Tween.LocalScale(_transform, targetScale, duration ?? _settings.DefaultAnimationDuration, 0f,
|
||||
Tween.EaseInOut, completeCallback: onComplete);
|
||||
}
|
||||
|
||||
@@ -85,7 +86,7 @@ namespace UI.CardSystem.StateMachine
|
||||
return null;
|
||||
}
|
||||
|
||||
return Tween.AnchoredPosition(_rectTransform, targetPosition, duration ?? defaultDuration, 0f,
|
||||
return Tween.AnchoredPosition(_rectTransform, targetPosition, duration ?? _settings.DefaultAnimationDuration, 0f,
|
||||
Tween.EaseInOut, completeCallback: onComplete);
|
||||
}
|
||||
|
||||
@@ -94,7 +95,7 @@ namespace UI.CardSystem.StateMachine
|
||||
/// </summary>
|
||||
public TweenBase AnimateLocalPosition(Vector3 targetPosition, float? duration = null, Action onComplete = null)
|
||||
{
|
||||
return Tween.LocalPosition(_transform, targetPosition, duration ?? defaultDuration, 0f,
|
||||
return Tween.LocalPosition(_transform, targetPosition, duration ?? _settings.DefaultAnimationDuration, 0f,
|
||||
Tween.EaseInOut, completeCallback: onComplete);
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ namespace UI.CardSystem.StateMachine
|
||||
/// </summary>
|
||||
public TweenBase AnimateLocalRotation(Quaternion targetRotation, float? duration = null, Action onComplete = null)
|
||||
{
|
||||
return Tween.LocalRotation(_transform, targetRotation, duration ?? defaultDuration, 0f,
|
||||
return Tween.LocalRotation(_transform, targetRotation, duration ?? _settings.DefaultAnimationDuration, 0f,
|
||||
Tween.EaseInOut, completeCallback: onComplete);
|
||||
}
|
||||
|
||||
@@ -129,17 +130,19 @@ namespace UI.CardSystem.StateMachine
|
||||
/// Play card flip animation - rotates card back from 0° to 90°, then card front from 180° to 0°
|
||||
/// Based on FlippableCard.FlipToReveal()
|
||||
/// </summary>
|
||||
public void PlayFlip(Transform cardBack, Transform cardFront, float duration = 0.6f, Action onComplete = null)
|
||||
public void PlayFlip(Transform cardBack, Transform cardFront, float? duration = null, Action onComplete = null)
|
||||
{
|
||||
float flipDuration = duration ?? _settings.FlipDuration;
|
||||
|
||||
// Phase 1: Rotate both to 90 degrees (edge view)
|
||||
if (cardBack != null)
|
||||
{
|
||||
Tween.LocalRotation(cardBack, Quaternion.Euler(0, 90, 0), duration * 0.5f, 0f, Tween.EaseInOut);
|
||||
Tween.LocalRotation(cardBack, Quaternion.Euler(0, 90, 0), flipDuration * 0.5f, 0f, Tween.EaseInOut);
|
||||
}
|
||||
|
||||
if (cardFront != null)
|
||||
{
|
||||
Tween.LocalRotation(cardFront, Quaternion.Euler(0, 90, 0), duration * 0.5f, 0f, Tween.EaseInOut,
|
||||
Tween.LocalRotation(cardFront, Quaternion.Euler(0, 90, 0), flipDuration * 0.5f, 0f, Tween.EaseInOut,
|
||||
completeCallback: () =>
|
||||
{
|
||||
// At edge (90°), switch visibility
|
||||
@@ -149,7 +152,7 @@ namespace UI.CardSystem.StateMachine
|
||||
cardFront.gameObject.SetActive(true);
|
||||
|
||||
// Phase 2: Rotate front from 90 to 0 (show at correct orientation)
|
||||
Tween.LocalRotation(cardFront, Quaternion.Euler(0, 0, 0), duration * 0.5f, 0f, Tween.EaseInOut,
|
||||
Tween.LocalRotation(cardFront, Quaternion.Euler(0, 0, 0), flipDuration * 0.5f, 0f, Tween.EaseInOut,
|
||||
completeCallback: onComplete);
|
||||
});
|
||||
}
|
||||
@@ -159,14 +162,16 @@ namespace UI.CardSystem.StateMachine
|
||||
/// Play scale punch during flip animation for extra juice
|
||||
/// Based on FlippableCard.FlipToReveal()
|
||||
/// </summary>
|
||||
public void PlayFlipScalePunch(float punchScale = 1.1f, float duration = 0.6f)
|
||||
public void PlayFlipScalePunch(float? punchScale = null, float? duration = null)
|
||||
{
|
||||
float punch = punchScale ?? _settings.FlipScalePunch;
|
||||
float flipDuration = duration ?? _settings.FlipDuration;
|
||||
Vector3 originalScale = _transform.localScale;
|
||||
|
||||
Tween.LocalScale(_transform, originalScale * punchScale, duration * 0.5f, 0f, Tween.EaseOutBack,
|
||||
Tween.LocalScale(_transform, originalScale * punch, flipDuration * 0.5f, 0f, Tween.EaseOutBack,
|
||||
completeCallback: () =>
|
||||
{
|
||||
Tween.LocalScale(_transform, originalScale, duration * 0.5f, 0f, Tween.EaseInBack);
|
||||
Tween.LocalScale(_transform, originalScale, flipDuration * 0.5f, 0f, Tween.EaseInBack);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -178,9 +183,12 @@ namespace UI.CardSystem.StateMachine
|
||||
/// Enlarge card to specified scale
|
||||
/// Based on FlippableCard.EnlargeCard() and AlbumCard.EnlargeCard()
|
||||
/// </summary>
|
||||
public void PlayEnlarge(float targetScale = 2.5f, float duration = 0.3f, Action onComplete = null)
|
||||
public void PlayEnlarge(float? targetScale = null, float? duration = null, Action onComplete = null)
|
||||
{
|
||||
Tween.LocalScale(_transform, Vector3.one * targetScale, duration, 0f, Tween.EaseOutBack,
|
||||
float scale = targetScale ?? _settings.NewCardEnlargedScale;
|
||||
float scaleDuration = duration ?? _settings.ScaleDuration;
|
||||
|
||||
Tween.LocalScale(_transform, Vector3.one * scale, scaleDuration, 0f, Tween.EaseOutBack,
|
||||
completeCallback: onComplete);
|
||||
}
|
||||
|
||||
@@ -188,9 +196,11 @@ namespace UI.CardSystem.StateMachine
|
||||
/// Shrink card back to original scale
|
||||
/// Based on AlbumCard.ShrinkCard() and FlippableCard.ReturnToNormalSize()
|
||||
/// </summary>
|
||||
public void PlayShrink(Vector3 targetScale, float duration = 0.3f, Action onComplete = null)
|
||||
public void PlayShrink(Vector3 targetScale, float? duration = null, Action onComplete = null)
|
||||
{
|
||||
Tween.LocalScale(_transform, targetScale, duration, 0f, Tween.EaseInBack,
|
||||
float scaleDuration = duration ?? _settings.ScaleDuration;
|
||||
|
||||
Tween.LocalScale(_transform, targetScale, scaleDuration, 0f, Tween.EaseInBack,
|
||||
completeCallback: onComplete);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user