# Getting path of right click in unity 3D editor

I want to create an extension for the Unity 3D Editor and have an custom asset type. During the process of creation this I recognized that I would improve the UX/usability if I can specify the path where I want to create the asset by using right click. But I fail to get the context path of the right click and I cannot find any hints on google or at the unity scripting api. Below you can see an image of the process I tried to describe above.

Here is the code that is responsible for handling the context creation "event".

[MenuItem("Assets/Create/Chat")]
Chat c = Chatter.createDefaultChat();

// This is the part where I want to insert the relative path.
AssetDatabase.CreateAsset(c, "Assets/" + c.Title + ".asset");
}


You can get the path by using Selection.activeObject. Here is a small code to get this feature working :)

   string path = AssetDatabase.GetAssetPath (Selection.activeObject);

if (path == "")
{
path = "Assets";
}
else if (Path.GetExtension(path) != "")
{
path = path.Replace(Path.GetFileName (AssetDatabase.GetAssetPath (Selection.activeObject)), "");
}
AssetDatabase.CreateAsset (asset, AssetDatabase.GenerateUniqueAssetPath (path + "/New MyAsset.asset"));