Unity之 AssetBundle应用
来源:互联网 发布:管家婆 端口 编辑:程序博客网 时间:2024/05/19 04:05
把以下这个脚本放入工程中 自动 打包已经设置了AssetBundleName的资源
using UnityEngine;
using UnityEditor;
using System.IO;
public class NewAssetBundleEditor : Editor
{
[MenuItem("AssetBundle/Build AssetBundles")]
static void BuildAllAssetBundles()
{
//如果文件夹不存在,则创建文件夹
string outPath = Application.dataPath + "/AssetBundles";
if (!Directory.Exists(outPath))
{
Directory.CreateDirectory(outPath);
}
//BuildAssetBundleOptions.ForceRebuildAssetBundle:用于强制重打所有AssetBundle文件
//BuildTarget.StandaloneWindows:适应平台:Windows
BuildPipeline.BuildAssetBundles("Assets/AssetBundles", BuildAssetBundleOptions.ForceRebuildAssetBundle, BuildTarget.StandaloneWindows);
AssetDatabase.Refresh();
}
}
以上是资源打包
下面是资源加载脚本
using UnityEngine.UI ;
using System.Collections;
using UnityEngine;
public class ReadAB : MonoBehaviour {
string path ;
// Use this for initialization
void Start () {
path = "file:///" + Application.dataPath + "/AssetBundles/cube";
transform .Find ("Button").GetComponent<Button>().onClick .AddListener (delegate(){
StartCoroutine (loadabbywww1(path));});
}
// Update is called once per frame
void Update () {
}
public IEnumerator loadabbywww1(string path)
{
// AssetBundle ab = AssetBundle.LoadFromFile(path);
WWW www = new WWW(path);
yield return www;
while (!www.isDone )
{
yield return null;
}
AssetBundle ab = www.assetBundle;
GameObject cube = ab.LoadAsset("cube")as GameObject ;
if (cube!=null)
{
Debug.Log(cube.name);
}
Instantiate(cube);
yield return new WaitForSeconds(0.1f);
ab.Unload(false);
}
public IEnumerator loadabbywww(string path)
{
string murl = "file:///" + Application.dataPath + "/AssetBundles";
WWW mwww = WWW.LoadFromCacheOrDownload(murl,0);
yield return mwww;
while (!mwww.isDone)
{
yield return null;
}
AssetBundle mab = mwww.assetBundle;
AssetBundleManifest mainfest = (AssetBundleManifest)mab.LoadAsset("AssetBundlesManifest");
mab.Unload(false);
string[] dps = mainfest.GetAllDependencies("cube");
AssetBundle[] abs = new AssetBundle[dps.Length];
for (int i = 0; i < dps.Length;i++)
{
string durl = "file:///" + Application.dataPath + dps[i];
WWW dwww = WWW.LoadFromCacheOrDownload(durl,mainfest.GetAssetBundleHash (dps[i]));
yield return dwww;
abs[i] = dwww.assetBundle;
}
WWW www = WWW.LoadFromCacheOrDownload(path,mainfest.GetAssetBundleHash("firstab"+".ab"),0);
yield return www;
AssetBundle ab = www.assetBundle;
GameObject cube = ab.LoadAsset("firstab") as GameObject;
if (cube!=null)
{
Instantiate(cube);
ab.Unload(false);
}
}
}
- Unity之 AssetBundle应用
- unity动态加载之AssetBundle应用
- unity动态加载之AssetBundle应用
- Unity之AssetBundle的实际应用
- Unity之AssetBundle资源管理
- UNITY之AssetBundle
- unity之AssetBundle
- Unity资源打包之Assetbundle
- Unity之资源打包Assetbundle
- Unity 热更新之AssetBundle
- Unity资源解决方案之AssetBundle
- Unity资源打包之Assetbundle
- Unity 热更新之AssetBundle
- Unity 热更新之AssetBundle
- unity AssetBundle
- unity-AssetBundle
- <Unity> AssetBundle
- Unity AssetBundle
- 后台调js方法
- servlet与struts2的存值方式
- django初学习
- my97时间控件结束时间不能小于开始时间
- IOS开发者账号申请记录
- Unity之 AssetBundle应用
- 类之间的关系
- shadowsocks访问google出错问题
- ES6 Template String 模板字符串
- valuestack存储值过程
- mysql General error: 1366 Incorrect string value: '\xF0\x9F\x91\x8D\xF0\x9F...' for column 'dianpumiaoshu' at row 1 解决方法
- 【MyBatis学习01】宏观上把握MyBatis框架
- 20位活跃在Github上的国内技术大牛
- 支付宝人气眼是美团吗?支付宝人气眼什么意思?