- Home /
What's the type of a folder/directory concerning the validation for a MenuItem?
[MenuItem("Assets/Compile Folder", true)]
static bool CompileSourceFiles()
{
return Selection.activeObject.GetType() == typeof();
}
I'd like to add a menuitem to the context menu, which is only available if the right-click has been done on a folder.
Unity's example is just about a Texture2D type. After enabling the menuitems for folder, how can I get the path of the folder?
Question is solved. The solution can be foun on Gist at GitHub https://gist.github.com/MarcoMeter/7ca803a5c4dcfabb4037728eddb5c95a
Answer by MarcoMeter · Sep 24, 2016 at 01:15 PM
Found the solution already:
Validation function:
[MenuItem("Assets/Compile Folder", true)]
private static bool CompileSourceFilesValidation()
{
string filePath = AssetDatabase.GetAssetPath(Selection.activeObject);
FileAttributes attr = File.GetAttributes(filePath);
return ((attr & FileAttributes.Directory) == FileAttributes.Directory);
}
Your answer
Follow this Question
Related Questions
Editor Script does not save changes 1 Answer
What is the correct syntax for UnityEditor.VersionControl.Provider.GetAssetByPath? 1 Answer
Variables modified on other scripts through a Editor Script reset on Play? 1 Answer
How do you run File->Build Settings... from code? 0 Answers
Editor Scripting Question 1 Answer