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

  [csharp] view plain copy 在CODE上查看代码片派生到我的代码片

  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;

  Clip 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/";

  }

  }