Files
DeviantMobile-Rohan/Assets/Scripts/SpecialMoveCardSystem/SpecialAnimationBridge.cs

61 lines
1.9 KiB
C#

using UnityEngine;
namespace SpecialMoveCards
{
/// <summary>
/// Decouples PlayerPocket from AnimationManager or direct Animator usage.
/// Prefers AnimationManager if present, else falls back to Animator trigger/state.
/// </summary>
[RequireComponent(typeof(Animator))]
public class SpecialAnimationBridge : MonoBehaviour
{
private AnimationManager animManager; // existing class in project
private Animator animator;
private void Awake()
{
animator = GetComponent<Animator>();
animManager = GetComponent<AnimationManager>();
}
/// <summary>
/// Play a special move by animation trigger/state name.
/// </summary>
public void PlaySpecialMove(string triggerOrState)
{
if (string.IsNullOrEmpty(triggerOrState))
{
Debug.LogWarning("PlaySpecialMove called with empty name");
return;
}
if (animManager != null)
{
// AnimationManager will CrossFade by clip/state name
animManager.PlayAnimation(triggerOrState);
return;
}
// Fallback: try to SetTrigger if such a parameter exists. Else CrossFade.
if (animator == null) return;
int paramCount = animator.parameterCount;
bool hasTrigger = false;
for (int i = 0; i < paramCount; i++)
{
var p = animator.GetParameter(i);
if (p.type == AnimatorControllerParameterType.Trigger && p.name == triggerOrState)
{
hasTrigger = true;
break;
}
}
if (hasTrigger)
animator.SetTrigger(triggerOrState);
else
animator.CrossFade(triggerOrState, 0.1f, 0, 0);
}
}
}