Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

Asset creation process

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

[MenuItem("Assets/Create/Chat")]
public static void createChatViaMenu() {
    Chat c = Chatter.createDefaultChat();

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

If you need any more information please let me know.

like image 720
Wachiwi Avatar asked Oct 25 '25 08:10

Wachiwi


1 Answers

Solution can be found in this answer by Hash Buoy.

The core information I needed was that I could get the relative path via AssetDatabase.GetAssetPath (Selection.activeObject).

like image 125
Wachiwi Avatar answered Oct 27 '25 22:10

Wachiwi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!