Reputation: 14411
Is there a way to find all prefabs defined/available in a Unity project programmatically?
This should include prefabs sitting in the Assets folder which are not in the Resources folder.
Use-cases range from dynamically resolving dependencies (from a name for example) to wanting to implement some central instantiation code.
Upvotes: 1
Views: 340
Reputation: 16287
string path = Application.dataFolder;
string[] files = System.IO.Directory.GetFiles(path, "*.prefab");
for(int i=0;i<files.Length;i++)
Debug.Log(files[i];
If you wish to load the prefab into the scene:
var url = "file://....prefab";
var www = new WWW (url);
yield return www;
www.bytes[]; // This way, you have to convert it to game object yourself.
Upvotes: 1