Unity学习笔记/*加载bundle包AssetBundle接口*/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/*加载bundle包*/
public class F: MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        StartCoroutine(load());
    }
    IEnumerator load()
    {
        WWW www = new WWW("file:E:/unity_work/Study_unity_3D/Assets/Bundle/2.unity3d");//加载本地的bundle包
        //WWW www = new WWW("http://...");加载网络bundle包
        //WWW www = new WWW("file://"+Application.streamingAssetsPath+"2.unity3d");//手机加载的bundle包
        yield return www;
        AssetBundle bundle = www.assetBundle;
        /*同步加载,速度快,容易阻塞*/
       GameObject go= bundle.LoadAsset<GameObject>("Assets/Prefabs/Cube.prefab");//获取加载对象

        /*异步加载,不会阻塞,但速度稍慢*/
        /* AssetBundleRequest request = bundle.LoadAssetAsync("Assets/Prefabs/Cube.prefab", typeof(GameObject));
         yield return request;
         GameObject go = request.asset as GameObject;*/
        Instantiate(go);//实例话该对象
        www.Dispose();//析构释放内存
    }
}

发布了5 篇原创文章 · 获赞 0 · 访问量 22

猜你喜欢

转载自blog.csdn.net/qq_42447732/article/details/105617633