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);
}
}

}

猜你喜欢

转载自www.cnblogs.com/yangyadong66/p/9259954.html