コガネブログ

平日更新を目標にUnityやC#、Visual Studioなどのゲーム開発アレコレを書いていきます

【Unity】AnimatorStateTransition の Has Exit Time や Transition Duration を一括で false や 0 に設定するエディタ拡張の例

ソースコード

using System.IO;
using System.Linq;
using UnityEditor;
using UnityEditor.Animations;

public static class ExampleClass
{
    [MenuItem( "Tools/Example" )]
    private static void Example()
    {
        var path = "【ここに該当ファイルが存在するフォルダのパスを入力】";

        var transitions = Directory
            .GetFiles  ( path, "*", SearchOption.AllDirectories )
            .Select    ( c => AssetDatabase.LoadAssetAtPath<AnimatorController>( c ) )
            .Where     ( c => c != null )
            .SelectMany( c => c.layers )
            .Select    ( c => c.stateMachine )
            .SelectMany( c => c.states )
            .SelectMany( c => c.state.transitions )
        ;

        foreach ( var n in transitions )
        {
            n.hasExitTime   = false ;
            n.exitTime      = 0     ;
            n.duration      = 0     ;
        }

        AssetDatabase.SaveAssets();
    }
}