├── .gitignore ├── Assets ├── Demo.meta ├── Demo │ ├── Demo.unity │ ├── Demo.unity.meta │ ├── PurchaseController.cs │ └── PurchaseController.cs.meta ├── IAPManager.cs └── IAPManager.cs.meta ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset └── UnityConnectSettings.asset ├── README.md └── Unity-IAPManager.unitypackage /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /AssetBundles/ 7 | /UnityPackageManager/ 8 | /Assets/AssetStoreTools* 9 | /.vscode/ 10 | 11 | # Autogenerated VS/MD solution and project files 12 | ExportedObj/ 13 | *.csproj 14 | *.unityproj 15 | *.sln 16 | *.suo 17 | *.tmp 18 | *.user 19 | *.userprefs 20 | *.pidb 21 | *.booproj 22 | *.svd 23 | 24 | # Unity3D generated meta files 25 | *.pidb.meta 26 | 27 | # Unity3D Generated File On Crash Reports 28 | sysinfo.txt 29 | 30 | # Builds 31 | *.apk -------------------------------------------------------------------------------- /Assets/Demo.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1af8d05ce44084f1697848fe76d4da51 3 | folderAsset: yes 4 | timeCreated: 1470312330 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Demo/Demo.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/Assets/Demo/Demo.unity -------------------------------------------------------------------------------- /Assets/Demo/Demo.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 801c89aca02f349809e885970f080c3e 3 | timeCreated: 1470363046 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Demo/PurchaseController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.UI; 3 | using System.Collections; 4 | 5 | public class PurchaseController : MonoBehaviour { 6 | 7 | // public 8 | public IAPManager iapManager; 9 | 10 | public Text[] itemNames; 11 | public Text[] prices; 12 | 13 | #region INITIALIZE 14 | // Use this for initialization 15 | void Awake () { 16 | // コールバックイベント登録 17 | iapManager.OnInitializedEvent = OnInitialized; 18 | iapManager.OnInitializeFailedEvent = OnInitializeFailed; 19 | iapManager.OnPurchaseCompletedEvent = OnPurchaseCompleted; 20 | iapManager.OnPurchaseFailedEvent = OnPurchaseFailed; 21 | iapManager.OnRestoreCompletedEvent = OnRestoreCompleted; 22 | } 23 | #endregion 24 | 25 | 26 | // 購入購入 27 | public void Purchase(int itemIndex) { 28 | // 購入処理 29 | iapManager.Purchase (itemIndex); 30 | } 31 | 32 | public void Restore() { 33 | // 購入処理 34 | iapManager.Restore (); 35 | } 36 | 37 | 38 | #region PURCHASE_EVENT_HANDLER 39 | 40 | // 初期化完了 41 | private void OnInitialized(IAPManager.PurchaseItemData[] items) { 42 | // 初期化完了処理 43 | int index = 0; 44 | foreach (IAPManager.PurchaseItemData item in items) { 45 | // アイテム情報の設定 46 | itemNames[index].text = item.itemName; 47 | prices[index].text = item.priceString; 48 | index++; 49 | } 50 | } 51 | 52 | // 初期化失敗 53 | private void OnInitializeFailed(string error) { 54 | // エラー処理 55 | 56 | } 57 | 58 | 59 | // 購入完了 60 | private void OnPurchaseCompleted(IAPManager.PurchaseItemData itemData) { 61 | // 購入完了処理 62 | 63 | } 64 | 65 | 66 | // 購入失敗 67 | private void OnPurchaseFailed(IAPManager.PurchaseItemData item) { 68 | // 購入失敗処理 69 | 70 | } 71 | 72 | // リストア完了 73 | private void OnRestoreCompleted () { 74 | // リストア完了処理 75 | 76 | } 77 | 78 | #endregion PURCHASE_EVENT_HANDLER 79 | } 80 | -------------------------------------------------------------------------------- /Assets/Demo/PurchaseController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2976335075c64434e996e3c6293ac20d 3 | timeCreated: 1470312380 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/IAPManager.cs: -------------------------------------------------------------------------------- 1 | // ======== 2 | // IAPManager.cs 3 | // v1.0.0 4 | // Created by Kamanii 5 | // ======== 6 | 7 | 8 | #if UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_TVOS 9 | // You must obfuscate your secrets using Window > Unity IAP > Receipt Validation Obfuscator 10 | // before receipt validation will compile in this sample. 11 | // #define RECEIPT_VALIDATION 12 | #endif 13 | 14 | using System; 15 | using System.Collections.Generic; 16 | 17 | using UnityEngine; 18 | using UnityEngine.Events; 19 | using UnityEngine.Purchasing; 20 | using UnityEngine.UI; 21 | #if RECEIPT_VALIDATION 22 | using UnityEngine.Purchasing.Security; 23 | #endif 24 | 25 | public class IAPManager : MonoBehaviour, IStoreListener { 26 | 27 | // 購入アイテムのデータ管理クラス 28 | [Serializable] 29 | public class PurchaseItemData { 30 | [SerializeField, Header("[Input Needed]")] 31 | // プロダクトID 32 | public string productId; 33 | // アイテム名 34 | public string itemName; 35 | // 消耗品・非消耗品・定期購入 36 | public ProductType productType; 37 | 38 | [SerializeField, Header("[Automatic Input]")] 39 | // アイテムの説明 40 | public string description; 41 | // コード 42 | public string currencyCode; 43 | // 価格 44 | public float price; 45 | // 価格文字列 46 | public string priceString; 47 | } 48 | 49 | // iOSセットアップ ================ 50 | [SerializeField, Header("*iOS Store Setting")] 51 | public PurchaseItemData[] iosItems; 52 | 53 | // Androidセッティング ============ 54 | [SerializeField, Header("*Android Store Setting")] 55 | // アイテムデータ 56 | public PurchaseItemData[] androidItems; 57 | // GooglePlay共通鍵文字列 58 | [SerializeField, TextArea()] 59 | public string googlePlayPublicKey = string.Empty; 60 | 61 | 62 | // デリゲート宣言 63 | public delegate void InitializedDelegate (PurchaseItemData[] items); 64 | public delegate void InitializeFailedDelegate (string error); 65 | public delegate void PurchaseDelegate (PurchaseItemData item); 66 | public delegate void RestoreDelegate (); 67 | 68 | // コールバックイベント 69 | public InitializedDelegate OnInitializedEvent; 70 | public InitializeFailedDelegate OnInitializeFailedEvent; 71 | public PurchaseDelegate OnPurchaseCompletedEvent; 72 | public PurchaseDelegate OnPurchaseFailedEvent; 73 | public RestoreDelegate OnRestoreCompletedEvent; 74 | 75 | 76 | // Unity IAP objects 77 | private IStoreController storeController; 78 | private IAppleExtensions appleExtentions; 79 | 80 | // プロダクト返却 81 | public Product[] ItemProducts { 82 | get { 83 | return storeController.products.all; 84 | } 85 | } 86 | 87 | private int selectedItemIndex = -1; // -1 == no product 88 | private bool purchaseInProgress; 89 | 90 | private Selectable m_InteractableSelectable; // Optimization used for UI state management 91 | 92 | #if RECEIPT_VALIDATION 93 | private CrossPlatformValidator validator; 94 | #endif 95 | 96 | /// 97 | /// This will be called when Unity IAP has finished initialising. 98 | /// 99 | public void OnInitialized(IStoreController controller, IExtensionProvider extensions) 100 | { 101 | storeController = controller; 102 | appleExtentions = extensions.GetExtension (); 103 | 104 | // InitUI(controller.products.all); 105 | 106 | // On Apple platforms we need to handle deferred purchases caused by Apple's Ask to Buy feature. 107 | // On non-Apple platforms this will have no effect; OnDeferred will never be called. 108 | appleExtentions.RegisterPurchaseDeferredListener(OnDeferred); 109 | 110 | Debug.Log("Available items:"); 111 | int index = 0; 112 | foreach (var item in controller.products.all) 113 | { 114 | if (item.availableToPurchase) 115 | { 116 | Debug.Log(string.Join(" - ", 117 | new[] 118 | { 119 | item.metadata.localizedTitle, 120 | item.metadata.localizedDescription, 121 | item.metadata.isoCurrencyCode, 122 | item.metadata.localizedPrice.ToString(), 123 | item.metadata.localizedPriceString 124 | })); 125 | 126 | #if UNITY_ANDROID 127 | androidItems[index].itemName = item.metadata.localizedTitle; 128 | androidItems[index].description = item.metadata.localizedDescription; 129 | androidItems[index].currencyCode = item.metadata.isoCurrencyCode; 130 | androidItems[index].price = (float)item.metadata.localizedPrice; 131 | androidItems[index].priceString = item.metadata.localizedPriceString; 132 | #elif UNITY_IOS 133 | iosItems[index].itemName = item.metadata.localizedTitle; 134 | iosItems[index].description = item.metadata.localizedDescription; 135 | iosItems[index].currencyCode = item.metadata.isoCurrencyCode; 136 | iosItems[index].price = (float)item.metadata.localizedPrice; 137 | iosItems[index].priceString = item.metadata.localizedPriceString; 138 | #endif 139 | 140 | } 141 | index++; 142 | } 143 | 144 | // Prepare model for purchasing 145 | if (storeController.products.all.Length > 0) { 146 | selectedItemIndex = -0; 147 | } 148 | 149 | 150 | // 初期化完了通知 151 | if (OnInitializedEvent != null) { 152 | Debug.Log ("初期化完了"); 153 | #if UNITY_ANDROID 154 | OnInitializedEvent (androidItems); 155 | #elif UNITY_IOS 156 | OnInitializedEvent (iosItems); 157 | #endif 158 | } 159 | } 160 | 161 | /// 162 | /// This will be called when a purchase completes. 163 | /// 164 | public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e) 165 | { 166 | Debug.Log("Purchase OK: " + e.purchasedProduct.definition.id); 167 | Debug.Log("Receipt: " + e.purchasedProduct.receipt); 168 | 169 | purchaseInProgress = false; 170 | 171 | #if RECEIPT_VALIDATION 172 | if (Application.platform == RuntimePlatform.Android || 173 | Application.platform == RuntimePlatform.IPhonePlayer || 174 | Application.platform == RuntimePlatform.OSXPlayer) { 175 | try { 176 | var result = validator.Validate(e.purchasedProduct.receipt); 177 | Debug.Log("Receipt is valid. Contents:"); 178 | foreach (IPurchaseReceipt productReceipt in result) { 179 | Debug.Log(productReceipt.productID); 180 | Debug.Log(productReceipt.purchaseDate); 181 | Debug.Log(productReceipt.transactionID); 182 | 183 | GooglePlayReceipt google = productReceipt as GooglePlayReceipt; 184 | if (null != google) { 185 | Debug.Log(google.purchaseState); 186 | Debug.Log(google.purchaseToken); 187 | } 188 | 189 | AppleInAppPurchaseReceipt apple = productReceipt as AppleInAppPurchaseReceipt; 190 | if (null != apple) { 191 | Debug.Log(apple.originalTransactionIdentifier); 192 | Debug.Log(apple.cancellationDate); 193 | Debug.Log(apple.quantity); 194 | } 195 | } 196 | } catch (IAPSecurityException) { 197 | Debug.Log("Invalid receipt, not unlocking content"); 198 | return PurchaseProcessingResult.Complete; 199 | } 200 | } 201 | #endif 202 | 203 | 204 | // アイテムデータの取得 205 | #if UNITY_ANDROID 206 | PurchaseItemData[] items = androidItems; 207 | #elif UNITY_IOS 208 | PurchaseItemData[] items = iosItems; 209 | #endif 210 | 211 | Debug.Log(string.Join(" - ", 212 | new[] 213 | { 214 | e.purchasedProduct.definition.id, 215 | e.purchasedProduct.definition.storeSpecificId, 216 | e.purchasedProduct.metadata.localizedTitle, 217 | e.purchasedProduct.metadata.localizedDescription, 218 | e.purchasedProduct.metadata.isoCurrencyCode, 219 | e.purchasedProduct.metadata.localizedPrice.ToString(), 220 | e.purchasedProduct.metadata.localizedPriceString 221 | })); 222 | 223 | // プロダクトIDの検索 224 | foreach (PurchaseItemData item in items) { 225 | // 同じプロダクトIDであれば 226 | if (item.productId == e.purchasedProduct.definition.storeSpecificId) { 227 | // 購入完了通知 228 | if (OnPurchaseCompletedEvent != null) 229 | OnPurchaseCompletedEvent (item); 230 | } 231 | } 232 | 233 | // You should unlock the content here. 234 | 235 | // Indicate we have handled this purchase, we will not be informed of it again.x 236 | return PurchaseProcessingResult.Complete; 237 | } 238 | 239 | /// 240 | /// This will be called is an attempted purchase fails. 241 | /// 242 | public void OnPurchaseFailed(Product item, PurchaseFailureReason r) 243 | { 244 | Debug.Log("Purchase failed: " + item.definition.id); 245 | Debug.Log(r); 246 | 247 | purchaseInProgress = false; 248 | 249 | 250 | // アイテムデータの取得 251 | #if UNITY_ANDROID 252 | PurchaseItemData[] items = androidItems; 253 | #elif UNITY_IOS 254 | PurchaseItemData[] items = iosItems; 255 | #endif 256 | 257 | // プロダクトIDの検索 258 | foreach (PurchaseItemData i in items) { 259 | // 同じプロダクトIDであれば 260 | if (i.productId == item.definition.storeSpecificId) { 261 | 262 | // 購入失敗通知 263 | if (OnPurchaseFailedEvent != null) 264 | OnPurchaseFailedEvent(i); 265 | } 266 | } 267 | 268 | } 269 | 270 | public void OnInitializeFailed(InitializationFailureReason error) 271 | { 272 | Debug.Log("Billing failed to initialize!"); 273 | switch (error) 274 | { 275 | case InitializationFailureReason.AppNotKnown: 276 | Debug.LogError("Is your App correctly uploaded on the relevant publisher console?"); 277 | break; 278 | case InitializationFailureReason.PurchasingUnavailable: 279 | // Ask the user if billing is disabled in device settings. 280 | Debug.Log("Billing disabled!"); 281 | break; 282 | case InitializationFailureReason.NoProductsAvailable: 283 | // Developer configuration error; check product metadata. 284 | Debug.Log("No products available for purchase!"); 285 | break; 286 | } 287 | 288 | // 初期化失敗 289 | if (OnInitializeFailedEvent != null) 290 | OnInitializeFailedEvent ("Purchase Error"); 291 | } 292 | 293 | public void Awake() { 294 | // 仮想ストアの設定 295 | var module = StandardPurchasingModule.Instance(); 296 | module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser; 297 | var builder = ConfigurationBuilder.Instance(module); 298 | 299 | // iOSとAndroidの処理分岐 300 | #if UNITY_IOS 301 | string storeName = AppleAppStore.Name; 302 | PurchaseItemData[] itemData = iosItems; 303 | #elif UNITY_ANDROID 304 | string storeName = GooglePlay.Name; 305 | PurchaseItemData[] itemData = androidItems; 306 | // GooglePlay共通鍵の設定 307 | builder.Configure().SetPublicKey(googlePlayPublicKey); 308 | #endif 309 | 310 | // プロダクトの登録 311 | for (int i = 0; i < itemData.Length; i++) { 312 | // 各データの取得 313 | string name = itemData [i].itemName; 314 | string pID = itemData [i].productId; 315 | ProductType type = itemData [i].productType; 316 | 317 | // プロダクトの登録 318 | builder.AddProduct (name, type, new IDs { 319 | { pID, storeName } 320 | }); 321 | } 322 | 323 | #if RECEIPT_VALIDATION 324 | validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.bundleIdentifier); 325 | #endif 326 | 327 | // IAP初期化 328 | UnityPurchasing.Initialize(this, builder); 329 | } 330 | 331 | /// 332 | /// This will be called after a call to IAppleExtensions.RestoreTransactions(). 333 | /// 334 | private void OnTransactionsRestored(bool success) 335 | { 336 | Debug.Log("Transactions restored."); 337 | 338 | // リストア完了通知 339 | if (OnRestoreCompletedEvent != null) 340 | OnRestoreCompletedEvent (); 341 | } 342 | 343 | /// 344 | /// iOS Specific. 345 | /// This is called as part of Apple's 'Ask to buy' functionality, 346 | /// when a purchase is requested by a minor and referred to a parent 347 | /// for approval. 348 | /// 349 | /// When the purchase is approved or rejected, the normal purchase events 350 | /// will fire. 351 | /// 352 | /// Item. 353 | private void OnDeferred(Product item) 354 | { 355 | Debug.Log("Purchase deferred: " + item.definition.id); 356 | } 357 | 358 | 359 | 360 | 361 | #region PUBLIC_ACCESS_METHOD 362 | // ============== 363 | // 外部からアクセスする必要のあるメソッド 364 | 365 | // アイテム購入処理 366 | public void Purchase (int index) { 367 | if (purchaseInProgress == true) { 368 | return; 369 | } 370 | 371 | storeController.InitiatePurchase(storeController.products.all[index]); 372 | 373 | // Don't need to draw our UI whilst a purchase is in progress. 374 | // This is not a requirement for IAP Applications but makes the demo 375 | // scene tidier whilst the fake purchase dialog is showing. 376 | purchaseInProgress = true; 377 | } 378 | 379 | // 非消耗品アイテムのリストア処理 380 | public void Restore () { 381 | appleExtentions.RestoreTransactions(OnTransactionsRestored); 382 | } 383 | 384 | #endregion PUBLIC_ACCESS_METHOD 385 | } 386 | -------------------------------------------------------------------------------- /Assets/IAPManager.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e6c95d7be09dd4c7786a4d710804f375 3 | timeCreated: 1470312340 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 2017.3.0p3 2 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Unity IAPManager 2 | UnityIAPを個人的に使いやすくまとめたものです。
3 | iOS/Androidのみ対応です。 4 | 5 | #### 自プロジェクトでの使用 6 | 同封の**Unity-IAPManager.unitypackage**をそのままインポートするだけです。
7 | IAPManagerを使用するために*Window>Service*からIn-App Purchasingを有効にし、UnityIAPパッケージをインポートしてください。
8 | 9 | # 使い方 10 | 11 | #### アイテム情報の登録 12 | IAPManagerを空のGameObjectにアタッチし、Inspectorで各ストアアイテムの情報を登録します。
13 | iOSとAndroid二つの項目が用意されているのでそれぞれ入力します。
14 | ![Imgur](https://i.imgur.com/frU9CWR.png) 15 |
16 | 17 | #### イベントハンドラの設定 18 | IAPManagerの各処理のイベントを受け取るためにイベントハンドラを設定します。 19 | 20 | public IAPManager iapManager; 21 | void Awake () { 22 | iapManager.OnInitializedEvent = OnInitialized; 23 | iapManager.OnInitializeFailedEvent = OnInitializeFailed; 24 | iapManager.OnPurchaseCompletedEvent = OnPurchaseCompleted; 25 | iapManager.OnPurchaseFailedEvent = OnPurchaseFailed; 26 | iapManager.OnRestoreCompletedEvent = OnRestoreCompleted; 27 | } 28 | 29 | // 初期化完了 30 | private void OnInitialized(IAPManager.PurchaseItemData[] items) { 31 | // 初期化完了処理 32 | } 33 | 34 | // 初期化失敗 35 | private void OnInitializeFailed(string error) { 36 | // エラー処理 37 | } 38 | 39 | // 購入完了 40 | private void OnPurchaseCompleted(IAPManager.PurchaseItemData itemData) { 41 | // 購入完了処理 42 | } 43 | 44 | // 購入失敗 45 | private void OnPurchaseFailed(IAPManager.PurchaseItemData item) { 46 | // 購入失敗処理 47 | } 48 | 49 | // リストア完了 50 | private void OnRestoreCompleted () { 51 | // リストア完了処理 52 | } 53 | 54 | 55 | #### 購入処理 56 | IAPManagerクラスのPurchaseクラスにアイテムのindexを引数として渡します。 57 | 58 | // アイテム購入ボタンが押された 59 | public void OnTapPurchaseButton (int itemIndex) { 60 | // 購入 61 | iapManager.Purchase (itemIndex); 62 | } 63 | 64 | 65 | #### リストア(iOSのみ) 66 | 購入済みのアイテムを復元します。
67 | 復元されたアイテム情報は*OnPurchaseCompletedEvent*にて受け取ります。 68 | 69 | // アイテム購入ボタンが押された 70 | public void OnTapRestoreButton () { 71 | // リストア 72 | iapManager.Restore (); 73 | } 74 | 75 | 76 | ## ビルド環境 77 | Unity 2017.3.0p3
78 | macOS High Sierra 10.13.3 79 | -------------------------------------------------------------------------------- /Unity-IAPManager.unitypackage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kamanii24/Unity-IAPManager/4e570d7701097ddbbf72ac2c2e71bdeaebfc3c53/Unity-IAPManager.unitypackage --------------------------------------------------------------------------------