GithubHelp home page GithubHelp logo

unity-iapmanager's Introduction

Unity IAPManager

UnityIAPを個人的に使いやすくまとめたものです。
iOS/Androidのみ対応です。

自プロジェクトでの使用

同封のUnity-IAPManager.unitypackageをそのままインポートするだけです。
IAPManagerを使用するためにWindow>ServiceからIn-App Purchasingを有効にし、UnityIAPパッケージをインポートしてください。

使い方

アイテム情報の登録

IAPManagerを空のGameObjectにアタッチし、Inspectorで各ストアアイテムの情報を登録します。
iOSとAndroid二つの項目が用意されているのでそれぞれ入力します。
Imgur

イベントハンドラの設定

IAPManagerの各処理のイベントを受け取るためにイベントハンドラを設定します。

  public IAPManager iapManager;
  void Awake () {
     iapManager.OnInitializedEvent = OnInitialized;
     iapManager.OnInitializeFailedEvent = OnInitializeFailed;
     iapManager.OnPurchaseCompletedEvent = OnPurchaseCompleted;
     iapManager.OnPurchaseFailedEvent = OnPurchaseFailed;
     iapManager.OnRestoreCompletedEvent	= OnRestoreCompleted;
  }
  
  // 初期化完了
  private void OnInitialized(IAPManager.PurchaseItemData[] items) {
     // 初期化完了処理
  }

  // 初期化失敗
  private void OnInitializeFailed(string error) {
     // エラー処理
  }

  // 購入完了
  private void OnPurchaseCompleted(IAPManager.PurchaseItemData itemData) {
     // 購入完了処理
  }

  // 購入失敗
  private void OnPurchaseFailed(IAPManager.PurchaseItemData item) {
      // 購入失敗処理
  }

  // リストア完了
  private void OnRestoreCompleted () {
      // リストア完了処理
  }

購入処理

IAPManagerクラスのPurchaseクラスにアイテムのindexを引数として渡します。

  // アイテム購入ボタンが押された
  public void OnTapPurchaseButton (int itemIndex) {
      // 購入
      iapManager.Purchase (itemIndex);
  }

リストア(iOSのみ)

購入済みのアイテムを復元します。
復元されたアイテム情報はOnPurchaseCompletedEventにて受け取ります。

  // アイテム購入ボタンが押された
  public void OnTapRestoreButton () {
      // リストア
      iapManager.Restore ();
  }

ビルド環境

Unity 2017.3.0p3
macOS High Sierra 10.13.3

unity-iapmanager's People

Contributors

kamanii24 avatar

Stargazers

 avatar chimera kang avatar  avatar jay down avatar Jack avatar Mike avatar  avatar  avatar yangmingzhe avatar yoshitetsu avatar TanakaToshiki (JP) avatar Li Min avatar  avatar

Watchers

Jack avatar James Cloos avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.