152 lines
6.3 KiB
C#
152 lines
6.3 KiB
C#
using Pixelplacement;
|
|
using Pixelplacement.TweenSystem;
|
|
using UnityEngine;
|
|
using System;
|
|
|
|
namespace Minigames.StatueDressup.Utils
|
|
{
|
|
/// <summary>
|
|
/// Common animation utilities extracted from CardAnimator pattern.
|
|
/// Provides reusable tween animations for UI elements.
|
|
/// </summary>
|
|
public static class TweenAnimationUtility
|
|
{
|
|
#region Scale Animations
|
|
|
|
/// <summary>
|
|
/// Animate scale to target value with ease in-out
|
|
/// </summary>
|
|
public static TweenBase AnimateScale(Transform transform, Vector3 targetScale, float duration, Action onComplete = null)
|
|
{
|
|
return Tween.LocalScale(transform, targetScale, duration, 0f, Tween.EaseInOut, completeCallback: onComplete);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Pulse scale animation (scale up then back to original)
|
|
/// </summary>
|
|
public static void PulseScale(Transform transform, float pulseAmount = 1.1f, float duration = 0.2f, Action onComplete = null)
|
|
{
|
|
Vector3 originalScale = transform.localScale;
|
|
Vector3 pulseScale = originalScale * pulseAmount;
|
|
|
|
Tween.LocalScale(transform, pulseScale, duration, 0f, Tween.EaseOutBack,
|
|
completeCallback: () =>
|
|
{
|
|
Tween.LocalScale(transform, originalScale, duration, 0f, Tween.EaseInBack, completeCallback: onComplete);
|
|
});
|
|
}
|
|
|
|
/// <summary>
|
|
/// Pop-in animation (scale from 0 to target with overshoot)
|
|
/// </summary>
|
|
public static TweenBase PopIn(Transform transform, Vector3 targetScale, float duration = 0.5f, Action onComplete = null)
|
|
{
|
|
transform.localScale = Vector3.zero;
|
|
return Tween.LocalScale(transform, targetScale, duration, 0f, Tween.EaseOutBack, completeCallback: onComplete);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Pop-out animation (scale from current to 0)
|
|
/// </summary>
|
|
public static TweenBase PopOut(Transform transform, float duration = 0.3f, Action onComplete = null)
|
|
{
|
|
return Tween.LocalScale(transform, Vector3.zero, duration, 0f, Tween.EaseInBack, completeCallback: onComplete);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Smooth scale transition with bounce
|
|
/// </summary>
|
|
public static TweenBase ScaleWithBounce(Transform transform, Vector3 targetScale, float duration, Action onComplete = null)
|
|
{
|
|
return Tween.LocalScale(transform, targetScale, duration, 0f, Tween.EaseOutBack, completeCallback: onComplete);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Position Animations
|
|
|
|
/// <summary>
|
|
/// Animate anchored position (for RectTransform UI elements)
|
|
/// </summary>
|
|
public static TweenBase AnimateAnchoredPosition(RectTransform rectTransform, Vector2 targetPosition, float duration, Action onComplete = null)
|
|
{
|
|
return Tween.AnchoredPosition(rectTransform, targetPosition, duration, 0f, Tween.EaseInOut, completeCallback: onComplete);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Animate local position (for regular transforms)
|
|
/// </summary>
|
|
public static TweenBase AnimateLocalPosition(Transform transform, Vector3 targetPosition, float duration, Action onComplete = null)
|
|
{
|
|
return Tween.LocalPosition(transform, targetPosition, duration, 0f, Tween.EaseInOut, completeCallback: onComplete);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Move with bounce effect
|
|
/// </summary>
|
|
public static TweenBase MoveWithBounce(RectTransform rectTransform, Vector2 targetPosition, float duration, Action onComplete = null)
|
|
{
|
|
return Tween.AnchoredPosition(rectTransform, targetPosition, duration, 0f, Tween.EaseOutBack, completeCallback: onComplete);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Combined Hover Animations
|
|
|
|
/// <summary>
|
|
/// Hover enter animation (lift and scale) for RectTransform
|
|
/// </summary>
|
|
public static void HoverEnter(RectTransform rectTransform, Vector2 originalPosition, float liftAmount = 20f,
|
|
float scaleMultiplier = 1.05f, float duration = 0.2f, Action onComplete = null)
|
|
{
|
|
Vector2 targetPos = originalPosition + Vector2.up * liftAmount;
|
|
|
|
Tween.AnchoredPosition(rectTransform, targetPos, duration, 0f, Tween.EaseOutBack);
|
|
Tween.LocalScale(rectTransform, Vector3.one * scaleMultiplier, duration, 0f, Tween.EaseOutBack, completeCallback: onComplete);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Hover exit animation (return to original position and scale) for RectTransform
|
|
/// </summary>
|
|
public static void HoverExit(RectTransform rectTransform, Vector2 originalPosition, float duration = 0.2f, Action onComplete = null)
|
|
{
|
|
Tween.AnchoredPosition(rectTransform, originalPosition, duration, 0f, Tween.EaseInBack);
|
|
Tween.LocalScale(rectTransform, Vector3.one, duration, 0f, Tween.EaseInBack, completeCallback: onComplete);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Glow pulse effect (scale up/down repeatedly)
|
|
/// </summary>
|
|
public static TweenBase StartGlowPulse(Transform transform, float pulseAmount = 1.1f, float duration = 0.8f)
|
|
{
|
|
Vector3 originalScale = transform.localScale;
|
|
Vector3 pulseScale = originalScale * pulseAmount;
|
|
|
|
return Tween.LocalScale(transform, pulseScale, duration, 0f, Tween.EaseInOutSine, Tween.LoopType.PingPong);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Stop any active tweens on transform
|
|
/// </summary>
|
|
public static void StopTweens(Transform transform)
|
|
{
|
|
Tween.Cancel(transform.GetInstanceID());
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Fade Animations
|
|
|
|
/// <summary>
|
|
/// Fade CanvasGroup alpha
|
|
/// </summary>
|
|
public static TweenBase FadeCanvasGroup(CanvasGroup canvasGroup, float targetAlpha, float duration, Action onComplete = null)
|
|
{
|
|
return Tween.CanvasGroupAlpha(canvasGroup, targetAlpha, duration, 0f, Tween.EaseInOut, completeCallback: onComplete);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|