using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
//几种压缩方式及平台选择,这里路径为Application.persistentDataPath,具体在各个平台上的路径请自行前往下方链接查阅
//https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
public class BuildAssetBundle : Editor
{
[MenuItem("BuildAB/BuildABToWin64/LZMA(体积小,加载慢)")]
private static void BuildABsToWin64_LZMA()
{
string path =Application.persistentDataPath + "/AssetBundle";
BuildPipeline.BuildAssetBundles(path, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);
Debug.Log("AssetBundle资源打包完成");
}
[MenuItem("BuildAB/BuildABToWin64/不压缩(体积大,加载快)")]
private static void BuildABsToWin64_UnComper()
{
string path = Application.persistentDataPath + "/AssetBundle";
BuildPipeline.BuildAssetBundles(path, BuildAssetBundleOptions.UncompressedAssetBundle, BuildTarget.StandaloneWindows64);
Debug.Log("AssetBundle资源打包完成");
}
[MenuItem("BuildAB/BuildABToWin64/LZ4(体积中,加载中)")]
private static void BuildABsToWin64_LZ4()
{
string path = Application.persistentDataPath + "/AssetBundle";
BuildPipeline.BuildAssetBundles(path, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.StandaloneWindows64);
Debug.Log("AssetBundle资源打包完成");
}
[MenuItem("BuildAB/安卓平台_LZ4")]
private static void BuildADTOAndroid()
{
string path = Application.persistentDataPath + "/AssetBundle";
BuildPipeline.BuildAssetBundles(path, BuildAssetBundleOptions.ChunkBasedCompression, BuildTarget.Android);
}
}
//加载方式
private void Load()
{
AssetBundle ab = AssetBundle.LoadFromFile(Application.persistentDataPath +"/AssetBundle/prefabs/hero.test");
GameObject o = ab.LoadAsset<GameObject>("wuseer");
Instantiate(o);
}