Skip to content

Instantly share code, notes, and snippets.

@mitay-walle
Created June 24, 2024 23:04
Show Gist options
  • Save mitay-walle/d905fcdf0cd35c8bf6544ef19adc7cf3 to your computer and use it in GitHub Desktop.
Save mitay-walle/d905fcdf0cd35c8bf6544ef19adc7cf3 to your computer and use it in GitHub Desktop.
Unity3d MenuItem to create Blend Tree asset
using System.Reflection;
using UnityEditor;
using UnityEditor.Animations;
namespace Plugins.Editor
{
public static class MenuItems
{
[MenuItem("Assets/Create/Blend Tree")]
private static void CreateBlendTree()
{
var asset = new BlendTree();
MethodInfo _tryGetActiveFolderPath = typeof(ProjectWindowUtil).GetMethod("TryGetActiveFolderPath", BindingFlags.Static | BindingFlags.NonPublic);
object[] args = new object[] { null };
bool found = (bool)_tryGetActiveFolderPath.Invoke(null, args);
string path = (string)args[0];
if (found)
{
path += "/" + $"{ObjectNames.GetUniqueName(new[] { "NewBlendTree" }, "NewBlendTree")}.asset";
AssetDatabase.CreateAsset(asset, path);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment