Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raystudio9236/b73af340b2d4181b953c1a70f031315a to your computer and use it in GitHub Desktop.
Save raystudio9236/b73af340b2d4181b953c1a70f031315a to your computer and use it in GitHub Desktop.
Unity 3d : Get Selected Folder in Project Window
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.IO;
public static class UnityUtil
{
public static string GetSelectedPathOrFallback()
{
string path = "Assets";
foreach (UnityEngine.Object obj in Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.Assets))
{
path = AssetDatabase.GetAssetPath(obj);
if ( !string.IsNullOrEmpty(path) && File.Exists(path) )
{
path = Path.GetDirectoryName(path);
break;
}
}
return path;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment