Unity/課金/復元
提供: 初心者エンジニアの簡易メモ
googleとappleの復元機能
public class IAPDemo : IStoreListener
{
private IStoreController m_Controller;
private bool m_IsGooglePlayStoreSelected;
private IAppleExtensions m_AppleExtensions;
private IGooglePlayStoreExtensions m_GooglePlayStoreExtensions;
public void Init()
{
var module = StandardPurchasingModule.Instance();
m_IsGooglePlayStoreSelected =
Application.platform == RuntimePlatform.Android && module.appStore == AppStore.GooglePlay;
}
/// <summary>
/// This will be called when Unity IAP has finished initialising.
/// </summary>
public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
{
m_Controller = controller;
m_AppleExtensions = extensions.GetExtension<IAppleExtensions>();
m_GooglePlayStoreExtensions = extensions.GetExtension<IGooglePlayStoreExtensions>();
}
public void RestoreButtonClick()
{
if (m_IsGooglePlayStoreSelected)
{
m_GooglePlayStoreExtensions.RestoreTransactions(OnTransactionsRestored);
}
else
{
m_AppleExtensions.RestoreTransactions(OnTransactionsRestored);
}
}
/// <summary>
/// This will be called after a call to IAppleExtensions.RestoreTransactions().
/// </summary>
private void OnTransactionsRestored(bool success)
{
Debug.Log("Transactions restored." + success);
}
公式のIAPDemo.csから抜粋
