Unity IAPは、Placementsを通じてIAPプロモーションアセットを表示するためのシンプルなウェブビューインターフェイスを提供します。これらのアセットのレンダリングプロセスを制御するには、Native Promoを使用してカスタムプロモーションディスプレイを実装します。
Native Promo.を使用するには、Asset Storeから最新のSDK (3.0+)をダウンロードしてインストールする必要があります。
IAPPlacements 、Products 、Promos の設定手順に従ってください。ただし、IAP製品を設定する際には、クリエイティブアセットをアップロードしないようにしてください。
SDKは、プロモーションアセットのインタラクションを処理するためのメソッドを備えたNative Promoアダプタインターフェイスを提供します。カスタムスクリプトでこれらのメソッドを使用して、Promoの開始、終了、および購入フローの開始をSDKに通知します。
開発者ごとにNative Promoの実装は大きく異なります。以下の抽象的なサンプルコードでは、ある実装を示しています。
using UnityEngine.Monetization;
public class NativePromoDisplay : MonoBehaviour {
PlacementContent placementContent = Monetization.GetPlacementContent (placementId);
PromoAdPlacementContent promoContent = placementContent as PromoAdPlacementContent;
INativePromoAdapter adapter = Monetization.CreateNativePromoAdapter (promoContent);
void ShowPromo () {
LogPromoInfo ();
// Use promoContent’s associated Product ID (e.g. adapter.metadata.premiumProduct.productID) to determine which assets to show
// Call adapter.OnShown () to tell the SDK the Promo has started, then execute your custom display for those assets
// Call adapter.OnClicked () to tell the SDK the player clicked the purchase button and to initiate the purchase flow
// Call adapter.OnClosed () to tell the SDK the Promo has ended
}
void LogPromoInfo () {
Debug.LogFormat ("Product ID: \t{0}", adapter.metadata.premiumProduct.productId);
Debug.LogFormat ("Localized Title: \t{0}", adapter.metadata.premiumProduct.localizedTitle);
Debug.LogFormat ("Localized Description: \t{0}", adapter.metadata.premiumProduct.localizedDescription);
Debug.LogFormat ("ISO Currency Code: \t{0}", adapter.metadata.premiumProduct.isoCurrencyCode);
Debug.LogFormat ("Localized Price: \t{0}", adapter.metadata.premiumProduct.localizedPrice);
Debug.LogFormat ("Localized Price String: \t{0}", adapter.metadata.premiumProduct.localizedPriceString);
}
}
PromoAdPlacementContent
ShowAdPlacementContent
クラスを拡張し、IAP Promo コンテンツの機能を提供します。
Unity IAP Productオブジェクトです。
プロパティ | 検索方法 | 説明 |
---|---|---|
string productId |
GetProductId () |
本製品の内部参照ID。 |
文字列 localizedTitle |
GetlocalizedTitle () |
店頭でのUIを目的とした、消費者向けの本製品の名称です。 |
string localizedPriceString |
GetLocalizedPriceString () |
店舗のUIを目的とした、通貨記号を含む消費者向けの価格文字列。 |
ダブル localizedPrice |
GetLocalizedPrice () |
本製品の価格に対する内部システムの値です。 |
string isoCurrencyCode |
GetIsoCurrencyCode () |
本製品のローカライズされた通貨のISOコード。 |
string localizedDescription |
GetLocalizedDescription () |
消費者向けの商品説明で、店舗のUIのためのものです。 |
string productType |
GetProductType () |
Unityは、「Consumable」、「Non-consumable」、「Subscription」の各製品タイプをサポートしています。 |
Productプロパティの詳細については、「Defining Products」のドキュメントを参照してください 。
INativePromoAdapter adapter = Monetization.CreateNativePromoAdapter (promoContent); ```
このインターフェースは、ユーザーによるプロモーション用アセットの操作を行うためのアクセスメソッドを提供します。これらのメソッドを使用して、カスタムアセットを渡し、期待される動作を定義します。
このプロパティは、アダプタを介して渡された PromoAdPlaceContent
オブジェクトの情報を含みます。
public struct PromoMetadata {
public Product premiumProduct;
}
public PromoMetadata metadata { get; };
例:
string cc = nativePromoAdapter.metadata.premiumProduct.isoCurrencyCode;
Promoが表示されたときにこの関数を呼び出します。プロモーションアセットを表示するためのカスタムメソッドが含まれている必要があります。
void OnShown ();
プレイヤーがPromoのオファーを解除したときにこの関数を呼び出します。
void OnClosed ();
プレイヤーが本製品を購入するためのボタンをクリックしたら、この関数を呼び出します。これにより、購入フローが開始されます。
void OnClicked ();
開発者ごとにNative Promoの実装は大きく異なります。以下の抽象的なサンプルコードでは、ある実装を示しています。
@interface ViewController: UIViewController <USRVUnityPurchasingDelegate>
-(void) showPromo: (UMONPromoAdPlacementContent *) placementContent {
self.nativePromoAdapter = [[UMONNativePromoAdapter alloc] initWithPromo: placementContent];
UMONPromoMetaData *metaData = placementContent.metadata;
UPURProduct *product = metaData.premiumProduct;
NSString *price = (product == nil || product.localizedPriceString == nil) ? @"$0.99": product.localizedPriceString;
self.nativePromoView.hidden = NO;
NSString *title = [NSString stringWithFormat: @"Buy for only %@", price];
[self.purchaseButton setTitle: title forState: UIControlStateNormal];
[self.nativePromoAdapter promoDidShow];
}
// If the player clicked the purchase button:
(IBAction) purchaseButtonTapped: (id) sender {
[self.nativePromoAdapter promoDidClick];
[self.nativePromoAdapter promoDidClose];
self.nativePromoView.hidden = YES;
}
// If the player closed the promotional asset:
-(IBAction) promoCloseButtonTapped: (id) sender {
self.nativePromoView.hidden = YES;
[self.nativePromoAdapter promoDidClose];
}
- (void) loadProducts: (UnityPurchasingLoadProductsCompletionHandler) completionHandler {
// Retrieve your Products list (see purchasing integration docs)
}
- (void) purchaseProduct: (NSString *) productId
// Insert logic for successful or failed product purchase (see purchasing integration docs)
}
ここで参照されている USRVUnityPurchasingDelegate
クラスの詳細については、purchasing integration for iOS のドキュメントをお読みください。
RewardablePlacementContent
クラスを拡張し、ビデオ広告コンテンツの機能を提供します。
Unity IAP Productオブジェクトです。
プロパティ | 説明 |
---|---|
@property (strong, nonatomic, readonly) NSString *productId |
本製品の内部参照ID。 |
@property (strong, nonatomic, readonly) NSString *localizedTitle () |
店頭でのUIを目的とした、消費者向けの本製品の名称です。 |
@property (strong, nonatomic, readonly) NSString *localizedPriceString |
店舗のUIを目的とした、通貨記号を含む消費者向けの価格文字列。 |
@property (nonatomic, readonly) double *localizedPrice |
本製品の価格に対する内部システムの値です。 |
@property (strong, nonatomic, readonly) NSString *isoCurrencyCode |
本製品のローカライズされた通貨のISOコード。 |
@property (strong, nonatomic, readonly) NSString *localizedDescription |
消費者向けの商品説明で、店舗のUIのためのものです。 |
@property (strong, nonatomic, readonly) NSString *productType |
Unityは、「Consumable」、「Non-consumable」、「Subscription」の各製品タイプをサポートしています。 |
Productプロパティの詳細については、「Defining Products」のドキュメントを参照してください 。
-(instancetype) initWithPromo:(UMONPromoAdPlacementContent *) promo; ```
このデリゲートは、ユーザーがプロモーション用アセットを操作するためのアクセスメソッドを提供します。これらのメソッドを使用して、カスタムアセットを渡し、期待される動作を定義します。
このプロパティは、アダプタを介して渡された UMONPromoAdPlacementContent
オブジェクトの情報を含みます。
@interface UMONPromoAdPlacementContent: UMONShowAdPlacementContent
-(instancetype) initWithPlacementId: (NSString *) placementId withParams: (NSDictionary *) params;
@property (nonatomic, strong, readonly) UMONPromoMetaData *metadata;
@end
Promoが表示されたらこの関数を呼び出します。この関数には、プロモーションアセットを表示する独自のメソッドを含める必要があります。
-(void) promoDidShow;
-(void) promoDidShow: (UMONNativePromoShowType) showType;
<a name="iOSpromoDidClose"></a>
#### promoDidClose
プレイヤーがPromoのオファーを解除したときにこの関数を呼び出します。
-(void) promoDidClose; ```
promoDidClick
プレイヤーが本製品を購入するためのボタンをクリックしたら、この関数を呼び出します。これにより、購入フローが開始されます。
-(void) promoDidClick;
開発者ごとにNative Promoの実装は大きく異なります。以下の抽象的なサンプルコードでは、ある実装を示しています。
UnityPurchasing.setAdapter (new UnityPurchasingAdapter ());
private class UnityPurchasingAdapter implements IPurchasingAdapter {
@Override
public void retrieveProducts (IRetrieveProductsListener listener) {
// Retrieve your Products list (see purchasing integration docs)
}
@Override
public void onPurchase (String productID, ITransactionListener listener, Map<String, Object> extras) {
// Insert logic for successful or failed product purchase (see purchasing integration docs)
}
private void showPromo (final PromoAdPlacementContent placementContent) {
final NativePromoAdapter nativePromoAdapter = new NativePromoAdapter (placementContent);
PromoMetadata metadata = placementContent.getMetadata ();
Product product = metadata.getPremiumProduct ();
String price = product == null ? "$0.99": product.getLocalizedPriceString ();
final View root = getLayoutInflater ().inflate (R.layout.unitymonetization_native_promo, (ViewGroup) findViewById (R.id.unityads_example_layout_root));
Button buyButton = root.findViewById(R.id.native_promo_buy_button);
Button closeButton = root.findViewById (R.id.native_promo_close_button);
buyButton.setText ("Buy now for only " + price + "!");
nativePromoAdapter.onShown();
buyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick (View v) {
// Do purchase then call
nativePromoAdapter.onClosed ();
((ViewGroup)root).removeView (findViewById (R.id.native_promo_root));
}
});
closeButton.setOnClickListener (new View.OnClickListener () {
@Override
public void onClick(View v) {
nativePromoAdapter.onClosed ();
((ViewGroup)root).removeView (findViewById (R.id.native_promo_root));
}
});
}
ここで参照している UnityPurchasingAdapter
クラスの詳細については、purchasing integration for Android のドキュメントをお読みください。
PromoAdPlacementContent
<a name="AndroidProduct"></a>
#### 製品
Unity IAP製品のオブジェクトです。
| **プロパティ** | **検索方法** | **説明** |
| -------- | ---------------- | ----------- |
| ```String productId``` | ```getProductId ()``` | 本製品の内部参照ID。 |
| ```String localizedTitle``` | ```getlocalizedTitle ()``` | 店頭でのUIを目的とした、消費者向けの本製品の名称です。 |
| ```String localizedPriceString``` | ```getLocalizedPriceString ()``` | 店舗のUIを目的とした、通貨記号を含む消費者向けの価格文字列。 |
| ```ダブル localizedPrice``` | ```getLocalizedPrice ()``` | 本製品の価格に対する内部システムの値です。 |
| ```String isoCurrencyCode``` | ```getIsoCurrencyCode ()``` | 本製品のローカライズされた通貨のISOコード。 |
| ```String localizedDescription``` | ```getLocalizedDescription ()``` | 消費者向けの商品説明で、店舗のUIのためのものです。 |
| ```String productType``` | ```getProductType ()``` | Unityは、「Consumable」、「Non-consumable」、「Subscription」の各製品タイプをサポートしています。 |
Productプロパティの詳細については、[「Defining Products」のドキュメントを参照してください](UnityIAPDefiningProducts.html) 。
<a name="AndroidNativePromoAdapter"></a>
#### NativePromoAdapter
このデリゲートは、ユーザーがプロモーション用アセットを操作するためのアクセスメソッドを提供します。これらのメソッドを使用して、カスタム アセットを渡し、期待される動作を定義します。 ```PromoAdPlacementContent``` オブジェクトを ```NativePromoAdapter``` 関数に渡して、新しいアダプタを作成します。たとえば、以下のようになります。
final NativePromoAdapter nativePromoAdapter = new NativePromoAdapter (placementContent); ```
このプロパティは、アダプタを介して渡された PromoAdPlaceContent
オブジェクトの情報を含みます。
public PromoMetadata getMetadata ();
Promoが表示されたときにこの関数を呼び出します。プロモーションアセットを表示するためのカスタムメソッドが含まれている必要があります。
public void onShown (NativePromoShowType type);
<a name="AndroidOnClosed"></a>
#### onClosed
プレイヤーがPromoのオファーを解除したときにこの関数を呼び出します。
public void onClicked ```
プレイヤーが本製品を購入するためのボタンをクリックしたら、この関数を呼び出します。これにより、購入フローが開始されます。
public void promoClicked;
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.