Book Image

Unity 5 for Android Essentials

By : Valera Cogut
Book Image

Unity 5 for Android Essentials

By: Valera Cogut

Overview of this book

Table of Contents (14 chapters)
Unity 5 for Android Essentials
About the Author
About the Reviewers

Safeness techniques in practice

Next, the C# script example will cover how to protect the content of your asset bundles (as shown here):

using UnityEngine;
using System.Collections;

public class AssetBundleSecurityFirst : MonoBehaviour {
  string assetBundleUrl = 

  IEnumerator Start() {
    WWW www = WWW.LoadFromCacheOrDownload(assetBundleUrl, 1);
    yield return www;

    TextAsset textAsset = www.assetBundle.Load(
      "YourEncryptedAssetName", typeof(TextAsset)
    ) as TextAsset;
    /*byte[] yourDecryptedBytes = AnyDecryptionFunction(
      textAsset.bytes // your encrypted bytes

Another secure way is to encrypt the whole asset bundle instead of just the TextAsset data as shown in the preceding code. Alternatively, in this approach, you cannot use the WWW.LoadFromCacheOrDownload method. You always need to import your bundles from WWW streaming as shown in the following code:

using UnityEngine;
using System...