I have a few editor scripts that make assets for me, but when I right-click and select my context menu item to create the asset I have no idea where to get the current project’s path from, so I end up making the asset in the root of the assets folder.
I was hoping there might be some method or static property to return me this - anyone solved this one?
i.e. I have a ScriptableObject for behaviours. I right click in the Project window to create a new behaviour - I’d like that behaviour to be created at the location I right-clicked.
You can use built-in property to generate a “create asset” menu
[CreateAssetMenu( menuName = "Wappen Asset/WaveBankData" )]
public class WaveBankData : ScriptableObject
{
And it will magically added to right click menu → Create. Has same functionality as Unity’s one. It will be created in current browser location, prompt for a rename, etc.
As a bonus
, here is how TextMesh pro determine current right-click folder. If you call Selection.assetGUIDs under MenuItem call back, it will guarantee current displaying folder (the one that you clicked on its empty space)
[MenuItem("Assets/Create/TextMeshPro/Color Gradient", false, 115)]
public static void CreateColorGradient(MenuCommand context)
{
string filePath;
if (Selection.assetGUIDs.Length == 0)
filePath = "Assets/New TMP Color Gradient.asset";
else
filePath = AssetDatabase.GUIDToAssetPath(Selection.assetGUIDs[0]);