Unity AssetBundle打包资源工具

Posted yangyadong66

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity AssetBundle打包资源工具相关的知识,希望对你有一定的参考价值。

using UnityEngine;
using System.Collections;
using UnityEditor;

/// <summary>
/// 简单资源打包Editor
/// </summary>
public class BuildPacketEditor : EditorWindow
{
[MenuItem("Tools/Packet/BuildAssetBundle-android")]
public static void ExportAndroid()
{
ImportPacket(BuildTarget.Android);//打包到安卓资源
}

[MenuItem("Tools/Packet/BuildAssetBundle-ios")]
public static void ExportIos()
{
ImportPacket(BuildTarget.iOS);//打包到IOS资源
}

[MenuItem("Tools/Packet/BuildAssetBundle-Win")]
public static void ExportWin()
{
ImportPacket(BuildTarget.StandaloneWindows);//打包到wwindows资源
}

static void ImportPacket(BuildTarget target)
{
string path = EditorUtility.SaveFilePanel("Save Resource", "", "New Resource", "assetbundle");//显示“保存文件”对话框并返回所选路径名。
if (path.Length != 0)
{
Object[] selection = Selection.GetFiltered(typeof(Object), SelectionMode.DeepAssets);
if (selection.Length < 1)
{
Debug.LogError("请选中要打包资源!");
return;
}
BuildPipeline.BuildAssetBundle(Selection.activeObject, selection, path, BuildAssetBundleOptions.CollectDependencies | BuildAssetBundleOptions.CompleteAssets, target);
}
}

}










































以上是关于Unity AssetBundle打包资源工具的主要内容,如果未能解决你的问题,请参考以下文章

AssetBundle Browser 教程丨Unity自带的一款AB包打包工具

AssetBundle Browser 教程丨Unity自带的一款AB包打包工具

一个灵活的AssetBundle打包工具

Unity AssetBundle共享资源打包/依赖资源打包

unity3d unity5.0 assetbundlemanifest包含哪些数据

Unity3D资源异步加载——AssetBundle资源打包加载