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