Beispiel #1
0
        protected virtual void _buyMarketItem(string productId, string payload)
        {
#if UNITY_EDITOR
            PurchasableVirtualItem item = StoreInfo.GetPurchasableItemWithProductId(productId);
            if (item == null)
            {
                throw new VirtualItemNotFoundException("ProductId", productId);
            }

            // in the editor we just give the item... no real market.
            item.Give(1);
#endif
        }
Beispiel #2
0
        protected virtual void _buyMarketItem(string productId, string payload)
        {
#if UNITY_EDITOR
            PurchasableVirtualItem item = StoreInfo.GetPurchasableItemWithProductId(productId);
            if (item == null)
            {
                throw new VirtualItemNotFoundException("ProductId", productId);
            }

            // simulate onMarketPurchaseStarted event
            var eventJSON = new JSONObject();
            eventJSON.AddField("itemId", item.ItemId);
            eventJSON.AddField("payload", payload);
            StoreEvents.Instance.onMarketPurchaseStarted(eventJSON.print());

            // simulate events as they happen on the device
            // the order is :
            //    onMarketPurchase
            //    give item
            //    onItemPurchase
            StoreEvents.Instance.RunLater(() => {
                eventJSON = new JSONObject();
                eventJSON.AddField("itemId", item.ItemId);
                eventJSON.AddField("payload", payload);
                var extraJSON = new JSONObject();
                        #if UNITY_IOS
                extraJSON.AddField("receipt", "fake_receipt_abcd1234");
                extraJSON.AddField("token", "fake_token_zyxw9876");
                        #elif UNITY_ANDROID
                extraJSON.AddField("orderId", "fake_orderId_abcd1234");
                extraJSON.AddField("purchaseToken", "fake_purchaseToken_zyxw9876");
                        #endif
                eventJSON.AddField("extra", extraJSON);
                StoreEvents.Instance.onMarketPurchase(eventJSON.print());

                // in the editor we just give the item... no real market.
                item.Give(1);

                // We have to make sure the ItemPurchased event will be fired AFTER the balance/currency-changed events.
                StoreEvents.Instance.RunLater(() => {
                    eventJSON = new JSONObject();
                    eventJSON.AddField("itemId", item.ItemId);
                    eventJSON.AddField("payload", payload);
                    StoreEvents.Instance.onItemPurchased(eventJSON.print());
                });
            });
#endif
        }