Skip to content

Instantly share code, notes, and snippets.

@tsubaki tsubaki/LoadAssetbundle.cs
Last active Mar 16, 2019

Embed
What would you like to do?
AssetBundleを復号してロードする
using System.Collections;
using UnityEngine;
using System.IO;
using System.Text;
public class LoadAssetbundle : MonoBehaviour
{
AssetBundle bundle;
FileStream fileStream;
const string password = "password";
void OnEnable()
{
// 暗号化したAssetBundleを取得
fileStream = new FileStream($"{Application.streamingAssetsPath}/esprite", FileMode.Open);
var uniqueSalt = Encoding.UTF8.GetBytes("sprite"); // AssetBundle名でsoltを生成
// Streamで暗号化を解除しつつAssetBundleをロードする
var uncryptor = new SeekableAesStream(fileStream, password, uniqueSalt);
bundle = AssetBundle.LoadFromStream(uncryptor);
}
private IEnumerator Start()
{
// 普通のAssetBundleと同様にロード出来る
var request = bundle.LoadAssetAsync<Sprite>("01");
yield return request;
GetComponent<SpriteRenderer>().sprite = request.asset as Sprite;
}
private void OnDisable()
{
bundle.Unload(true);
fileStream.Close();
}
}
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.