Skip to content

Instantly share code, notes, and snippets.

@attilam
Created December 6, 2018 19:37
Show Gist options
  • Save attilam/f9e6f15f780b48769bfd20716429c483 to your computer and use it in GitHub Desktop.
Save attilam/f9e6f15f780b48769bfd20716429c483 to your computer and use it in GitHub Desktop.
Create Legacy AnimationClips using the Asset Menu in Unity
using System.IO;
using UnityEditor;
using UnityEngine;
public class CreateLegacyAnimationClip {
[MenuItem("Assets/Create/Animation (Legacy)", false, 402)]
public static void CreateIt()
{
AnimationClip clip = new AnimationClip();
clip.legacy = true;
// via https://forum.unity.com/threads/how-to-get-currently-selected-folder-for-putting-new-asset-into.81359/
string path = "Assets";
foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
{
path = AssetDatabase.GetAssetPath(obj);
if (File.Exists(path))
{
path = Path.GetDirectoryName(path);
}
break;
}
AssetDatabase.CreateAsset(clip, path+"/New Legacy Animation.anim");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment