以编程方式管理预制件

时间:2015-10-09 05:24:33

标签: unity3d

有没有办法以编程方式查找Unity项目中定义/可用的所有预制件?

这应该包括位于Assets文件夹中的预制件,这些预制件不在Resources文件夹中。

用例包括动态解析依赖项(例如从名称)到想要实现某些中央实例化代码。

1 个答案:

答案 0 :(得分:1)

string path = Application.dataFolder;
string[] files = System.IO.Directory.GetFiles(path, "*.prefab");
for(int i=0;i<files.Length;i++)
    Debug.Log(files[i];

enter image description here

如果您希望将预制件加载到场景中:

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.