facebook twitter hatena line email

「Unity/課金/復元」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==googleとappleの復元機能== <pre> public class IAPDemo : IStoreListener { private IStoreController m_Controller; private IAppleExtensions m_AppleExtensions...」)
 
(googleとappleの復元機能)
 
行4: 行4:
 
{
 
{
 
     private IStoreController m_Controller;
 
     private IStoreController m_Controller;
 
+
    private bool m_IsGooglePlayStoreSelected;
 
     private IAppleExtensions m_AppleExtensions;
 
     private IAppleExtensions m_AppleExtensions;
 
     private IGooglePlayStoreExtensions m_GooglePlayStoreExtensions;
 
     private IGooglePlayStoreExtensions m_GooglePlayStoreExtensions;
行10: 行10:
 
     public void Init()
 
     public void Init()
 
     {
 
     {
 +
        var module = StandardPurchasingModule.Instance();
 
         m_IsGooglePlayStoreSelected =
 
         m_IsGooglePlayStoreSelected =
 
             Application.platform == RuntimePlatform.Android && module.appStore == AppStore.GooglePlay;
 
             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()
 
     public void RestoreButtonClick()
 
     {
 
     {
行24: 行34:
 
             m_AppleExtensions.RestoreTransactions(OnTransactionsRestored);
 
             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);
 
     }
 
     }
 
</pre>
 
</pre>
 
公式のIAPDemo.csから抜粋
 
公式のIAPDemo.csから抜粋

2020年7月20日 (月) 05:14時点における最新版

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から抜粋