Skip to content

Instantly share code, notes, and snippets.

@garettbass
Created January 10, 2021 21:34
Show Gist options
  • Save garettbass/4088cccd5ae35a18fb5ed9d4193dcd02 to your computer and use it in GitHub Desktop.
Save garettbass/4088cccd5ae35a18fb5ed9d4193dcd02 to your computer and use it in GitHub Desktop.
using UnityEditor;
using UnityEngine;
using UnityEditor.Animations;
using System.IO;
public class CreateBlendTreeAsset
{
[MenuItem("Assets/Create/Animation Blend Tree", priority = 402)]
private static void CreateBlendTree()
{
var directory = GetSelectedDirectory();
var asset = new BlendTree();
var path = Path.Combine(directory, "New Blend Tree.asset");
// display immedate rename prompt in the project window
ProjectWindowUtil.CreateAsset(asset, path);
}
private static string GetSelectedDirectory()
{
var activeObject = Selection.activeObject;
if (activeObject == null)
{ // nothing is selected in the project window
return "Assets";
}
var activePath = AssetDatabase.GetAssetPath(activeObject);
if (activeObject is DefaultAsset)
{ // a folder is selected in the project window
return activePath;
}
// an asset is selected in the project window
return Path.GetDirectoryName(activePath);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment