Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Unity 5 for Android Essentials

You're reading from   Unity 5 for Android Essentials A fast-paced guide to building impressive games and applications for Android devices with Unity 5

Arrow left icon
Product type Paperback
Published in Aug 2015
Publisher
ISBN-13 9781784399191
Length 200 pages
Edition 1st Edition
Tools
Arrow right icon
Author (1):
Arrow left icon
 Cogut Cogut
Author Profile Icon Cogut
Cogut
Arrow right icon
View More author details
Toc

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...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime
Visually different images