,

"In App Purchases"를 위한 프로그램 준비

이 장은 애플의 "StoreKit"과 어떻게 게임을 연계시키는지를 다루기 위한 것이 아닙니다. 이것은 사용자가 이미 native code plugin를 통해 "StoreKit"과 연계하였음을 가정합니다.

애플의 "StoreKit"문서는 "In App Purchase" 과정을 통해 판매될 수 있는 네가지의 _상품_에 대해 정의합니다:

이 장은 첫번째 경우만을 다르며 다운로드할 수 있는 콘텐트 개념에만 집중합니다. AssetBundles는 다운로드할 수 있는 콘텐츠의 가장 적합한 후보이며 두가지 경우가 다루어질 것입니다:

iOS에서 에셋 내보내기

다운로드 가능한 콘텐츠를 위한 개별 프로젝트를 가지는 것은 주 프로그램과 같이 오는 다운로드 가능한 컨텐츠와 나중에 다운로드 받는 콘텐츠를 잘 구분하게 해주는 좋은 생각입니다.

다운로드 가능한 콘텐츠에 포함되어 있는 어떤 게임 스크립트도 주 실행프로그램안에 존재해야 합니다.

@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);
        }
}


첫 두 스텝이 잘 끝나면 Build AssetBundle From Selection - Track dependencies 메뉴 아이템이 보일 것입니다.

iOS에서 에셋 다운로드

	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");	
	}
        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"; 
        }
	// 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);