一直想研究打包assetbundle,但是一直没机会用,在网上看到的零零碎碎的片段也看不懂,今天终于抽空实验成功了,但是现在虽然成功打包并解析出了单个模型,但是我现在还是不明白怎么去用。
在打包过程中,还有两部分不慎明白,一就是打包出来的文件,有很多不知道都是干啥用的;二就是Aes加密还不太懂。
先把目前的研究成果记录一下,总共分为三个脚本,打包,加密,解析。下边是三个脚本的具体代码。
打包:
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using UnityEditor;
using UnityEngine;
public class CreateAssetBundles
{
private static string AssetBundlesPath = Path.Combine(Application.streamingAssetsPath, "AssetBundle");
[MenuItem("Assets/自定义命令/生成AssetBundles")]
private static void BuildAllAssetBundle()
{
SetSelectFolderFileBundleName();
BuildAssetBundlesWindows64();
}
/// <summary>
/// 打包assetbundle
/// </summary>
private static void BuildAssetBundlesWindows64()
{
string path = Path.Combine(AssetBundlesPath, "Windows64");
BuildAssetBundles(path, BuildTarget.StandaloneWindows64);
DeleteFile(path);
AssetBundlesEncypt(path);
AssetDatabase.Refresh();
}
/// <summary>
/// 删除多余文件
/// </summary>
/// <param name="_path"></param>
private static void DeleteFile(string _path)
{
if (Directory.Exists(_path))
{
DirectoryInfo dirInfo = new DirectoryInfo(_path);
FileInfo[] infos = dirInfo.GetFiles();
foreach (var v in infos)
{
if (v.Name.EndsWith(".manifest") || v.Name.EndsWith(".meta") || v.Name.StartsWith("AssetBundle") || v.Name.StartsWith("Windows64") || v.Name.StartsWith("WebGL"))
{
var vfile = Path.Combine(_path, v.Name)