加载assetbundle
using System.Collections; using System.Collections.Generic; using UnityEngine; using System.IO; public class LoadAssetBundle : MonoBehaviour { private string BundleURL; public UILabel uilabel; public Material mat; private void Start() { //在pc端加载的assetbundle包后缀为“assetbundle” 移动端后缀为“unity3d” #if UNITY_EDITOR StartCoroutine(LoadAsset("文件名.assetbundle", "URL")); #else StartCoroutine(LoadAsset("文件名.unity3d", "URL")); #endif } IEnumerator LoadAsset( string FileName,string Url) { //如果本地有这个asb包则读本地 ,如果没有则下载到本地后再读取 if (File.Exists(Application.persistentDataPath + "/" + FileName)) { using (WWW asset = new WWW("file:///" +Application.persistentDataPath + "/" + FileName)) { yield return asset; AssetBundle bundle = asset.assetBundle; //bundle.LoadAsset("文件名") GameObject Obj = Instantiate(bundle.LoadAsset("打包前的资源名称")) as GameObject; bundle.Unload(false); yield return new WaitForSeconds(5); } } else { using (WWW asset = new WWW(Url)) { yield return asset; FileStream f = new FileStream(Application.persistentDataPath + "/" + FileName, FileMode.Create, FileAccess.Write); f.Write(asset.bytes, 0, asset.bytes.Length); AssetBundle bundle = asset.assetBundle; GameObject Obj = Instantiate(bundle.LoadAsset("打包前的资源名称")) as GameObject; bundle.Unload(false); yield return new WaitForSeconds(5); } } } }
相关推荐
-
C#给含有数字的字符串排序 csharp
2019-1-7
-
c#图片压缩处理 csharp
2019-1-7
-
C#将浮点型的值转换成中文金额 csharp
2019-1-7
-
C#通用表达式树 csharp
2019-1-7
-
多线程日志类 csharp
2019-1-8
-
C#用户登录功能 csharp
2019-1-7
-
ASP.NET 上传文件控件 csharp
2019-1-7
-
C#获取摄像头画面 csharp
2019-1-8
-
C#去除字符串空格 csharp
2019-1-8
-
实例序列化XML、XML反序列化实例、输入文件到服务器 csharp
2019-1-7