码迷,mamicode.com
首页 > 编程语言 > 详细

unity fbx 导出动画

时间:2019-01-10 15:34:16      阅读:747      评论:0      收藏:0      [点我收藏+]

标签:index   delete   leo   pre   direct   serialize   setpath   tab   select   

public class ActionConvetTool
{
    [MenuItem("ActionTools/动作处理")]
    public static void ActionConvert()
    {
        UnityEngine.Object[] arr = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Unfiltered);
        for (int index = 0; index < arr.Length; index++)
        {
            string strFilePath = AssetDatabase.GetAssetPath(arr[index]);
            Debug.Log("filePath=" + strFilePath);

            ActionScriptable action = ScriptableObject.CreateInstance<ActionScriptable>();

            UnityEngine.Object[] objects = AssetDatabase.LoadAllAssetsAtPath(strFilePath);
            if (objects == null || objects.Length == 0)
            {
                return;
            }

            for (int i = 0; i < objects.Length; i++)
            {
                if (objects[i] is AnimationClip)
                {
                    action.aClip = objects[i] as AnimationClip;
                    string strSerializeFile = "Assets/Resources/Action/";
                    string strDir = Application.dataPath + "/Resources/Action";
                    if (!Directory.Exists(strDir))
                    {
                        Directory.CreateDirectory(strDir);
                    }
                    string strFileName = objects[i].name + ".asset";
                    string strFile = Application.dataPath + "/Resources/Action/" +strFileName;
                    if (File.Exists(strFile))
                    {
                        File.Delete(strFile);
                    }

                    AssetDatabase.CreateAsset(action, strSerializeFile+strFileName);

                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();

                    break;
                }
            }
        }
    }
}

注意事项:需要先选中fbx模型然后导出

unity fbx 导出动画

标签:index   delete   leo   pre   direct   serialize   setpath   tab   select   

原文地址:https://www.cnblogs.com/ylwn817/p/10249721.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!