Unity FBX model animation extraction

      The character has been humanoid, so its animation can be used on other models, that is, it can share a set of model animations, but have you found that the animation is tied to the fbx model? It doesn’t matter you can Select these animation files and press Contrl+D to extract them, and then you can delete the entire fbx model. The newly generated animation is no longer based on fbx, which can greatly reduce the resource size.

using UnityEngine;
using UnityEditor;
using System.Collections;
using System.IO;
 
public class AnimationClipTool
{
    [MenuItem("AnimationClip/GetFilteredtoAnim &1", true)]
    static bool NotGetFiltered()
    {
        return Selection.activeObject;
    }
 
    [MenuItem("AnimationClip/GetFilteredtoAnim &1")]
    static void GetFiltered()
    {
        string targetPath = Application.dataPath + "/AnimationClip";
        if (!Directory.Exists(targetPath))
        {
            Directory.CreateDirectory(targetPath);
        }
        Object[] SelectionAsset = Selection.GetFiltered(typeof(Object), SelectionMode.Unfiltered);
        Debug.Log(SelectionAsset.Length);
        foreach (Object Asset in SelectionAsset)
        {
            AnimationClip newClip = new AnimationClip();
            EditorUtility.CopySerialized(Asset, newClip);
            AssetDatabase.CreateAsset(newClip, "Assets/AnimationClip/" + Asset.name + ".anim");
        }
        AssetDatabase.Refresh();
    }
}

  Select the animation clip, click the AnimationClip/GetFilteredtoAnim option on the menu bar (shortcut ALT+1), the animation clip generated by the code will appear in the Assets/AnimationClip folder

      (If you select other resource files instead of animation clips, Source and Destination Types do not match error will appear)

Guess you like

Origin blog.csdn.net/sun124608666/article/details/112239183