コード例 #1
0
        public static UpgradeVG GetLastUpgradeForVirtualGood(string goodItemId)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            UpgradeVG vgu = null;
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniUpgradeVG = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getGoodLastUpgrade", goodItemId)) {
                vgu = new UpgradeVG(jniUpgradeVG);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(vgu);
#elif UNITY_IOS && !UNITY_EDITOR
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetLastUpgradeForVirtualGood(goodItemId, out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

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

            JSONObject obj = new JSONObject(json);
            return(new UpgradeVG(obj));
#else
            return(null);
#endif
        }
コード例 #2
0
        public static string GetGoodCurrentUpgrade(string goodItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling GetGoodCurrentUpgrade with: " + goodItemId);
#if UNITY_ANDROID && !UNITY_EDITOR
                string currentItemId = "";
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    currentItemId = AndroidJNIHandler.CallStatic <string>(jniStoreInventory, "getGoodCurrentUpgrade", goodItemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
                return(currentItemId);
#elif UNITY_IOS && !UNITY_EDITOR
                IntPtr p   = IntPtr.Zero;
                int    err = storeInventory_GetGoodCurrentUpgrade(goodItemId, out p);

                IOS_ErrorCodes.CheckAndThrowException(err);

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

                return(result);
#endif
            }
            return(null);
        }
コード例 #3
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
        }
コード例 #4
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
        }
コード例 #5
0
 /// <summary>
 /// Removes the non-consumable item with the given <c>nonConsItemId</c> from the non-consumable
 /// items storage.
 /// </summary>
 /// <param name="nonConsItemId">Id of the item to be removed.</param>
 /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
 override protected void _removeNonConsumableItem(string nonConsItemId)
 {
     AndroidJNI.PushLocalFrame(100);
     using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
         AndroidJNIHandler.CallStaticVoid(jniStoreInventory, "removeNonConsumableItem", nonConsItemId);
     }
     AndroidJNI.PopLocalFrame(IntPtr.Zero);
 }
コード例 #6
0
 /// <summary>
 /// Buys the item with the given <c>itemId</c>.
 /// </summary>
 /// <param name="itemId">id of item to be bought</param>
 /// <exception cref="VirtualItemNotFoundException">Thrown if the item to be bought is not found.</exception>
 /// <exception cref="InsufficientFundsException">Thrown if the user does not have enough funds.</exception>
 override protected void _buyItem(string itemId)
 {
     AndroidJNI.PushLocalFrame(100);
     using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
         AndroidJNIHandler.CallStaticVoid(jniStoreInventory, "buy", itemId);
     }
     AndroidJNI.PopLocalFrame(IntPtr.Zero);
 }
コード例 #7
0
 /// <summary>
 /// Takes from your user the given amount of the virtual item with the given <c>itemId</c>.
 /// For example, when your user requests a refund, you need to TAKE the item he/she is returning from him/her.
 /// </summary>
 /// <param name="itemId">Item identifier.</param>
 /// <param name="amount">Amount.</param>
 /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
 override protected void _takeItem(string itemId, int amount)
 {
     AndroidJNI.PushLocalFrame(100);
     using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
         AndroidJNIHandler.CallStaticVoid(jniStoreInventory, "takeVirtualItem", itemId, amount);
     }
     AndroidJNI.PopLocalFrame(IntPtr.Zero);
 }
コード例 #8
0
 /// <summary>
 /// Unequips the virtual good with the given <c>goodItemId</c>. Unequipping means that the
 /// user decides to stop using the virtual good he/she is currently using.
 /// For more details and examples <see cref="com.soomla.store.domain.virtualGoods.EquippableVG"/>.
 /// </summary>
 /// <param name="goodItemId">Id of the good to be unequipped.</param>
 /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
 override protected void _unEquipVirtualGood(string goodItemId)
 {
     AndroidJNI.PushLocalFrame(100);
     using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
         AndroidJNIHandler.CallStaticVoid(jniStoreInventory, "unEquipVirtualGood", goodItemId);
     }
     AndroidJNI.PopLocalFrame(IntPtr.Zero);
 }
コード例 #9
0
 /// <summary>
 /// Removes all upgrades from the virtual good with the given <c>goodItemId</c>.
 /// </summary>
 /// <param name="goodItemId">Id of the good whose upgrades are to be removed.</param>
 /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
 override protected void _removeGoodUpgrades(string goodItemId)
 {
     AndroidJNI.PushLocalFrame(100);
     using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
         AndroidJNIHandler.CallStaticVoid(jniStoreInventory, "removeUpgrades", goodItemId);
     }
     AndroidJNI.PopLocalFrame(IntPtr.Zero);
 }
