赞
踩
- public class TestSaveSprite
- {
- [MenuItem("Tools/导出AnimationClip")]
- public static void AnimationClipsCopy()
- {
- Object[] go = Selection.objects;
-
- string Path = AssetDatabase.GetAssetPath(go[0]);
-
- string parentPath = getParentPathForAsset(Path);
-
- for (int i = 0; i < go.Length; i++)
- {
- string fbxPath = AssetDatabase.GetAssetPath(go[i]);
-
- AnimCopy(fbxPath, parentPath,string.Format("{0}Clone",go[i].name));
- }
- }
-
- /// <summary>
- /// 返回传入目录的父目录(相对于asset)
- /// </summary>
- /// <param name="assetPath"></param>
- /// <returns></returns>
- public static string getParentPathForAsset(string assetPath)
- {
- string[] pathName = assetPath.Split('/');
- string parentPath = "";
-
- if (pathName.Length < 2 || pathName[pathName.Length - 1] == "")
- {
- Debug.Log(assetPath + @"没有父目录!");
- return parentPath;
- }
-
- for (int i = 0; i < pathName.Length - 1; i++)
- {
-
- if (i != pathName.Length - 2) parentPath += pathName[i] + @"/";
- else
- parentPath += pathName[i];
- }
-
- return parentPath;
- }
- static void AnimCopy(string fbxPath, string parentPath, string name)
- {
- Object[] objs = AssetDatabase.LoadAllAssetsAtPath(fbxPath);
-
- string animationPath = "";
-
- AnimationClipSettings setting;
-
- AnimationClip srcClip;//源AnimationClip
-
- AnimationClip newClip;//新AnimationClip
-
- foreach (Object o in objs)
- {
- if (o.GetType() == typeof(AnimationClip))
- {
- srcClip = o as AnimationClip;
-
- newClip = new AnimationClip();
-
- newClip.name = srcClip.name;//设置新clip的名字
-
- if (!Directory.Exists(parentPath + @"/copy/"))
-
- Directory.CreateDirectory(parentPath + @"/copy/");
-
- animationPath = parentPath + @"/copy/" + newClip.name + ".anim";
-
- setting = AnimationUtility.GetAnimationClipSettings(srcClip);//获取AnimationClipSettings
-
- AnimationUtility.SetAnimationClipSettings(newClip, setting);//设置新clip的AnimationClipSettings
-
- newClip.frameRate = srcClip.frameRate;//设置新clip的帧率
-
- EditorCurveBinding[] curveBindings = AnimationUtility.GetCurveBindings(srcClip);//获取clip的curveBinds
-
- for (int i = 0; i < curveBindings.Length; i++)
- {
- AnimationUtility.SetEditorCurve(newClip, curveBindings[i], AnimationUtility.GetEditorCurve(srcClip, curveBindings[i]));//设置新clip的curve
- }
-
- AssetDatabase.CreateAsset(newClip, animationPath); //AssetDatabase中的路径都是相对Asset的 如果指定路径已存在asset则会被删除,然后创建新的asset
-
- AssetDatabase.SaveAssets();//保存修改
-
- AssetDatabase.Refresh();
- }
- }
- }
- }

Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。