Skip to content

Instantly share code, notes, and snippets.

@BeautyfullCastle
Created November 12, 2019 09:50
Show Gist options
  • Save BeautyfullCastle/321f83a24b0af52abffee5abd0008583 to your computer and use it in GitHub Desktop.
Save BeautyfullCastle/321f83a24b0af52abffee5abd0008583 to your computer and use it in GitHub Desktop.
Copy clip assets from selected multiple model assets. Select assets and right click and find menu Model/Duplicate animation assets. Hotkey is Alt+D.
using System.IO;
using UnityEditor;
using UnityEngine;
namespace Assets.Editor
{
public class AnimAssetDuplicator
{
[MenuItem("Assets/Model/Duplicate Animation Assets &d")]
public static void DuplicateAnimationAssetsInThisFolder()
{
foreach (var gameObject in Selection.gameObjects)
{
string path = AssetDatabase.GetAssetPath(gameObject);
Object[] objects = AssetDatabase.LoadAllAssetsAtPath(path);
foreach (Object obj in objects)
{
DuplicateAnimationClip(obj as AnimationClip);
}
}
}
private static void DuplicateAnimationClip(AnimationClip sourceClip)
{
if (sourceClip != null && !sourceClip.empty && !sourceClip.name.Contains("preview"))
{
string path = AssetDatabase.GetAssetPath(sourceClip);
path = Path.Combine(Path.GetDirectoryName(path), sourceClip.name) + ".anim";
string newPath = AssetDatabase.GenerateUniqueAssetPath(path);
AnimationClip newClip = new AnimationClip();
EditorUtility.CopySerialized(sourceClip, newClip);
AssetDatabase.CreateAsset(newClip, newPath);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment