Unity3D內容加密保護,unity3d內容加密

來源:互聯網
上載者:User

Unity3D內容加密保護,unity3d內容加密

僅管資源 (Assets) 在傳輸時可使用加密進行保護,但在資料流入客戶手中後,其內容就有可能被擷取。例如,有工具可記錄驅動程式層級上的 3D 資料,允許使用者提取傳送至 GPU 的模型和紋理。因此,我們通常希望在使用者決定提取資源時,能夠滿足其要求。

當然,如果您需要,也可以對資源套件 (AssetBundle) 檔案使用自己的資料加密。

一種方法是,使用文本資源 (AssetBundle) 類型將資料存放區為位元組。您可以加密資料檔案,並使用副檔名 .bytes 進行儲存,Unity 會將其視為文本資源 (TextAsset) 類型。在編輯器 ( Editor) 中匯入後,作為文本資源 (TextAssets) 的檔案可匯入將置於伺服器上的資源套件 (AssetBundle)。客戶可以下載資源套件 (AssetBundle) 並將儲存在文本資源 (TextAsset) 中的位元組解密為內容。藉助此方法,既不會對資源套件 (AssetBundles) 加密,又可以將資料作為文本資源 (TextAssets) 儲存。

string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";IEnumerator Start () {// Start a download of the encrypted assetbundleWWW www = new WWW.LoadFromCacheOrDownload (url, 1);// Wait for download to completeyield return www;// Load the TextAsset from the AssetBundleTextAsset textAsset = www.assetBundle.Load("EncryptedData", typeof(TextAsset));// Get the byte databyte[] encryptedData = textAsset.bytes;// Decrypt the AssetBundle databyte[] decryptedData = YourDecryptionMethod(encryptedData);// Use your byte array.The AssetBundle will be cached}

另一可用方法是對資源中的資源套件 (AssetBundles) 完全加密,然後使用 WWW 類下載資源套件。只要伺服器將其作為位元據提供 ,則可用任何您喜歡的副檔名命名。下載完成後,您可以使用 WWW 執行個體的 .bytes 屬性資料相關的解密程式擷取解密的資源套件 (AssetBundle) 檔案資料,並使用AssetBundle.CreateFromMemory 在記憶體中建立資源套件 (AssetBundle)。

string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";IEnumerator Start () {// Start a download of the encrypted assetbundleWWW www = new WWW (url);// Wait for download to completeyield return www;// Get the byte databyte[] encryptedData = www.bytes;// Decrypt the AssetBundle databyte[] decryptedData = YourDecryptionMethod(encryptedData);// Create an AssetBundle from the bytes arrayAssetBundle bundle = AssetBundle.CreateFromMemory(decryptedData);// You can now use your AssetBundle.The AssetBundle is not cached.}

第二種方法之於第一種方法的優勢在於,可使用任何類函數(AssetBundles.LoadFromCacheOrDownload 除外)傳輸位元組,並且可對資料進行完全加密 – 例如,外掛程式中的通訊端。缺點在於無法使用 Unity 的自動緩衝功能進行緩衝。可使用所有播放器(網頁播放器 (WebPlayer) 除外)在磁碟上手動隱藏檔,並使用AssetBundles.CreateFromFile 負載檔案。

第三種方法結合了前兩種方法的優點,可將資源套件 (AssetBundle) 另存新檔其他普通資源套件中的文本資源 (TextAsset)。系統會緩衝包含已加密資源套件 (AssetBundle) 的未加密資源套件。然後會將原始資源套件 (AssetBundle) 載入到記憶體,並使用AssetBundle.CreateFromMemory 解密並執行個體化。

string url = "http://www.mywebsite.com/mygame/assetbundles/assetbundle1.unity3d";IEnumerator Start () {// Start a download of the encrypted assetbundleWWW www = new WWW.LoadFromCacheOrDownload (url, 1);// Wait for download to completeyield return www;// Load the TextAsset from the AssetBundleTextAsset textAsset = www.assetBundle.Load("EncryptedData", typeof(TextAsset));// Get the byte databyte[] encryptedData = textAsset.bytes;// Decrypt the AssetBundle databyte[] decryptedData = YourDecryptionMethod(encryptedData);// Create an AssetBundle from the bytes arrayAssetBundle bundle = AssetBundle.CreateFromMemory(decryptedData);// You can now use your AssetBundle.The wrapper AssetBundle is cached}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.