Beispiel #1
0
        public static PurchasableVirtualItem GetPurchasableItemWithProductId(string productId)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            VirtualItem vi = null;
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getPurchasableItem", productId)) {
                vi = VirtualItem.factoryItemFromJNI(jniVirtualItem);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return((PurchasableVirtualItem)vi);
#elif UNITY_IOS && !UNITY_EDITOR
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetPurchasableItemWithProductId(productId, out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string nonConsJson = Marshal.PtrToStringAnsi(p);
            Marshal.FreeHGlobal(p);

            JSONObject obj = new JSONObject(nonConsJson);
            return((PurchasableVirtualItem)VirtualItem.factoryItemFromJSONObject(obj));
#else
            return(null);
#endif
        }
Beispiel #2
0
        public static VirtualItem GetItemByItemId(string itemId)
        {
            StoreUtils.LogDebug(TAG, "Trying to fetch an item with itemId: " + itemId);
#if UNITY_ANDROID && !UNITY_EDITOR
            VirtualItem vi = null;
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getVirtualItem", itemId)) {
                vi = VirtualItem.factoryItemFromJNI(jniVirtualItem);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(vi);
#elif UNITY_IOS && !UNITY_EDITOR
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetItemByItemId(itemId, out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string json = Marshal.PtrToStringAnsi(p);
            Marshal.FreeHGlobal(p);

            StoreUtils.LogDebug(TAG, "Got json: " + json);

            JSONObject obj = new JSONObject(json);
            return(VirtualItem.factoryItemFromJSONObject(obj));
#else
            return(null);
#endif
        }
Beispiel #3
0
        /// <summary>
        /// Gets the purchasable item with the given <c>productId</c>.
        /// </summary>
        /// <param name="productId">Product id.</param>
        /// <returns>Purchasable virtual item with the given id.</returns>
        /// <exception cref="VirtualItemNotFoundException">Exception is thrown if item is not found.</exception>
        override protected PurchasableVirtualItem _getPurchasableItemWithProductId(string productId)
        {
            VirtualItem vi = null;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getPurchasableItem", productId)) {
                vi = VirtualItem.factoryItemFromJNI(jniVirtualItem);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return((PurchasableVirtualItem)vi);
        }
Beispiel #4
0
        /// <summary>
        /// Fetches the virtual goods of your game.
        /// </summary>
        /// <returns>All virtual goods.</returns>
        override protected List <VirtualGood> _getVirtualGoods()
        {
            List <VirtualGood> virtualGoods = new List <VirtualGood>();

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualGoods = new AndroidJavaClass("com.soomla.store.data.StoreInfo").CallStatic <AndroidJavaObject>("getGoods")) {
                for (int i = 0; i < jniVirtualGoods.Call <int>("size"); i++)
                {
                    AndroidJNI.PushLocalFrame(100);
                    using (AndroidJavaObject jniGood = jniVirtualGoods.Call <AndroidJavaObject>("get", i)) {
                        virtualGoods.Add((VirtualGood)VirtualItem.factoryItemFromJNI(jniGood));
                    }
                    AndroidJNI.PopLocalFrame(IntPtr.Zero);
                }
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(virtualGoods);
        }
Beispiel #5
0
        public static List <VirtualGood> GetVirtualGoods()
        {
            StoreUtils.LogDebug(TAG, "Trying to fetch goods");
            List <VirtualGood> virtualGoods = new List <VirtualGood>();

#if UNITY_ANDROID && !UNITY_EDITOR
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualGoods = new AndroidJavaClass("com.soomla.store.data.StoreInfo").CallStatic <AndroidJavaObject>("getGoods")) {
                for (int i = 0; i < jniVirtualGoods.Call <int>("size"); i++)
                {
                    AndroidJNI.PushLocalFrame(100);
                    using (AndroidJavaObject jniGood = jniVirtualGoods.Call <AndroidJavaObject>("get", i)) {
                        virtualGoods.Add((VirtualGood)VirtualItem.factoryItemFromJNI(jniGood));
                    }
                    AndroidJNI.PopLocalFrame(IntPtr.Zero);
                }
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS && !UNITY_EDITOR
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetVirtualGoods(out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

            string goodsJson = Marshal.PtrToStringAnsi(p);
            Marshal.FreeHGlobal(p);

            StoreUtils.LogDebug(TAG, "Got json: " + goodsJson);

            JSONObject goodsArr = new JSONObject(goodsJson);
            foreach (JSONObject obj in goodsArr.list)
            {
                virtualGoods.Add((VirtualGood)VirtualItem.factoryItemFromJSONObject(obj));
            }
#endif
            return(virtualGoods);
        }