Created
June 12, 2012 10:20
-
-
Save smakhtin/2916758 to your computer and use it in GitHub Desktop.
Create a copy of read-only mesh animation in Unity (by neodrop)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEditor; | |
using UnityEngine; | |
public class CurvesTransferer | |
{ | |
const string duplicatePostfix = "_copy"; | |
static void CopyClip(string importedPath, string copyPath) | |
{ | |
AnimationClip src = AssetDatabase.LoadAssetAtPath(importedPath, typeof(AnimationClip)) as AnimationClip; | |
AnimationClip newClip = new AnimationClip(); | |
newClip.name = src.name + duplicatePostfix; | |
AssetDatabase.CreateAsset(newClip, copyPath); | |
AssetDatabase.Refresh(); | |
} | |
[MenuItem("Assets/Transfer Clip Curves to Copy")] | |
static void CopyCurvesToDuplicate() | |
{ | |
// Get selected AnimationClip | |
AnimationClip imported = Selection.activeObject as AnimationClip; | |
if (imported == null) | |
{ | |
Debug.Log("Selected object is not an AnimationClip"); | |
return; | |
} | |
// Find path of copy | |
string importedPath = AssetDatabase.GetAssetPath(imported); | |
string copyPath = importedPath.Substring(0, importedPath.LastIndexOf("/")); | |
copyPath += "/" + imported.name + duplicatePostfix + ".anim"; | |
CopyClip(importedPath, copyPath); | |
AnimationClip copy = AssetDatabase.LoadAssetAtPath(copyPath, typeof(AnimationClip)) as AnimationClip; | |
if (copy == null) | |
{ | |
Debug.Log("No copy found at " + copyPath); | |
return; | |
} | |
// Copy curves from imported to copy | |
AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(imported, true); | |
for (int i = 0; i < curveDatas.Length; i++) | |
{ | |
AnimationUtility.SetEditorCurve( | |
copy, | |
curveDatas[i].path, | |
curveDatas[i].type, | |
curveDatas[i].propertyName, | |
curveDatas[i].curve | |
); | |
} | |
Debug.Log("Copying curves into " + copy.name + " is done"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment