臥槽,今天一打開Package Manager我發(fā)現(xiàn)了什么??。?!

我的天吶,等了這么久終于出了!居然單獨(dú)出了一個(gè)AddressablesCN用于加密,簡(jiǎn)直太貼心了。
此處感動(dòng)地留下了淚水,幸好項(xiàng)目還沒(méi)發(fā)布,分分鐘轉(zhuǎn)過(guò)來(lái)。
本貼就是感慨一下,順帶召喚小伙伴們,快去用AddressablesCN啊,簡(jiǎn)單易用,有了加密功能簡(jiǎn)直無(wú)懈可擊~
附帶官方使用說(shuō)明地址:https://ucgbucket.unitychina.cn/AssetStreaming/AddressablesCN.pdf
這里簡(jiǎn)述一下使用方法:
1.創(chuàng)建Group

2.如果要設(shè)置自己的密鑰:在工程里新建一個(gè)腳本,腳本內(nèi)容如下,命名你們隨意,設(shè)置一下密鑰,注意密鑰需要16位,正常ASCII碼均可,也就是普通數(shù)字大小寫字母都行
using System.IO;
using System.Security.Cryptography;
namespace UnityEngine.ResourceManagement.ResourceProviders
{
public class MyAESStreamProcessor : IDataConverter
{
byte[] Key
{
get
{
return
System.Text.Encoding.ASCII.GetBytes("ABCDEFGHIJKLMNOP");//修改此處密鑰,需要16位,正常ASCII碼均可
}
}
SymmetricAlgorithm m_algorithm;
SymmetricAlgorithm Algorithm
{
get
{
if (m_algorithm == null)
{
m_algorithm = new AesManaged();
m_algorithm.Padding = PaddingMode.Zeros;
var initVector = new byte[m_algorithm.BlockSize / 8];
for (int i = 0; i < initVector.Length; i++)
initVector[i] = (byte)i;
m_algorithm.IV = initVector;
m_algorithm.Key = Key;
m_algorithm.Mode = CipherMode.ECB;
}
return m_algorithm;
}
}
public Stream CreateReadStream(Stream input, string id)
{
return new CryptoStream(input,
Algorithm.CreateDecryptor(Algorithm.Key, Algorithm.IV),
CryptoStreamMode.Read);
}
public Stream CreateWriteStream(Stream input, string id)
{
return new CryptoStream(input,
Algorithm.CreateEncryptor(Algorithm.Key, Algorithm.IV),
CryptoStreamMode.Write);
}
}
}
3.Group上的高級(jí)設(shè)置選一下加密方式

用起來(lái)真簡(jiǎn)單,給AddressablesCN點(diǎn)贊~
在實(shí)際項(xiàng)目使用中發(fā)現(xiàn)他會(huì)報(bào)錯(cuò),然后加載半天后Addressables報(bào)空物體,排查了一下,發(fā)現(xiàn)所有的Group都得選同一個(gè)加密方式,尤其是默認(rèn)的Group別忘了選~
2020.1.29更新
好吧我又回來(lái)了,我收回以上的贊揚(yáng)。
實(shí)際使用的時(shí)候發(fā)現(xiàn)AddressablesCN會(huì)在啟動(dòng)程序的時(shí)候卡頓很久,造成了大量的GC

默默換回了Addressables。。。