LoginSignup
9
9

More than 5 years have passed since last update.

fbxファイルからAnimationClipを取得する

Posted at

fbxファイルからAnimationClip取得する方法がググっても見付けきれなかったのですが
以下のように取得対象のfbxファイルのみをLoadした状態にして、FindObjectsOfTypeAllで取り出すという
力技で取得することができた。(もっとスマートな方法があるのかも...)

public List<AnimationClip> GetAnimationClipInFbx(string iFbxFileName)
{
    // 現在のLoad中のAnimationClipをUnloadし、何もLoadしていない状態にする
    Resources.FindObjectsOfTypeAll<AnimationClip>().ToList().ForEach(x => Resources.UnloadAsset(x));

    // AnimationClipを取り出したいFbxファイルをLoadする
    string aFbxFilePath = Application.dataPath + "/Resources/Models/" + iFbxFileName;
    aFbxFilePath = aFbxFilePath.Replace(".fbx", "").Replace("\\", "/");
    Resources.LoadAll(aFbxFilePath);

    // 現在のLoad中のみのAnimationClipを返す
    var aAnimationClips = Resources.FindObjectsOfTypeAll<AnimationClip>();

    List<AnimationClip> aAnimationClipList = new List<AnimationClip>();
    foreach (var aAnimationClip in aAnimationClips)
    {
        if (Regex.IsMatch(aAnimationClip.name, @"^Take\d*"))
        {
            aAnimationClipList.Add(aAnimationClip);
        }
    }
    return aAnimationClipList;
}
9
9
1

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
9
9