Finalize nice animations
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using Core.SaveLoad;
|
||||
using UnityEngine;
|
||||
using AppleHills.Core.Settings;
|
||||
using Pixelplacement;
|
||||
|
||||
namespace UI.CardSystem.StateMachine.States
|
||||
{
|
||||
@@ -17,6 +18,7 @@ namespace UI.CardSystem.StateMachine.States
|
||||
private Transform _originalParent;
|
||||
private Vector3 _originalLocalPosition;
|
||||
private Quaternion _originalLocalRotation;
|
||||
private Vector3 _originalWorldPosition;
|
||||
|
||||
// Events for page to manage backdrop and reparenting
|
||||
public event System.Action<CardAlbumEnlargedState> OnEnlargeRequested;
|
||||
@@ -42,14 +44,18 @@ namespace UI.CardSystem.StateMachine.States
|
||||
_originalParent = _context.RootTransform.parent;
|
||||
_originalLocalPosition = _context.RootTransform.localPosition;
|
||||
_originalLocalRotation = _context.RootTransform.localRotation;
|
||||
_originalWorldPosition = _context.RootTransform.position;
|
||||
|
||||
// Notify page to show backdrop and reparent card to top layer
|
||||
// Notify page to show backdrop and reparent card to top layer (preserve world transform)
|
||||
OnEnlargeRequested?.Invoke(this);
|
||||
|
||||
// Enlarge the card using album scale setting
|
||||
// Animate into center and scale up significantly
|
||||
if (_context.Animator != null)
|
||||
{
|
||||
_context.Animator.PlayEnlarge(_settings.AlbumCardEnlargedScale);
|
||||
// Move to center of enlarged container (assumes zero is centered)
|
||||
_context.Animator.AnimateLocalPosition(Vector3.zero, _settings.ScaleDuration);
|
||||
// Enlarge using settings-controlled scale
|
||||
_context.Animator.PlayEnlarge(_settings.AlbumCardEnlargedScale, _settings.ScaleDuration);
|
||||
}
|
||||
|
||||
Logging.Debug($"[CardAlbumEnlargedState] Card enlarged from album: {_context.CardData?.Name}");
|
||||
@@ -57,22 +63,38 @@ namespace UI.CardSystem.StateMachine.States
|
||||
|
||||
public void OnCardClicked(CardContext context)
|
||||
{
|
||||
// Click to shrink back
|
||||
// Click to shrink back (play reverse of opening animation)
|
||||
Logging.Debug($"[CardAlbumEnlargedState] Card clicked while enlarged, shrinking back");
|
||||
|
||||
// Notify page to prepare for shrink
|
||||
// Ask page to hide backdrop (state will handle moving back & reparenting)
|
||||
OnShrinkRequested?.Invoke(this);
|
||||
|
||||
// Shrink animation, then transition back
|
||||
// Animate back to original world position + shrink to original scale
|
||||
float duration = _settings.ScaleDuration;
|
||||
|
||||
// Move using world-space tween so we land exactly on the original position
|
||||
Tween.Position(context.RootTransform, _originalWorldPosition, duration, 0f, Tween.EaseInOut);
|
||||
|
||||
if (context.Animator != null)
|
||||
{
|
||||
context.Animator.PlayShrink(_originalScale, onComplete: () =>
|
||||
context.Animator.PlayShrink(_originalScale, duration, onComplete: () =>
|
||||
{
|
||||
// Reparent back to original hierarchy and restore local transform
|
||||
context.RootTransform.SetParent(_originalParent, true);
|
||||
context.RootTransform.localPosition = _originalLocalPosition;
|
||||
context.RootTransform.localRotation = _originalLocalRotation;
|
||||
|
||||
// Transition back to placed state
|
||||
context.StateMachine.ChangeState("PlacedInSlotState");
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback if no animator: snap back
|
||||
context.RootTransform.position = _originalWorldPosition;
|
||||
context.RootTransform.SetParent(_originalParent, true);
|
||||
context.RootTransform.localPosition = _originalLocalPosition;
|
||||
context.RootTransform.localRotation = _originalLocalRotation;
|
||||
context.StateMachine.ChangeState("PlacedInSlotState");
|
||||
}
|
||||
}
|
||||
@@ -102,4 +124,3 @@ namespace UI.CardSystem.StateMachine.States
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user