はじめに
「Unity Forge Anim Callbacks」を Unity プロジェクトに導入することで
Animator や Animation でコールバックを簡単に実装できるようになります
使用例
Animator
using UnityEngine; using UnityForge.AnimCallbacks; public class Example : MonoBehaviour { [SerializeField] private Animator animator; [SerializeField] private int layerIndex; [SerializeField] private string clipName; private void Start() { animator.AddClipStartCallback( layerIndex, clipName, () => print( "開始" ) ); animator.AddClipEndCallback( layerIndex, clipName, () => print( "終了" ) ); animator.AddClipCallback( layerIndex, clipName, 0.5f, () => print( "0.5 秒後" ) ); } }
Animation
using UnityEngine; using UnityForge.AnimCallbacks; public class Example : MonoBehaviour { [SerializeField] private Animation animation; [SerializeField] private string clipName; private void Start() { animation.AddClipStartCallback( clipName, () => print( "開始" ) ); animation.AddClipEndCallback( clipName, () => print( "終了" ) ); animation.AddClipCallback( clipName, 0.5f, () => print( "0.5 秒後" ) ); animation.Play( clipName ); } }