IAPDemo.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. #if UNITY_ANDROID || UNITY_IPHONE || UNITY_STANDALONE_OSX || UNITY_TVOS
  2. // You must obfuscate your secrets using Window > Unity IAP > Receipt Validation Obfuscator
  3. // before receipt validation will compile in this sample.
  4. // #define RECEIPT_VALIDATION
  5. #endif
  6. using System;
  7. using System.Collections.Generic;
  8. using UnityEngine;
  9. using UnityEngine.Events;
  10. using UnityEngine.Purchasing;
  11. using UnityEngine.UI;
  12. #if RECEIPT_VALIDATION
  13. using UnityEngine.Purchasing.Security;
  14. #endif
  15. /// <summary>
  16. /// An example of basic Unity IAP functionality.
  17. /// To use with your account, configure the product ids (AddProduct)
  18. /// and Google Play key (SetPublicKey).
  19. /// </summary>
  20. [AddComponentMenu("Unity IAP/Demo")]
  21. public class IAPDemo : MonoBehaviour, IStoreListener
  22. {
  23. // Unity IAP objects
  24. private IStoreController m_Controller;
  25. private IAppleExtensions m_AppleExtensions;
  26. private IMoolahExtension m_MoolahExtensions;
  27. private ISamsungAppsExtensions m_SamsungExtensions;
  28. private IMicrosoftExtensions m_MicrosoftExtensions;
  29. #pragma warning disable 0414
  30. private bool m_IsGooglePlayStoreSelected;
  31. #pragma warning restore 0414
  32. private bool m_IsSamsungAppsStoreSelected;
  33. private bool m_IsCloudMoolahStoreSelected;
  34. private string m_LastTransationID;
  35. private string m_LastReceipt;
  36. private string m_CloudMoolahUserName;
  37. private bool m_IsLoggedIn = false;
  38. private int m_SelectedItemIndex = -1; // -1 == no product
  39. private bool m_PurchaseInProgress;
  40. private Selectable m_InteractableSelectable; // Optimization used for UI state management
  41. #if RECEIPT_VALIDATION
  42. private CrossPlatformValidator validator;
  43. #endif
  44. /// <summary>
  45. /// This will be called when Unity IAP has finished initialising.
  46. /// </summary>
  47. public void OnInitialized(IStoreController controller, IExtensionProvider extensions)
  48. {
  49. m_Controller = controller;
  50. m_AppleExtensions = extensions.GetExtension<IAppleExtensions> ();
  51. m_SamsungExtensions = extensions.GetExtension<ISamsungAppsExtensions> ();
  52. m_MoolahExtensions = extensions.GetExtension<IMoolahExtension> ();
  53. m_MicrosoftExtensions = extensions.GetExtension<IMicrosoftExtensions> ();
  54. InitUI(controller.products.all);
  55. // On Apple platforms we need to handle deferred purchases caused by Apple's Ask to Buy feature.
  56. // On non-Apple platforms this will have no effect; OnDeferred will never be called.
  57. m_AppleExtensions.RegisterPurchaseDeferredListener(OnDeferred);
  58. Debug.Log("Available items:");
  59. foreach (var item in controller.products.all)
  60. {
  61. if (item.availableToPurchase)
  62. {
  63. Debug.Log(string.Join(" - ",
  64. new[]
  65. {
  66. item.metadata.localizedTitle,
  67. item.metadata.localizedDescription,
  68. item.metadata.isoCurrencyCode,
  69. item.metadata.localizedPrice.ToString(),
  70. item.metadata.localizedPriceString,
  71. item.transactionID,
  72. item.receipt
  73. }));
  74. }
  75. }
  76. // Prepare model for purchasing
  77. if (m_Controller.products.all.Length > 0)
  78. {
  79. m_SelectedItemIndex = 0;
  80. }
  81. // Populate the product menu now that we have Products
  82. for (int t = 0; t < m_Controller.products.all.Length; t++)
  83. {
  84. var item = m_Controller.products.all[t];
  85. var description = string.Format("{0} - {1}", item.metadata.localizedTitle, item.metadata.localizedPriceString);
  86. // NOTE: my options list is created in InitUI
  87. GetDropdown().options[t] = new Dropdown.OptionData(description);
  88. }
  89. // Ensure I render the selected list element
  90. GetDropdown().RefreshShownValue();
  91. // Now that I have real products, begin showing product purchase history
  92. UpdateHistoryUI();
  93. LogProductDefinitions();
  94. }
  95. /// <summary>
  96. /// This will be called when a purchase completes.
  97. /// </summary>
  98. public PurchaseProcessingResult ProcessPurchase(PurchaseEventArgs e)
  99. {
  100. Debug.Log("Purchase OK: " + e.purchasedProduct.definition.id);
  101. Debug.Log("Receipt: " + e.purchasedProduct.receipt);
  102. m_LastTransationID = e.purchasedProduct.transactionID;
  103. m_LastReceipt = e.purchasedProduct.receipt;
  104. m_PurchaseInProgress = false;
  105. // Now that my purchase history has changed, update its UI
  106. UpdateHistoryUI();
  107. #if RECEIPT_VALIDATION
  108. // Local validation is available for GooglePlay and Apple stores
  109. if (m_IsGooglePlayStoreSelected ||
  110. Application.platform == RuntimePlatform.IPhonePlayer ||
  111. Application.platform == RuntimePlatform.OSXPlayer ||
  112. Application.platform == RuntimePlatform.tvOS) {
  113. try {
  114. var result = validator.Validate(e.purchasedProduct.receipt);
  115. Debug.Log("Receipt is valid. Contents:");
  116. foreach (IPurchaseReceipt productReceipt in result) {
  117. Debug.Log(productReceipt.productID);
  118. Debug.Log(productReceipt.purchaseDate);
  119. Debug.Log(productReceipt.transactionID);
  120. GooglePlayReceipt google = productReceipt as GooglePlayReceipt;
  121. if (null != google) {
  122. Debug.Log(google.purchaseState);
  123. Debug.Log(google.purchaseToken);
  124. }
  125. AppleInAppPurchaseReceipt apple = productReceipt as AppleInAppPurchaseReceipt;
  126. if (null != apple) {
  127. Debug.Log(apple.originalTransactionIdentifier);
  128. Debug.Log(apple.subscriptionExpirationDate);
  129. Debug.Log(apple.cancellationDate);
  130. Debug.Log(apple.quantity);
  131. }
  132. }
  133. } catch (IAPSecurityException) {
  134. Debug.Log("Invalid receipt, not unlocking content");
  135. return PurchaseProcessingResult.Complete;
  136. }
  137. }
  138. #endif
  139. // CloudMoolah purchase completion / finishing currently requires using the API
  140. // extension IMoolahExtension.RequestPayout to finish a transaction.
  141. if (m_IsCloudMoolahStoreSelected)
  142. {
  143. // Finish transaction with CloudMoolah server
  144. m_MoolahExtensions.RequestPayOut(e.purchasedProduct.transactionID,
  145. (string transactionID, RequestPayOutState state, string message) => {
  146. if (state == RequestPayOutState.RequestPayOutSucceed) {
  147. // Finally, finish transaction with Unity IAP's local
  148. // transaction log, recording the transaction id there
  149. m_Controller.ConfirmPendingPurchase(e.purchasedProduct);
  150. // Unlock content here.
  151. } else {
  152. Debug.Log("RequestPayOut: failed. transactionID: " + transactionID +
  153. ", state: " + state + ", message: " + message);
  154. // Finishing failed. Retry later.
  155. }
  156. });
  157. }
  158. // You should unlock the content here.
  159. // Indicate if we have handled this purchase.
  160. // PurchaseProcessingResult.Complete: ProcessPurchase will not be called
  161. // with this product again, until next purchase.
  162. // PurchaseProcessingResult.Pending: ProcessPurchase will be called
  163. // again with this product at next app launch. Later, call
  164. // m_Controller.ConfirmPendingPurchase(Product) to complete handling
  165. // this purchase. Use to transactionally save purchases to a cloud
  166. // game service.
  167. return PurchaseProcessingResult.Complete;
  168. }
  169. /// <summary>
  170. /// This will be called is an attempted purchase fails.
  171. /// </summary>
  172. public void OnPurchaseFailed(Product item, PurchaseFailureReason r)
  173. {
  174. Debug.Log("Purchase failed: " + item.definition.id);
  175. Debug.Log(r);
  176. m_PurchaseInProgress = false;
  177. }
  178. public void OnInitializeFailed(InitializationFailureReason error)
  179. {
  180. Debug.Log("Billing failed to initialize!");
  181. switch (error)
  182. {
  183. case InitializationFailureReason.AppNotKnown:
  184. Debug.LogError("Is your App correctly uploaded on the relevant publisher console?");
  185. break;
  186. case InitializationFailureReason.PurchasingUnavailable:
  187. // Ask the user if billing is disabled in device settings.
  188. Debug.Log("Billing disabled!");
  189. break;
  190. case InitializationFailureReason.NoProductsAvailable:
  191. // Developer configuration error; check product metadata.
  192. Debug.Log("No products available for purchase!");
  193. break;
  194. }
  195. }
  196. public void Awake()
  197. {
  198. var module = StandardPurchasingModule.Instance();
  199. // The FakeStore supports: no-ui (always succeeding), basic ui (purchase pass/fail), and
  200. // developer ui (initialization, purchase, failure code setting). These correspond to
  201. // the FakeStoreUIMode Enum values passed into StandardPurchasingModule.useFakeStoreUIMode.
  202. module.useFakeStoreUIMode = FakeStoreUIMode.StandardUser;
  203. var builder = ConfigurationBuilder.Instance(module);
  204. // This enables the Microsoft IAP simulator for local testing.
  205. // You would remove this before building your release package.
  206. builder.Configure<IMicrosoftConfiguration>().useMockBillingSystem = true;
  207. builder.Configure<IGooglePlayConfiguration>().SetPublicKey("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA2O/9/H7jYjOsLFT/uSy3ZEk5KaNg1xx60RN7yWJaoQZ7qMeLy4hsVB3IpgMXgiYFiKELkBaUEkObiPDlCxcHnWVlhnzJBvTfeCPrYNVOOSJFZrXdotp5L0iS2NVHjnllM+HA1M0W2eSNjdYzdLmZl1bxTpXa4th+dVli9lZu7B7C2ly79i/hGTmvaClzPBNyX+Rtj7Bmo336zh2lYbRdpD5glozUq+10u91PMDPH+jqhx10eyZpiapr8dFqXl5diMiobknw9CgcjxqMTVBQHK6hS0qYKPmUDONquJn280fBs1PTeA6NMG03gb9FLESKFclcuEZtvM8ZwMMRxSLA9GwIDAQAB");
  208. m_IsGooglePlayStoreSelected = Application.platform == RuntimePlatform.Android && module.androidStore == AndroidStore.GooglePlay;
  209. // CloudMoolah Configuration setings
  210. // All games must set the configuration. the configuration need to apply on the CloudMoolah Portal.
  211. // CloudMoolah APP Key
  212. builder.Configure<IMoolahConfiguration>().appKey = "d93f4564c41d463ed3d3cd207594ee1b";
  213. // CloudMoolah Hash Key
  214. builder.Configure<IMoolahConfiguration>().hashKey = "cc";
  215. // This enables the CloudMoolah test mode for local testing.
  216. // You would remove this, or set to CloudMoolahMode.Production, before building your release package.
  217. builder.Configure<IMoolahConfiguration>().SetMode(CloudMoolahMode.AlwaysSucceed);
  218. // This records whether we are using Cloud Moolah IAP.
  219. // Cloud Moolah requires logging in to access your Digital Wallet, so:
  220. // A) IAPDemo (this) displays the Cloud Moolah GUI button for Cloud Moolah
  221. m_IsCloudMoolahStoreSelected = Application.platform == RuntimePlatform.Android && module.androidStore == AndroidStore.CloudMoolah;
  222. // Define our products.
  223. // In this case our products have the same identifier across all the App stores,
  224. // except on the Mac App store where product IDs cannot be reused across both Mac and
  225. // iOS stores.
  226. // So on the Mac App store our products have different identifiers,
  227. // and we tell Unity IAP this by using the IDs class.
  228. builder.AddProduct("100.gold.coins", ProductType.Consumable, new IDs
  229. {
  230. {"100.gold.coins.mac", MacAppStore.Name},
  231. {"000000596586", TizenStore.Name},
  232. {"com.ff", MoolahAppStore.Name},
  233. });
  234. builder.AddProduct("500.gold.coins", ProductType.Consumable, new IDs
  235. {
  236. {"500.gold.coins.mac", MacAppStore.Name},
  237. {"000000596581", TizenStore.Name},
  238. {"com.ee", MoolahAppStore.Name},
  239. });
  240. builder.AddProduct("sword", ProductType.NonConsumable, new IDs
  241. {
  242. {"sword.mac", MacAppStore.Name},
  243. {"000000596583", TizenStore.Name},
  244. });
  245. builder.AddProduct("subscription", ProductType.Subscription, new IDs
  246. {
  247. {"subscription.mac", MacAppStore.Name}
  248. });
  249. // Write Amazon's JSON description of our products to storage when using Amazon's local sandbox.
  250. // This should be removed from a production build.
  251. builder.Configure<IAmazonConfiguration>().WriteSandboxJSON(builder.products);
  252. // This enables simulated purchase success for Samsung IAP.
  253. // You would remove this, or set to SamsungAppsMode.Production, before building your release package.
  254. builder.Configure<ISamsungAppsConfiguration>().SetMode(SamsungAppsMode.AlwaysSucceed);
  255. // This records whether we are using Samsung IAP. Currently ISamsungAppsExtensions.RestoreTransactions
  256. // displays a blocking Android Activity, so:
  257. // A) Unity IAP does not automatically restore purchases on Samsung Galaxy Apps
  258. // B) IAPDemo (this) displays the "Restore" GUI button for Samsung Galaxy Apps
  259. m_IsSamsungAppsStoreSelected = Application.platform == RuntimePlatform.Android && module.androidStore == AndroidStore.SamsungApps;
  260. // This selects the GroupId that was created in the Tizen Store for this set of products
  261. // An empty or non-matching GroupId here will result in no products available for purchase
  262. builder.Configure<ITizenStoreConfiguration>().SetGroupId("100000085616");
  263. #if RECEIPT_VALIDATION
  264. validator = new CrossPlatformValidator(GooglePlayTangle.Data(), AppleTangle.Data(), Application.bundleIdentifier);
  265. #endif
  266. // Now we're ready to initialize Unity IAP.
  267. UnityPurchasing.Initialize(this, builder);
  268. }
  269. /// <summary>
  270. /// This will be called after a call to IAppleExtensions.RestoreTransactions().
  271. /// </summary>
  272. private void OnTransactionsRestored(bool success)
  273. {
  274. Debug.Log("Transactions restored.");
  275. }
  276. /// <summary>
  277. /// iOS Specific.
  278. /// This is called as part of Apple's 'Ask to buy' functionality,
  279. /// when a purchase is requested by a minor and referred to a parent
  280. /// for approval.
  281. ///
  282. /// When the purchase is approved or rejected, the normal purchase events
  283. /// will fire.
  284. /// </summary>
  285. /// <param name="item">Item.</param>
  286. private void OnDeferred(Product item)
  287. {
  288. Debug.Log("Purchase deferred: " + item.definition.id);
  289. }
  290. private void InitUI(IEnumerable<Product> items)
  291. {
  292. // Disable the UI while IAP is initializing
  293. // See also UpdateInteractable()
  294. m_InteractableSelectable = GetDropdown(); // References any one of the disabled components
  295. // Show Restore button on supported platforms
  296. if (! (Application.platform == RuntimePlatform.IPhonePlayer ||
  297. Application.platform == RuntimePlatform.OSXPlayer ||
  298. Application.platform == RuntimePlatform.tvOS ||
  299. Application.platform == RuntimePlatform.WSAPlayerX86 ||
  300. Application.platform == RuntimePlatform.WSAPlayerX64 ||
  301. Application.platform == RuntimePlatform.WSAPlayerARM ||
  302. m_IsSamsungAppsStoreSelected || m_IsCloudMoolahStoreSelected) )
  303. {
  304. GetRestoreButton().gameObject.SetActive(false);
  305. }
  306. // Show Register, Login, and Validate buttons on CloudMoolah platform
  307. GetRegisterButton().gameObject.SetActive(m_IsCloudMoolahStoreSelected);
  308. GetLoginButton().gameObject.SetActive(m_IsCloudMoolahStoreSelected);
  309. GetValidateButton().gameObject.SetActive(m_IsCloudMoolahStoreSelected);
  310. foreach (var item in items)
  311. {
  312. // Add initial pre-IAP-initialization content. Update later in OnInitialized.
  313. var description = string.Format("{0} - {1}", item.definition.id, item.definition.type);
  314. GetDropdown().options.Add(new Dropdown.OptionData(description));
  315. }
  316. // Ensure I render the selected list element
  317. GetDropdown().RefreshShownValue();
  318. GetDropdown().onValueChanged.AddListener((int selectedItem) => {
  319. Debug.Log("OnClickDropdown item " + selectedItem);
  320. m_SelectedItemIndex = selectedItem;
  321. });
  322. // Initialize my button event handling
  323. GetBuyButton().onClick.AddListener(() => {
  324. if (m_PurchaseInProgress == true) {
  325. Debug.Log("Please wait, purchasing ...");
  326. return;
  327. }
  328. // For CloudMoolah, games utilizing a connected backend game server may wish to login.
  329. // Standalone games may not need to login.
  330. if (m_IsCloudMoolahStoreSelected && m_IsLoggedIn == false)
  331. {
  332. Debug.LogWarning("CloudMoolah purchase notifications will not be forwarded server-to-server. Login incomplete.");
  333. }
  334. // Don't need to draw our UI whilst a purchase is in progress.
  335. // This is not a requirement for IAP Applications but makes the demo
  336. // scene tidier whilst the fake purchase dialog is showing.
  337. m_PurchaseInProgress = true;
  338. m_Controller.InitiatePurchase(m_Controller.products.all[m_SelectedItemIndex], "aDemoDeveloperPayload");
  339. });
  340. if (GetRestoreButton() != null)
  341. {
  342. GetRestoreButton().onClick.AddListener(() => {
  343. if (m_IsCloudMoolahStoreSelected)
  344. {
  345. if (m_IsLoggedIn == false)
  346. {
  347. Debug.LogError("CloudMoolah purchase restoration aborted. Login incomplete.");
  348. }
  349. else
  350. {
  351. // Restore abnornal transaction identifer, if Client don't receive transaction identifer.
  352. m_MoolahExtensions.RestoreTransactionID((RestoreTransactionIDState restoreTransactionIDState) => {
  353. Debug.Log("restoreTransactionIDState = " + restoreTransactionIDState.ToString());
  354. bool success =
  355. restoreTransactionIDState != RestoreTransactionIDState.RestoreFailed &&
  356. restoreTransactionIDState != RestoreTransactionIDState.NotKnown;
  357. OnTransactionsRestored(success);
  358. });
  359. }
  360. }
  361. else if (m_IsSamsungAppsStoreSelected)
  362. {
  363. m_SamsungExtensions.RestoreTransactions(OnTransactionsRestored);
  364. }
  365. else if (Application.platform == RuntimePlatform.WSAPlayerX86 ||
  366. Application.platform == RuntimePlatform.WSAPlayerX64 ||
  367. Application.platform == RuntimePlatform.WSAPlayerARM)
  368. {
  369. m_MicrosoftExtensions.RestoreTransactions();
  370. }
  371. else
  372. {
  373. m_AppleExtensions.RestoreTransactions(OnTransactionsRestored);
  374. }
  375. });
  376. }
  377. // CloudMoolah requires user registration and supports login to manage the user's
  378. // digital wallet. The CM store also supports remote receipt validation.
  379. // CloudMoolah user registration extension, to establish digital wallet
  380. // This is a "fast" registration, requiring only a password. Users may provide
  381. // more detail including an email address during the purchase flow, a "slow" registration, if desired.
  382. if (GetRegisterButton() != null)
  383. {
  384. GetRegisterButton().onClick.AddListener (() => {
  385. // Provide a unique password to establish the user's account.
  386. // Typically, connected games (with backend game servers), may already
  387. // have available a user-token, which could be supplied here.
  388. m_MoolahExtensions.FastRegister("CMPassword", RegisterSucceeded, RegisterFailed);
  389. });
  390. }
  391. // CloudMoolah user login extension, to access existing digital wallet
  392. if (GetLoginButton() != null)
  393. {
  394. GetLoginButton().onClick.AddListener (() => {
  395. m_MoolahExtensions.Login(m_CloudMoolahUserName, "CMPassword", LoginResult);
  396. });
  397. }
  398. // CloudMoolah remote purchase receipt validation, to determine if the purchase is fraudulent
  399. // NOTE: Remote validation only available for CloudMoolah currently. For local validation,
  400. // see ProcessPurchase.
  401. if (GetValidateButton() != null)
  402. {
  403. GetValidateButton ().onClick.AddListener (() => {
  404. // Remotely validate the last transaction and receipt.
  405. m_MoolahExtensions.ValidateReceipt(m_LastTransationID, m_LastReceipt,
  406. (string transactionID, ValidateReceiptState state, string message) => {
  407. Debug.Log("ValidtateReceipt transactionID:" + transactionID
  408. + ", state:" + state.ToString() + ", message:" + message);
  409. });
  410. });
  411. }
  412. }
  413. public void LoginResult (LoginResultState state, string errorMsg)
  414. {
  415. if(state == LoginResultState.LoginSucceed)
  416. {
  417. m_IsLoggedIn = true;
  418. }
  419. else
  420. {
  421. m_IsLoggedIn = false;
  422. }
  423. Debug.Log ("LoginResult: state: " + state.ToString () + " errorMsg: " + errorMsg);
  424. }
  425. public void RegisterSucceeded(string cmUserName)
  426. {
  427. Debug.Log ("RegisterSucceeded: cmUserName = " + cmUserName);
  428. m_CloudMoolahUserName = cmUserName;
  429. }
  430. public void RegisterFailed (FastRegisterError error, string errorMessage)
  431. {
  432. Debug.Log ("RegisterFailed: error = " + error.ToString() + ", errorMessage = " + errorMessage);
  433. }
  434. public void UpdateHistoryUI()
  435. {
  436. if (m_Controller == null)
  437. {
  438. return;
  439. }
  440. var itemText = "Item\n\n";
  441. var countText = "Purchased\n\n";
  442. for (int t = 0; t < m_Controller.products.all.Length; t++)
  443. {
  444. var item = m_Controller.products.all [t];
  445. // Collect history status report
  446. itemText += "\n\n" + item.definition.id;
  447. countText += "\n\n" + item.hasReceipt.ToString();
  448. }
  449. // Show history
  450. GetText(false).text = itemText;
  451. GetText(true).text = countText;
  452. }
  453. protected void UpdateInteractable()
  454. {
  455. if (m_InteractableSelectable == null)
  456. {
  457. return;
  458. }
  459. bool interactable = m_Controller != null;
  460. if (interactable != m_InteractableSelectable.interactable)
  461. {
  462. if (GetRestoreButton() != null)
  463. {
  464. GetRestoreButton().interactable = interactable;
  465. }
  466. GetBuyButton().interactable = interactable;
  467. GetDropdown().interactable = interactable;
  468. GetRegisterButton().interactable = interactable;
  469. GetLoginButton().interactable = interactable;
  470. }
  471. }
  472. public void Update()
  473. {
  474. UpdateInteractable();
  475. }
  476. private Dropdown GetDropdown()
  477. {
  478. return GameObject.Find("Dropdown").GetComponent<Dropdown>();
  479. }
  480. private Button GetBuyButton()
  481. {
  482. return GameObject.Find("Buy").GetComponent<Button>();
  483. }
  484. /// <summary>
  485. /// Gets the restore button when available
  486. /// </summary>
  487. /// <returns><c>null</c> or the restore button.</returns>
  488. private Button GetRestoreButton()
  489. {
  490. return GetButton ("Restore");
  491. }
  492. private Button GetRegisterButton()
  493. {
  494. return GetButton ("Register");
  495. }
  496. private Button GetLoginButton()
  497. {
  498. return GetButton ("Login");
  499. }
  500. private Button GetValidateButton()
  501. {
  502. return GetButton ("Validate");
  503. }
  504. private Button GetButton(string buttonName)
  505. {
  506. GameObject obj = GameObject.Find(buttonName);
  507. if (obj != null)
  508. {
  509. return obj.GetComponent <Button>();
  510. }
  511. else
  512. {
  513. return null;
  514. }
  515. }
  516. private Text GetText(bool right)
  517. {
  518. var which = right ? "TextR" : "TextL";
  519. return GameObject.Find(which).GetComponent<Text>();
  520. }
  521. private void LogProductDefinitions()
  522. {
  523. var products = m_Controller.products.all;
  524. foreach (var product in products) {
  525. #if UNITY_5_6_OR_NEWER
  526. Debug.Log(string.Format("id: {0}\nstore-specific id: {1}\ntype: {2}\nenabled: {3}\n", product.definition.id, product.definition.storeSpecificId, product.definition.type.ToString(), product.definition.enabled ? "enabled" : "disabled"));
  527. #else
  528. Debug.Log(string.Format("id: {0}\nstore-specific id: {1}\ntype: {2}\n", product.definition.id, product.definition.storeSpecificId, product.definition.type.ToString()));
  529. #endif
  530. }
  531. }
  532. }