Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
暗号化したAssetBundleを生成
using UnityEngine;
using UnityEditor;
using System.IO;
using System.Text;
public class AssetBundleBuilder
{
const string password = "password";
[MenuItem("Assets/Build")]
static void Build()
{
// AssetBundleを構築
var exportPath = Application.streamingAssetsPath;
Directory.CreateDirectory(exportPath);
var manifest = BuildPipeline.BuildAssetBundles(
exportPath,
BuildAssetBundleOptions.ChunkBasedCompression,
BuildTarget.StandaloneWindows64);
// マニフェストから生成したAssetBundle一覧を取得して、全て暗号化をかける
foreach ( var name in manifest.GetAllAssetBundles())
{
// uniqueSaltはStream毎にユニークにする必要がある!!
// 今回はAssetBundle名を設定
var uniqueSalt = Encoding.UTF8.GetBytes(name);
// 暗号化してファイルに書き込む
var data = File.ReadAllBytes($"{Application.streamingAssetsPath}/{name}");
using (var baseStream = new FileStream($"{Application.streamingAssetsPath}/e{name}", FileMode.OpenOrCreate))
{
var cryptor = new SeekableAesStream(baseStream, password, uniqueSalt);
cryptor.Write(data, 0, data.Length);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.