EasyAnim
Coding Style wiki
EasyAnim is the abstract base class of a simple animation playback wrapper (play + end callback). Its implementations are EasyAnimation (legacy Animation system) and EasyAnimator (Animator). Play animations through the unified Play(name, animEnd) interface, and the end callback runs when the AnimEnd animation event fires.
| Namespace | OxGKit.Utilities.EasyAnim |
| Type | public abstract class EasyAnim : MonoBehaviour, public class EasyAnimation : EasyAnim, public class EasyAnimator : EasyAnim |
| Source | EasyAnim.cs, EasyAnimation.cs, EasyAnimator.cs |
using OxGKit.Utilities.EasyAnim;
Important You must set an animation event named AnimEnd on the animation clip; the animEnd callback fires only when playback reaches that event. Without the event, the callback never fires — this is the first thing to check when "the animation callback doesn't run".
Quick Start
using OxGKit.Utilities.EasyAnim;
using UnityEngine;
public class EasyAnimDemo : MonoBehaviour
{
private void Start()
{
// Get the EasyAnim (EasyAnimation or EasyAnimator)
var easyAnim = this.GetComponent<EasyAnim>();
// EasyAnimation takes a clip name; EasyAnimator takes a Trigger parameter name
easyAnim.Play("Open", () =>
{
Debug.Log("Animation End");
});
// Check whether the animation exists
bool hasAnim = easyAnim.HasAnim("Open");
}
}
General Rules
The AnimEnd Animation Event
- Select the animation clip in the Animation window.
- Add an Animation Event at the last frame (or wherever the callback should fire).
- Set the Function name to
AnimEnd(matching theprotected virtual void AnimEnd()event function on theEasyAnimbase class).
Fail-Open Behavior
- If
Playcannot find the given clip name (EasyAnimation) or parameter name (EasyAnimator), it callsAnimEnddirectly, firing the callback immediately (so the flow never stalls).
Reminder Each Play overwrites the previously set end callback; the callback is cleared after it fires (one-shot).
EasyAnim (Base)
Method Overview
| Method | Description |
|---|---|
| Play | (abstract) Plays an animation and sets the end callback. |
| HasAnim | (abstract) Checks whether the given animation exists. |
Play
public abstract void Play(string name, Action animEnd)
Plays the animation with the given name and sets the end callback (triggered by the AnimEnd animation event).
HasAnim
public abstract bool HasAnim(string name)
Checks whether an animation with the given name exists.
EasyAnimation
For the legacy Animation system. Add via AddComponentMenu: OxGKit/Utilities/EasyAnim/EasyAnimation; the Animation component can be assigned in the Inspector, otherwise Awake finds it via GetComponent.
GetAnimation
public Animation GetAnimation()
Gets the bound Animation component.
Play (EasyAnimation)
public override void Play(string animName, Action animEnd)
Plays a clip by its clip name (Animation.Play); if the clip is not found, the callback fires immediately.
HasAnim (EasyAnimation)
public override bool HasAnim(string animName)
Checks whether the Animation contains a clip with the given name (GetClip).
EasyAnimator
For Animator. Add via AddComponentMenu: OxGKit/Utilities/EasyAnim/EasyAnimator; the Animator component can be assigned in the Inspector, otherwise Awake finds it via GetComponent.
GetAnimation (EasyAnimator)
public Animator GetAnimation()
Gets the bound Animator component (the method is named GetAnimation but returns Animator).
Play (EasyAnimator)
public override void Play(string paramName, Action animEnd)
Plays via a Trigger parameter name (ResetTrigger first, then SetTrigger); if the parameter is not found, the callback fires immediately.
Attention paramName must be a Trigger parameter name in the Animator Controller (not a State or Clip name).
HasAnim (EasyAnimator)
public override bool HasAnim(string paramName)
Checks whether the Animator parameter list contains a parameter with the given name (with an internal parameter cache optimization; re-cached when the controller changes).