Unity 关于AssetBundle读取场景


一.

  1.关于如何打包成ab包,就不多说了,网上很多教程,siki学院也有siki老师的免费视频教程挺详细的,可以看看 http://www.sikiedu.com/my/course/74

  2.为了图方便,用了siki老师说的AssetBundlesBrowser打包工具,这个工具还可以查看包内容,满赞的

 

 

二.打包完成之后得到ab包

  1.直接上代码吧,毕竟那么简单

IEnumerator wait()
    {
        string path = Application.streamingAssetsPath + "/test.ab";//ab包位置//test.ab是我ab包的名字
        WWW www = new WWW(path);
        yield return www;
        if (string.IsNullOrEmpty(www.error))
        {
            //获取到ab包资源
            AssetBundle bundle = www.assetBundle;
            //输出所有资源地址
            string[] strs = bundle.GetAllScenePaths();
            foreach (string str in strs) Debug.Log(str);
            //一步读取场景
            AsyncOperation async = SceneManager.LoadSceneAsync("Test");//不需要带后缀//这里Test是我的场景名字
            async.allowSceneActivation = false;
            while (async.progress < 0.9f)
            {
                Debug.Log("场景进度  " + async.progress);
                yield return null;
            }
            async.allowSceneActivation = true;
            yield break;
        }
        Debug.Log("读取错误  " + www.error);
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM