- Home /
How do I print out which folder in the projects tab is currently selected ?
How would I print out whatever folder is released from this area of the Project tab, the moment I select the folder?
AssetDatabase.GetAssetPath(Selection.activeObject); work for the other part of the project tab , but not for this section.
I decided to just ask how to print out the name of the currently selected folder because it makes the questions easier to understand.
So if I select "New Folder" what function would I use to print out that "New Folder" was selected ; the moment I select it?
Thanks for any help.
Answer by fafase · Aug 29, 2015 at 07:37 PM
Would it be?
http://answers.unity3d.com/questions/472808/how-to-get-the-current-selected-folder-of-project.html
/// <summary>
/// Retrieves selected folder on Project view.
/// </summary>
/// <returns></returns>
public static string GetSelectedPathOrFallback()
{
string path = "Assets";
foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), Selection$$anonymous$$ode.Assets))
{
path = AssetDatabase.GetAssetPath(obj);
if (!string.IsNullOrEmpty(path) && File.Exists(path))
{
path = Path.GetDirectoryName(path);
break;
}
}
return path;
}
Dunno how you plan on using the method but I would move a few lines like this
public static string GetSelectedPathOrFallback()
{
string path = "Assets";
foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), Selection$$anonymous$$ode.Assets))
{
path = AssetDatabase.GetAssetPath(obj);
if (!string.IsNullOrEmpty(path) && File.Exists(path))
{
path = Path.GetDirectoryName(path);
return path;
}
}
return null;
}
Now you can check on the outside if the method went fine:
string path = GetSelectedPathOrFallback();
if(string.IsNullOrEmpty(path) == false){ // Do something }
else { // something went wrong}
Your answer
Follow this Question
Related Questions
Using Hidden folders for editor stuff? 1 Answer
How do I wait until after AssetDatabase creates an assets before carrying out another function ? 0 Answers
Getting direct dependencies for an asset 1 Answer
How do I return the path of a sub-asset in an AssetDatabase ? 0 Answers
Help with Missing Monobehaviours and Asset Serialization? 0 Answers