コード例 #10
0
        /// <summary>
        /// Retrieves the upgrade level of the virtual good with the given <c>goodItemId</c>.
        /// For Example:
        /// Let's say there's a strength attribute to one of the characters in your game and you provide
        /// your users with the ability to upgrade that strength on a scale of 1-3.
        /// This is what you've created:
        /// 1. <c>SingleUseVG</c> for "strength".
        /// 2. <c>UpgradeVG</c> for strength 'level 1'.
        /// 3. <c>UpgradeVG</c> for strength 'level 2'.
        /// 4. <c>UpgradeVG</c> for strength 'level 3'.
        /// In the example, this function will retrieve the upgrade level for "strength" (1, 2, or 3).
        /// </summary>
        /// <param name="goodItemId">Good item identifier.</param>
        /// <returns>The good upgrade level.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected int _getGoodUpgradeLevel(string goodItemId)
        {
            int level = 0;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                level = AndroidJNIHandler.CallStatic <int>(jniStoreInventory, "getGoodUpgradeLevel", goodItemId);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(level);
        }
コード例 #11
0
        /// <summary>
        /// Checks if the virtual good with the given <c>goodItemId</c> is currently equipped.
        /// </summary>
        /// <param name="goodItemId">Id of the virtual good who we want to know if is equipped.</param>
        /// <returns>True if the virtual good is equipped, false otherwise.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected bool _isVertualGoodEquipped(string goodItemId)
        {
            bool result = false;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                result = AndroidJNIHandler.CallStatic <bool>(jniStoreInventory, "isVirtualGoodEquipped", goodItemId);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(result);
        }
コード例 #12
0
        /** NON-CONSUMABLES **/

        /// <summary>
        /// Checks if the non-consumable with the given <c>nonConsItemId</c> exists.
        /// </summary>
        /// <param name="nonConsItemId">Id of the item to check if exists.</param>
        /// <returns>True if non-consumable item with nonConsItemId exists, false otherwise.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected bool _nonConsumableItemExists(string nonConsItemId)
        {
            bool result = false;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                result = AndroidJNIHandler.CallStatic <bool>(jniStoreInventory, "nonConsumableItemExists", nonConsItemId);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(result);
        }
コード例 #13
0
        /** VIRTUAL ITEMS **/

        /// <summary>
        /// Retrieves the balance of the virtual item with the given <c>itemId</c>.
        /// </summary>
        /// <param name="itemId">Id of the virtual item to be fetched.</param>
        /// <returns>Balance of the virtual item with the given item id.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected int _getItemBalance(string itemId)
        {
            AndroidJNI.PushLocalFrame(100);
            int balance = 0;

            using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                balance = AndroidJNIHandler.CallStatic <int>(jniStoreInventory, "getVirtualItemBalance", itemId);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(balance);
        }
コード例 #14
0
        /// <summary>
        /// Retrieves the current upgrade of the good with the given id.
        /// </summary>
        /// <param name="goodItemId">Id of the good whose upgrade we want to fetch. </param>
        /// <returns>The good's current upgrade.</returns>
        /// <exception cref="VirtualItemNotFoundException">Thrown if the item is not found.</exception>
        override protected string _getGoodCurrentUpgrade(string goodItemId)
        {
            string currentItemId = "";

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                currentItemId = AndroidJNIHandler.CallStatic <string>(jniStoreInventory, "getGoodCurrentUpgrade", goodItemId);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(currentItemId);
        }
コード例 #15
0
 /// <summary>
 /// Starts a purchase process in the market.
 /// </summary>
 /// <param name="productId">id of the item to buy.</param>
 protected override void _buyMarketItem(string productId, string payload)
 {
     AndroidJNI.PushLocalFrame(100);
     using (AndroidJavaObject jniPurchasableItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getPurchasableItem", productId)) {
         AndroidJNIHandler.CallVoid(jniStoreController, "buyWithMarket",
                                    jniPurchasableItem.Call <AndroidJavaObject>("getPurchaseType").Call <AndroidJavaObject>("getMarketItem"),
                                    payload);
     }
     AndroidJNI.PopLocalFrame(IntPtr.Zero);
 }
コード例 #16
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);
        }
コード例 #17
0
        /// <summary>
        /// Gets the last upgrade for the virtual good with the given <c>goodItemId</c>.
        /// </summary>
        /// <param name="goodItemId">item id</param>
        /// <returns>last upgrade for virtual good with the given id</returns>
        override protected UpgradeVG _getLastUpgradeForVirtualGood(string goodItemId)
        {
            UpgradeVG vgu = null;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniUpgradeVG = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getGoodLastUpgrade", goodItemId)) {
                vgu = new UpgradeVG(jniUpgradeVG);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(vgu);
        }
