Created
March 16, 2019 06:03
-
-
Save tsubaki/aa608f4aa446bbc2ae1044355a0ad151 to your computer and use it in GitHub Desktop.
暗号化したAssetBundleを生成
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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