Sorry for my English (Google Translate). The following is a snippet of code that creates an asset (ScriptableObject) in the selected directory (Assets/Resources/TestObject.asset):
[MenuItem("Assets/Create/Test Object")]
private static void CreateTestObject()
{
var testObject = ScriptableObject.CreateInstance<TestObject>();
AssetDatabase.CreateAsset(testObject, "Assets/Resources/TestObject.asset");
AssetDatabase.SaveAssets();
}
How can I get the path to the directory I'm in? In order to don´t hardcode the path manually, but to save this GameObject in the same folder where I call the method.
For example:
1) I call the method from Assets/TestFolder/TestFolder2.
2) And in this same directory it creates an asset (TestObject). And does not create in Assets/Resources.
To sum up, I need to get the path to the directory in which I called the method through the menu (Assets/Create/Test Object).
Additionally: Can I immediately rename the GameObject after creating it? As with other objects (scripts, folders, etc.).
Thanks in advance for your answers!
Example (screenshot): How do I get the path that is highlighted in red. I'll call the method through the menu (Create/Test Object). In the directory I have chosen (Assets/TestFolder/TestFolder2). And the asset is created there. And not in Assets/Resources. I need a method that will return a string to me: Assets/TestFolder/TestFolder2.