1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AnimatorControllerの中のステートを調べる

Posted at

エディタ限定です。ビルドではできない模様。
話を簡単にするためnullチェックとかは省略します。

まずエディタにおけるAnimatorControllerを取得。

// こいつが調べたいAnimatorとします。
Aniamtor animator = GetComponent<Animator>();

// エディタ用のAnimatorControllerにキャスト
var controller = animator.runtimeAnimatorController as UnityEditor.Animations.AnimatorController;

中に含まれるレイヤーごとにステートを列挙します。

// レイヤーごと
foreach (UnityEditor.Animations.AnimatorControllerLayer layer in controller.layers) {
    var states = layer?.stateMachine?.states;

    // ステートを列挙
    foreach (var state in states) {
        var clip = state.state?.motion as AnimationClip;
        if (clip == null) { // BlendTreeの可能性がある
            continue;
        }
    }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?