This chapter does not aim to cover how to integrate your game with Apple's "StoreKit" API. It is assumed that you already have integration with "StoreKit" via a native code plugin.
Apple's "StoreKit" documentation defines four kinds of Products that could be sold via the "In App Purchase" process:
This chapter covers the first case only and focuses mainly on the downloadable content concept. AssetBundles are ideal candidates for use as downloadable content, and two scenarios will be covered:
Having separate projects for downloadable content can be a good idea, allowing better separation between content that comes with your main application and content that is downloaded later.
Please note: Any game scripts included in downloadable content must also be present in the main executable.
@MenuItem ("Assets/Build AssetBundle From Selection - Track dependencies") static function ExportBundle(){ var str : String = EditorUtility.SaveFilePanel("Save Bundle...", Application.dataPath, Selection.activeObject.name, "assetbundle"); if (str.Length != 0){ BuildPipeline.BuildAssetBundle(Selection.activeObject, Selection.objects, str, BuildAssetBundleOptions.CompleteAssets, BuildTarget.iPhone); } }
Note: Apple may change the folder locations where you are permitted to write data. Always check Apple documentation to be sure your application will be compliant. The following was correct advice in early 2013.
var download : WWW; var url = "http://somehost/somepath/someassetbundle.assetbundle"; download = new WWW (url); yield download; assetBundle = download.assetBundle; if (assetBundle != null) { // Alternatively you can also load an asset by name (assetBundle.Load("my asset name")) var go : Object = assetBundle.mainAsset; if (go != null) instanced = Instantiate(go); else Debug.Log("Couldnt load resource"); } else { Debug.Log("Couldnt load resource"); }
// c# example public static string GetiPhoneDocumentsPath () { // Your game has read+write access to /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Library // Application.dataPath returns // /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/myappname.app/Data // Strip "/Data" from path string path = Application.dataPath.Substring (0, Application.dataPath.Length - 5); // Strip application name path = path.Substring(0, path.LastIndexOf('/')); return path + "/Library"; }
// Code designed for caching on iPhone, cachedAssetBundle path must be different when running in Editor // See code snippet above for getting the path to your Library folder private var cachedAssetBundle : String = "path to your Library folder" + "/savedassetbundle.assetbundle"; var cache = new System.IO.FileStream(cachedAssetBundle, System.IO.FileMode.Create); cache.Write(download.bytes, 0, download.bytes.Length); cache.Close(); Debug.Log("Cache saved: " + cachedAssetBundle);
Page last updated: 2013-01-30