Getting the absolute path of current project

I am currently working on a editor script that requires me to make use of System.IO, because Unity does not seem to have a function for getting every prefab in a specific asset folder. And i therefore have to use System.IO to get every file with a “.prefab” extension in the folder and then loop trough that list using AssetDatabase.LoadAssetAtPath()

But as i want this editor script to work on multiple machines with the project in different locations. As well as working on both Mac and Windows. I need a way to get the absolute path of the currently opened unity project. How do i do that?

So it would be something like this on windows:

"C:\Projects\MyUnityProject"

And something like this on the mac:

"/User/Projects/MyUnityProject"

Application.dataPath is what you are looking for.

You can use relative paths like “Assets/MyPrefabs/Prefab1.prefab”.

Application class contains a bunch of properties which return project paths, look into that.

There was a VCPath class on the UnityEditorInternal namespace that did the Job. (“VCPath.Project”) But that class is no longer present after version 4.2.x.
Using C# for editor stuff it will work by using Environment.CurrentDirectory, though I’m not sure how reliable that is.

I do something like this to get Assets/Resources path, while playing in editor, to implement my “builtin level editor”. But I do not use this path in final product.

	string codeBase = Assembly.GetExecutingAssembly().CodeBase;
	UriBuilder uri = new UriBuilder(codeBase);
	string path = Uri.UnescapeDataString(uri.Path);
	resourcePath = Path.GetFullPath(new Uri(Path.Combine(Path.GetDirectoryName(path), "../../Assets/Resources")).AbsolutePath);

My solution

public class GetProjectPathSample
{
    public static string GetProjectPath()
    {
        var args = System.Environment.GetCommandLineArgs();
        for (int i = 0; i < args.Length; i++)
        {
            if (args*.Equals("-projectpath", System.StringComparison.InvariantCultureIgnoreCase)) return args[i + 1];*

}
return string.Empty;
}
}