Skip to content

Instantly share code, notes, and snippets.

@noisecrime
Created July 16, 2014 15:53
Show Gist options
  • Save noisecrime/5e928eedc003b91bbf80 to your computer and use it in GitHub Desktop.
Save noisecrime/5e928eedc003b91bbf80 to your computer and use it in GitHub Desktop.
Simple editor script to duplicate animation clips found in the selected model/animation asset file. Duplicates unlike original animation clips may be edited.
// NoiseCrime Gist
// 2014.07.16
// Unity Version: 3.5.7+
// Simple editor script to duplicate animation clips found in the selected model/animation asset file.
// Duplicates unlike original animation clips may be edited.
using UnityEngine;
using UnityEditor;
public class Editor_DuplicateAnimationAsset : EditorWindow
{
[MenuItem("Assets/Duplicate Animation Assets (NoiseCrime)")]
static void DoCreateAnimationAssets()
{
if (Selection.activeGameObject.GetComponent<Animation>() != null)
{
// Validate Folder Exists
if( !System.IO.Directory.Exists(Application.dataPath + "/DuplicatedAnimationClips"))
{
AssetDatabase.CreateFolder("Assets", "DuplicatedAnimationClips");
}
Animation anim = Selection.activeGameObject.GetComponent<Animation>();
foreach (AnimationState sourceClip in anim)
{
#if UNITY_4_3
AnimationClip newClip = new AnimationClip();
EditorUtility.CopySerialized(sourceClip.clip, newClip);
AssetDatabase.CreateAsset(newClip, string.Format("Assets/DuplicatedAnimationClips/{0}_dup.anim", sourceClip.name));
#else
// Unity 3.5.7
AssetDatabase.CreateAsset(sourceClip.clip, string.Format("Assets/DuplicatedAnimationClips/{0}_dup.anim", sourceClip.name));
#endif
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment