http://www.cnblogs.com/leng-yuye/archive/2013/01/11/2856144.html
由于模型是由第三方的软件制作的,用unity不能直接编辑模型里的动画文件(read-ony),比如为动画绑定事件,所以要把模型中的动画文件抽取出来,这样文件是可写的了。
usingUnityEditor;
usingUnityEngine;
usingSystem.IO;
publicclassCurvesTransferer
{
[MenuItem("Character Generator/Transfer Clip Curves to Copy")]
staticvoidCopyClip()
{
foreach(Object oinSelection.GetFiltered(typeof(Object), SelectionMode.DeepAssets))
{
if(!(oisGameObject))continue;
if(!o.name.Contains("@"))continue;
GameObject animationFBX = (GameObject)o;
AnimationClip srcClip = animationFBX.animation.clip;
AnimationClip newClip =newAnimationClip();
newClip.name = srcClip.name;
// Create directory to store generated materials.
if(!Directory.Exists(AnimationsPath(animationFBX)))
Directory.CreateDirectory(AnimationsPath(animationFBX));
stringanimationPath = AnimationsPath(animationFBX) + newClip.name +".anim";
AssetDatabase.CreateAsset(newClip, animationPath);
AssetDatabase.Refresh();
AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(srcClip,true);
for(inti = 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.
staticstringCharacterRoot(GameObject character)
{
stringroot = AssetDatabase.GetAssetPath(character);
returnroot.Substring(0, root.LastIndexOf('/') + 1);
}
// Returns the path to the directory that holds materials generated
// for the specified FBX.
publicstaticstringAnimationsPath(GameObject character)
{
returnCharacterRoot(character) +"Copy Animations/";
}
}
文章转载,如有侵权请小窗。
网友评论