public static void RestoreAnimation()
    {
        AssetDatabase.SaveAssets();
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        string path = AssetDatabase.GetAssetPath(Selection.activeObject);

        {
            string f           = path.Replace(_rootDirectory, _BackupDirectory).Replace(".fbx", ".asset");
            string fbxfilePath = f.Replace(_BackupDirectory, _rootDirectory).Replace(".asset", ".fbx.meta");
            if (System.IO.File.Exists(fbxfilePath))
            {
                using (System.IO.StreamReader reader = new System.IO.StreamReader(fbxfilePath)) {
                    string     line = reader.ReadLine();
                    AnimBackup ab   = AssetDatabase.LoadAssetAtPath(f, typeof(AnimBackup)) as AnimBackup;
                    string     name = null;
                    while (line != null)
                    {
                        if (name == null)                          // not enter animation config yet.
                        {
                            if (line.StartsWith(animStart))
                            {
                                // find an animtion.
                                name = line.Substring(animStart.Length);
                            }
                            sb.Append(line + '\n');
                        }
                        else
                        {
                            string content = line + '\n';
                            if (line.StartsWith(curveStart))
                            {
                                string c = ab.GetAnimationCurveData(name);
                                if (c != null)
                                {
                                    content = c;
                                }
                                name = null;
                            }
                            sb.Append(content);
                        }
                        line = reader.ReadLine();
                    }
                }
                using (System.IO.StreamWriter writer = new System.IO.StreamWriter(fbxfilePath)) {
                    writer.Write(sb.ToString());
                }
                sb.Remove(0, sb.Length);
            }
        }
        AssetDatabase.Refresh();
    }
 public static void BackupAnimation()
 {
     AssetDatabase.SaveAssets();
     string [] files = System.IO.Directory.GetFiles(_rootDirectory);
     foreach (string f in files)
     {
         // look for meta file of animation file to get curver information.
         if (f.EndsWith(".fbx.meta"))
         {
             System.Collections.Generic.List <AnimBackup.AnimBackupData> curveData =
                 new System.Collections.Generic.List <AnimBackup.AnimBackupData>();
             // read every lines to find animation.
             using (System.IO.StreamReader reader = new System.IO.StreamReader(f)) {
                 string line = reader.ReadLine();
                 AnimBackup.AnimBackupData data = null;
                 bool reachCurve = false;
                 while (line != null)
                 {
                     if (data == null)
                     {
                         // find animation beginning.
                         if (line.StartsWith(animStart))
                         {
                             data       = new AnimBackup.AnimBackupData();
                             data._name = line.Substring(animStart.Length);
                         }
                     }
                     else
                     {
                         if (reachCurve)
                         {
                             bool written = false;
                             foreach (string v in curveDataStart)
                             {
                                 if (line.StartsWith(v))
                                 {
                                     // write data.
                                     data._curve += line + '\n';
                                     written      = true;
                                     break;
                                 }
                             }
                             // reach end of curve data, break.
                             if (!written)
                             {
                                 curveData.Add(data);
                                 reachCurve = false;
                                 data       = null;
                             }
                         }
                         else
                         {
                             // found curve data start.
                             if (line.StartsWith(curveStart))
                             {
                                 reachCurve  = true;
                                 data._curve = line + '\n';
                             }
                         }
                     }
                     line = reader.ReadLine();
                 }
             }
             // save backup.
             AnimBackup ab = ScriptableObject.CreateInstance <AnimBackup>();
             ab._data = curveData.ToArray();
             AssetDatabase.CreateAsset(ab, _BackupDirectory + f.Replace(_rootDirectory, "").Replace("fbx.meta", "asset"));
         }
     }
     AssetDatabase.Refresh();
 }