AssetBundle-----资源加载(读取assetbundle)

来源:互联网 发布:数据集成方法 编辑:程序博客网 时间:2024/06/04 18:08
using UnityEngine;using System.Collections;public class LoadAssetBundle : MonoBehaviour { public string path; public string file;void Start () { StartCoroutine(Load());} IEnumerator Load() { string _path ="file:///"+Application.dataPath + path; WWW www = WWW.LoadFromCacheOrDownload(_path,1); yield return www; AssetBundle bundle = www.assetBundle; AssetBundleRequest request = bundle.LoadAssetAsync(file); yield return request; GameObject obj = request.asset as GameObject; Instantiate(obj); bundle.Unload(false); www.Dispose(); }}
using System.Collections;using System.Collections.Generic;using UnityEngine;public class TEST : MonoBehaviour{    // Use this for initialization    void Start()    {        string path =Application.dataPath + "/bundles/aaaa";        AssetBundle assetbundle = AssetBundle.LoadFromFile(path);        GameObject g = assetbundle.LoadAsset<GameObject>("Cube");        GameObject.Instantiate(g);    }    // Update is called once per frame    void Update()    {    }}




0 0