unity从模型中抽取动画文件(animation)

http://www.cnblogs.com/leng-yuye/archive/2013/01/11/2856144.html

由于模型是由第三方的软件制作的,用unity不能直接编辑模型里的动画文件(read-ony),比如为动画绑定事件,所以要把模型中的动画文件抽取出来,这样文件是可写的了。抽取动画文件的脚本非本人所写,贴在此处大家分享。---unity3d

using UnityEditor;
using UnityEngine;
using System.IO;

public class CurvesTransferer
{
    [MenuItem("Character Generator/Transfer Clip Curves to Copy")]
    static void CopyClip()
    {
        foreach (Object o in Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets))
        {
            if (!(o is GameObject)) continue;
            if (!o.name.Contains("@")) continue;
            GameObject animationFBX = (GameObject)o;

            AnimationClip srcClip = animationFBX.animation.clip;
            AnimationClip newClip = new AnimationClip();
            newClip.name = srcClip.name;

            // Create directory to store generated materials.
            if (!Directory.Exists(AnimationsPath(animationFBX)))
                Directory.CreateDirectory(AnimationsPath(animationFBX));

            string animationPath = AnimationsPath(animationFBX) + newClip.name + ".anim";

            AssetDatabase.CreateAsset(newClip, animationPath);
            AssetDatabase.Refresh();

            AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(srcClip, true);
            for (int i = 0; i < curveDatas.Length; i++)
            {
                AnimationUtility.SetEditorCurve(newClip, curveDatas[i].path, curveDatas[i].type, curveDatas[i].propertyName, curveDatas[i].curve);
            }
        }
    }

    // Returns the path to the directory that holds the specified FBX.
    static string CharacterRoot(GameObject character)
    {
        string root = AssetDatabase.GetAssetPath(character);
        return root.Substring(0, root.LastIndexOf('/') + 1);
    }

    // Returns the path to the directory that holds materials generated
    // for the specified FBX.
    public static string AnimationsPath(GameObject character)
    {
        return CharacterRoot(character) + "Copy Animations/";
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值