AssetBundle动态加载
在Asset目录下新建一个StreamingAssets文件夹
创建一个BundleEditor.cs脚本文件
using UnityEditor;
using UnityEngine;
/// <summary>
/// 打包工具
/// </summary>
public class BundleEditor
{
[MenuItem("Tools/打包")]
public static void Build()
{
//打包
/* Application.streamingAssetsPath Asset/StreamingAssets/
* BuildAssetBundleOptions.ChunkBasedCompression 加密方式
* EditorUserBuildSettings.activeBuildTarget当前编辑器使用目标平台
*/
BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath, BuildAssetBundleOptions.ChunkBasedCompression,EditorUserBuildSettings.activeBuildTarget);
//编辑器刷新
AssetDatabase.Refresh();
}
}
在所需要打包的物体上加包名

使用Tool/打包

使用脚本加载
//加载物体
AssetBundle assetBundle=AssetBundle.LoadFromFile(Application.streamingAssetsPath + "/[包名]");
//场景生成物体
GameObject obj = GameObject.Instantiate(assetBundle.LoadAsset<GameObject>("[物体名]"));
网友评论