博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Getting Started with iOS Development Part9:Preparing your application for "In App Purchases"
阅读量:6233 次
发布时间:2019-06-22

本文共 4343 字,大约阅读时间需要 14 分钟。

Preparing your application for "In App Purchases"

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.

Apple's "StoreKit" documentation defines four kinds of Products that could be sold via the "In App Purchase" process:

  • Content
  • Functionality
  • Services
  • Subscriptions

This chapter covers the first case only and focuses mainly on the downloadable content concept.  are ideal candidates for use as downloadable content, and two scenarios will be covered:

  • How to export asset bundles for use on iOS
  • How download and cache them on iOS
 

Exporting your assets for use on iOS

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.

 
  1. Create an Editor folder inside the Project View.
  2. Create an ExportBundle.js script there and place the following code inside:
    @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);        }}
  3. Design your objects that need to be downloadable as prefabs
  4. Select a prefab that needs to be exported and mouse right click
    Getting <wbr>Started <wbr>with <wbr>iOS <wbr>Development <wbr>Part9:Preparing <wbr>your <wbr>application <wbr>for <wbr>"In <wbr>App <wbr>Purchases" 
    If the first two steps were done properly, then the Build AssetBundle From Selection - Track dependencies context menu item should be visible.
  5. Select it if you want to include everything that this asset uses.
  6. A save dialog will be shown, enter the desired asset bundle file name. An .assetbundle extension will be added automatically. The Unity iOS runtime accepts only asset bundles built with the same version of the Unity editor as the final application. Read  for details.

Downloading your assets on iOS

  1. Asset bundles can be downloaded and loaded by using the  and instantiating a main asset. Code sample:
    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");             }
  2. You can save required files to a Documents folder next to your game's Data folder.
    public static string GetiPhoneDocumentsPath () {                 // Your game has read+write access to /var/mobile/Applications/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/Documents                 // 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 + "/Documents";         }
     
  3. Cache a downloaded asset bundle using the .NET file API and for reuse it in the future by loading it via  andfile:///pathtoyourapplication/Documents/savedassetbundle.assetbundle. Sample code for caching:
    // 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 Documents folder        private var cachedAssetBundle : "path to your Documents 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);

转载地址:http://sqqna.baihongyu.com/

你可能感兴趣的文章
集合类型的装配
查看>>
【Linux开发技术之工具使用】配置VIM下编程和代码阅读环境
查看>>
【读书笔记】测试驱动开发(中文版)
查看>>
ExtAspNet v3.0.1
查看>>
javascript 构造函数和方法
查看>>
使用VB.net Express 2010开发AutoCAD.net插件调试时出现很多错误的解决办法
查看>>
.net服务使用笔记(原创)
查看>>
使用Tomcat配置域名
查看>>
[转]Oracle/Altibase数据库中Sequence的用法
查看>>
URAL 1009 K-based Numbers
查看>>
android 知识点汇总
查看>>
android之Notification通知
查看>>
C# 生成等比缩略图的类
查看>>
安利 : プログラミングで彼女をつくる 全攻略~
查看>>
1022. Digital Library (30)
查看>>
Canvas入门(2):图形渐变和图像形变换
查看>>
DataAccess通用数据库访问类,简单易用,功能强悍
查看>>
启动MYSQL密码审计插件
查看>>
spring的事务操作
查看>>
Extensions for Spatial Data
查看>>