コード例 #18
0
        /// <summary>
        /// Gets the category that the virtual good with the given <c>goodItemId</c> belongs to.
        /// </summary>
        /// <param name="goodItemId">Item id.</param>
        /// <returns>Category that the item with given id belongs to.</returns>
        /// <exception cref="VirtualItemNotFoundException">Exception is thrown if category is not found.</exception>
        override protected VirtualCategory _getCategoryForVirtualGood(string goodItemId)
        {
            VirtualCategory vc = null;

            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualVategory = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getCategory", goodItemId)) {
                vc = new VirtualCategory(jniVirtualVategory);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(vc);
        }
コード例 #19
0
        public static void BuyMarketItem(string productId)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniPurchasableItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.store.data.StoreInfo"), "getPurchasableItem", productId)) {
                AndroidJNIHandler.CallVoid(jniStoreController, "buyWithGooglePlay",
                                           jniPurchasableItem.Call <AndroidJavaObject>("getPurchaseType").Call <AndroidJavaObject>("getGoogleMarketItem"),
                                           "");
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS && !UNITY_EDITOR
            storeController_BuyMarketItem(productId);
#endif
        }
コード例 #20
0
        public static void BuyItem(string itemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling BuyItem with: " + itemId);
#if UNITY_ANDROID && !UNITY_EDITOR
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    AndroidJNIHandler.CallStaticVoid(jniStoreInventory, "buy", itemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS && !UNITY_EDITOR
                int err = storeInventory_BuyItem(itemId);

                IOS_ErrorCodes.CheckAndThrowException(err);
#endif
            }
        }
コード例 #21
0
        public static bool IsVirtualGoodEquipped(string goodItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling IsVirtualGoodEquipped with: " + goodItemId);
#if UNITY_ANDROID && !UNITY_EDITOR
                bool result = false;
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    result = AndroidJNIHandler.CallStatic <bool>(jniStoreInventory, "isVirtualGoodEquipped", goodItemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
                return(result);
#elif UNITY_IOS && !UNITY_EDITOR
                bool result = false;
                int  err    = storeInventory_IsVirtualGoodEquipped(goodItemId, out result);

                IOS_ErrorCodes.CheckAndThrowException(err);

                return(result);
#endif
            }
            return(false);
        }
コード例 #22
0
        /** NonConsumables **/


        public static bool NonConsumableItemExists(string nonConsItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling NonConsumableItemExists with: " + nonConsItemId);
#if UNITY_ANDROID && !UNITY_EDITOR
                bool result = false;
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    result = AndroidJNIHandler.CallStatic <bool>(jniStoreInventory, "nonConsumableItemExists", nonConsItemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
                return(result);
#elif UNITY_IOS && !UNITY_EDITOR
                bool result = false;
                int  err    = storeInventory_NonConsumableItemExists(nonConsItemId, out result);

                IOS_ErrorCodes.CheckAndThrowException(err);

                return(result);
#endif
            }
            return(false);
        }
コード例 #23
0
        /** Virtual Items **/


        public static int GetItemBalance(string itemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling GetItemBalance with: " + itemId);
#if UNITY_ANDROID && !UNITY_EDITOR
                AndroidJNI.PushLocalFrame(100);
                int balance = 0;
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    balance = AndroidJNIHandler.CallStatic <int>(jniStoreInventory, "getVirtualItemBalance", itemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
                return(balance);
#elif UNITY_IOS && !UNITY_EDITOR
                int balance = 0;
                int err     = storeInventory_GetItemBalance(itemId, out balance);

                IOS_ErrorCodes.CheckAndThrowException(err);

                return(balance);
#endif
            }
            return(0);
        }
コード例 #24
0
        public static int GetGoodUpgradeLevel(string goodItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling GetGoodUpgradeLevel with: " + goodItemId);
#if UNITY_ANDROID && !UNITY_EDITOR
                int level = 0;
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    level = AndroidJNIHandler.CallStatic <int>(jniStoreInventory, "getGoodUpgradeLevel", goodItemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
                return(level);
#elif UNITY_IOS && !UNITY_EDITOR
                int level = 0;
                int err   = storeInventory_GetGoodUpgradeLevel(goodItemId, out level);

                IOS_ErrorCodes.CheckAndThrowException(err);

                return(level);
#endif
            }
            return(0);
        }