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
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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 = 
    "http://yourweb.com/path/to/yourAssetBundle.unity3d";

  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...