|
Is there a way to access a selected folder (in project view) through an editor script? If a folder is selected it will show up in the Selection.objects array, but how can I verify that it's a folder and get the complete path to it? I would like to write an editor script that performs some operations on all assets within a certain folder in my project and want to be able to choose that folder directly in the project view.
(comments are locked)
|
|
You need to use AssetDatabase.GetAssetPath() and Directory.Exists() which is part of the System.IO library in C#. At the top of your script include the System.IO library: Then check your selections with the following: Note that selectionPath is a relative path but Directory.Exists() is smart enough to realize this and still use it.
(comments are locked)
|
|
I just had to do something similar when trying to find a path for new assets. It's a little hacky for your usage but will get the job done without having to guess. I start with the assumption that each item is a directory and ask AssetDatabase.GenerateUniqueAssetPath(path) to give me a valid, unique path for a file inside that directory. If the item actually is a directory then a path is returned; but if it's a file then an empty string is returned.
(comments are locked)
|
|
I just had the same problem. AssetDatabase.GetAssetPath(myObject) returns the folder path (or any other asset path). The real problem is to verify that it's a folder. I'm not sure but it seems that only folders are UnityEngine.Objects (everything in Unity is derived from it but a folder just have this type) Just tried it that way:
but unfortunately ".unity" files (scene files) are Objects too. Since folders can contain "." (dots) the only way to verify that it's a folder would be to build the complete path and use http://System.IO to check if it's a folder.
(comments are locked)
|
