image.png
protected GameObject InstantiatePrefab (string folderPath, string prefabName)
{
GameObject instance = null;
string[] prefabFolderPath = { folderPath };
string[] guids = AssetDatabase.FindAssets (prefabName, prefabFolderPath);
if(guids.Length == 0)
Debug.LogError ("The " + prefabName + " prefab could not be found in " + folderPath + " and could therefore not be instantiated. Please create one manually.");
else if(guids.Length > 1)
Debug.LogError ("Multiple " + prefabName + " prefabs were found in " + folderPath + " and one could therefore not be instantiated. Please create one manually.");
else
{
string path = AssetDatabase.GUIDToAssetPath (guids[0]);
GameObject prefab = AssetDatabase.LoadAssetAtPath<GameObject> (path);
instance = Instantiate (prefab);
}
return instance;
}
网友评论