public class VersionLoadAb : MonoBehaviour
{
string path = null;
// Use this for initialization
void Start()
{
path = string.Format("{0}/{1}", Application.dataPath +"/StreamingAssets", "scenes.ab");
StartCoroutine("GetBundle");
}
private IEnumerator GetBundle()
{
Debug.Log("enter GetBundle");
WWW www = new WWW(path);
yield return www;
Debug.Log("load GetBundle");
if (www.error == null)
{
Debug.Log("success GetBundle");
AssetBundle bundle = www.assetBundle;
AsyncOperation op= UnityEngine.SceneManagement.SceneManager.LoadSceneAsync("VersionABDemo");
yield return new WaitWhile(() => { return op.progress == 100; });
bundle.Unload(false);
}
else
{
Debug.Log("fail GetBundle");
Debug.Log(">>> error :" + www.error);
}
www.Dispose();
www = null;
yield break;
}
}
读取ab包里的场景需要注意一点的是拿到ab包之后就可以直接跳转场景勒
总体与读取资源没有多大区别
主要也是利用www类来加载ab包
----------------------------------------------------------------分割线----------------------------------------------------------------
依赖关系要清晰
不然在打入ab包的时候依赖容易丢失