Lua热更新之AssetBundle

//https://www.bilibili.com/video/av33895324/?p=20
//—1打包AssetBundle
using UnityEditor;
public class CreateAssetsBundle {
[MenuItem(“Assets/BuildAssetBundles”)]
static void BuildAssetBundles()
{
BuildPipeline.BuildAssetBundles(“AssetBundles”, BuildAssetBundleOptions.None,
BuildTarget.StandaloneWindows);
}
}

//—2加载AssetBundle包
using UnityEngine;
public class LoadAssetBundle : MonoBehaviour
{
public string url;
public string assetname;
IEnumerator Start()
{
//url = @“fil://E:/Test/AssetBundle/AssetBundles”;//应该把所有得\都改成/,头部加上file://表示头部文件
WWW www =new WWW(url);
yield return www;//表示等待www加载完成
if (www.error!=null)
{
Debug.LogError(“网络错误”);
}
else
{
AssetBundle bundle = www.assetBundle;
Object obj= bundle.LoadAsset(assetname);
Instantiate(obj);
bundle.Unload(false);//加载之后,要把资源卸载掉,false表示卸载已经用过的,true表示卸载所有的资源
}
www.Dispose();
}
}

你可能感兴趣的:(Lua热更新之AssetBundle)