Use built-in property
If your asset is simple and doesn't need special treatment, you should 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.
Via MenuItem callback
If you really want to use customized MenuItem. Here is how TextMesh pro determine current right-click folder. If you call Selection.assetGUIDs
under MenuItem callback, it will guarantee current displaying folder (the one that you clicked on its empty space)
For full script, see your own \Packages\com.unity.textmeshpro\Scripts\Editor\TMP_ColorGradientAssetMenu.cs
[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]);
(BONUS) The TRUE Project browser current directory
Is hidden inside internal unity ProjectWindowUtil.TryGetActiveFolderPath
static function and needs reflector to access it. If you are coder wiz and really want to have it, here it is. (For non coder, I wont explain this, please do C# research on your own)
using UnityEngine;
using UnityEditor;
using System.Reflection;
// Define this function somewhere in your editor class to make a shortcut to said hidden function
private static bool TryGetActiveFolderPath( out string path )
{
var _tryGetActiveFolderPath = typeof(ProjectWindowUtil).GetMethod( "TryGetActiveFolderPath", BindingFlags.Static | BindingFlags.NonPublic );
object[] args = new object[] { null };
bool found = (bool)_tryGetActiveFolderPath.Invoke( null, args );
path = (string)args[0];
return found;
}
Note: tested in Unity 2019.4.19f