Created
January 10, 2021 21:34
-
-
Save garettbass/4088cccd5ae35a18fb5ed9d4193dcd02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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