我可以使用 AssetBundle.LoadAsync 直接从 Assets 文件夹加载预制件吗?在 Assets/Bundle 文件夹中有一个名为 "BGELement" 的预制件,我不想将其放入 Resources 文件夹并使用 Resource.Load 加载它。以下是我的代码,但它会出错:NullReferenceException,错误行是 ab.LoadAsync()
using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
void Start () {
StartCoroutine(NewLoadBGElement ());
}
IEnumerator NewLoadBGElement () {
string path = Application.dataPath + "/Bundle/BGElement";
AssetBundle ab = new AssetBundle ();
AssetBundleRequest abr = ab.LoadAsync(path, typeof(GameObject));
yield return abr;
GameObject newCube = Instantiate(abr.asset) as GameObject;
}
}