Exemplo n.º 1
0
        public static PurchasableVirtualItem GetPurchasableItemWithProductId(string productId)
        {
#if UNITY_EDITOR
            foreach (var i in GetVirtualCurrencyPacks())
            {
                if (i.ItemId == productId)
                {
                    return(i);
                }
            }
            return(null);
#elif UNITY_ANDROID
            VirtualItem vi = null;
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.unity.StoreInfo"), "getPurchasableItem", productId)) {
                vi = VirtualItem.factoryItemFromJNI(jniVirtualItem);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return((PurchasableVirtualItem)vi);
#elif UNITY_IOS
            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
        }
Exemplo n.º 2
0
        public static UpgradeVG GetLastUpgradeForVirtualGood(string goodItemId)
        {
#if UNITY_ANDROID
            UpgradeVG vgu = null;
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniUpgradeVG = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.unity.StoreInfo"), "getGoodLastUpgrade", goodItemId)) {
                vgu = new UpgradeVG(jniUpgradeVG);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(vgu);
#elif UNITY_IOS
            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
        }
Exemplo n.º 3
0
        public static void BuyItem(string itemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling BuyItem with: " + itemId);
#if UNITY_ANDROID
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    AndroidJNIHandler.CallStaticVoid(jniStoreInventory, "buy", itemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS
                int err = storeInventory_BuyItem(itemId);

                IOS_ErrorCodes.CheckAndThrowException(err);
#endif
            }

#if UNITY_EDITOR
            var item = StoreInfo.GetPurchasableItemWithProductId(itemId) as PurchasableVirtualItem;

            if (UnityEngine.Random.value > 0.1)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Simulate purchase: " + itemId);
                Events.OnMarketPurchaseStarted(item);
                Events.OnMarketPurchase(item);
            }
            else
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Simulate failed purchase: " + itemId);
                Events.OnMarketPurchaseStarted(item);
                Events.OnMarketPurchaseCancelled(item);
            }
#endif
        }
Exemplo n.º 4
0
        public static VirtualItem GetItemByItemId(string itemId)
        {
            StoreUtils.LogDebug(TAG, "Trying to fetch an item with itemId: " + itemId);
#if UNITY_ANDROID
            VirtualItem vi = null;
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.unity.StoreInfo"), "getVirtualItem", itemId)) {
                vi = VirtualItem.factoryItemFromJNI(jniVirtualItem);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(vi);
#elif UNITY_IOS
            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
        }
Exemplo n.º 5
0
        public static VirtualCategory GetCategoryForVirtualGood(string goodItemId)
        {
#if UNITY_ANDROID && !UNITY_EDITOR
            VirtualCategory vc = null;
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualVategory = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.unity.StoreInfo"), "getCategoryForVirtualGood", goodItemId)) {
                vc = new VirtualCategory(jniVirtualVategory);
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            return(vc);
#elif UNITY_IOS && !UNITY_EDITOR
            IntPtr p   = IntPtr.Zero;
            int    err = storeInfo_GetCategoryForVirtualGood(goodItemId, out p);

            IOS_ErrorCodes.CheckAndThrowException(err);

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

            JSONObject obj = new JSONObject(json);
            return(new VirtualCategory(obj));
#else
            return(null);
#endif
        }
Exemplo n.º 6
0
        public static string GetGoodCurrentUpgrade(string goodItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling GetGoodCurrentUpgrade with: " + goodItemId);
#if UNITY_ANDROID
                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
                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);
        }
Exemplo n.º 7
0
        public static void BuyMarketItem(string productId)
        {
#if UNITY_ANDROID
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniPurchasableItem = AndroidJNIHandler.CallStatic <AndroidJavaObject>(
                       new AndroidJavaClass("com.soomla.unity.StoreInfo"), "getPurchasableItem", productId)) {
                AndroidJNIHandler.CallVoid(jniStoreController, "buyWithGooglePlay",
                                           jniPurchasableItem.Call <AndroidJavaObject>("getPurchaseType").Call <AndroidJavaObject>("getGoogleMarketItem"),
                                           "");
            }
            AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS
            storeController_BuyMarketItem(productId);
#endif
        }
Exemplo n.º 8
0
        public static void BuyItem(string itemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling BuyItem with: " + itemId);
#if UNITY_ANDROID
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    AndroidJNIHandler.CallStaticVoid(jniStoreInventory, "buy", itemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS
                int err = storeInventory_BuyItem(itemId);

                IOS_ErrorCodes.CheckAndThrowException(err);
#endif
            }
        }
Exemplo n.º 9
0
        public static void RemoveNonConsumableItem(string nonConsItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling RemoveNonConsumableItem with: " + nonConsItemId);
#if UNITY_ANDROID && !UNITY_EDITOR
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    AndroidJNIHandler.CallStaticVoid(jniStoreInventory, "removeNonConsumableItem", nonConsItemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS && !UNITY_EDITOR
                int err = storeInventory_RemoveNonConsumableItem(nonConsItemId);

                IOS_ErrorCodes.CheckAndThrowException(err);
#endif
            }
        }
Exemplo n.º 10
0
        public static void UpgradeGood(string goodItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling UpgradeGood with: " + goodItemId);
#if UNITY_ANDROID && !UNITY_EDITOR
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    AndroidJNIHandler.CallStaticVoid(jniStoreInventory, "upgradeVirtualGood", goodItemId);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS && !UNITY_EDITOR
                int err = storeInventory_UpgradeGood(goodItemId);

                IOS_ErrorCodes.CheckAndThrowException(err);
#endif
            }
        }
Exemplo n.º 11
0
        public static void TakeItem(string itemId, int amount)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling TakeItem with itedId: " + itemId + " and amount: " + amount);
#if UNITY_ANDROID && !UNITY_EDITOR
                AndroidJNI.PushLocalFrame(100);
                using (AndroidJavaClass jniStoreInventory = new AndroidJavaClass("com.soomla.store.StoreInventory")) {
                    AndroidJNIHandler.CallStaticVoid(jniStoreInventory, "takeVirtualItem", itemId, amount);
                }
                AndroidJNI.PopLocalFrame(IntPtr.Zero);
#elif UNITY_IOS && !UNITY_EDITOR
                int err = storeInventory_TakeItem(itemId, amount);

                IOS_ErrorCodes.CheckAndThrowException(err);
#endif
            }
        }
Exemplo n.º 12
0
        /** Virtual Items **/


        public static int GetItemBalance(string itemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling GetItemBalance with: " + itemId);
#if UNITY_ANDROID
                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
                int balance = 0;
                int err     = storeInventory_GetItemBalance(itemId, out balance);

                IOS_ErrorCodes.CheckAndThrowException(err);

                return(balance);
#endif
            }
            return(0);
        }
Exemplo n.º 13
0
        /** NonConsumables **/


        public static bool NonConsumableItemExists(string nonConsItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling NonConsumableItemExists with: " + nonConsItemId);
#if UNITY_ANDROID
                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
                bool result = false;
                int  err    = storeInventory_NonConsumableItemExists(nonConsItemId, out result);

                IOS_ErrorCodes.CheckAndThrowException(err);

                return(result);
#endif
            }
            return(false);
        }
Exemplo n.º 14
0
        public static int GetGoodUpgradeLevel(string goodItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling GetGoodUpgradeLevel with: " + goodItemId);
#if UNITY_ANDROID
                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
                int level = 0;
                int err   = storeInventory_GetGoodUpgradeLevel(goodItemId, out level);

                IOS_ErrorCodes.CheckAndThrowException(err);

                return(level);
#endif
            }
            return(0);
        }
Exemplo n.º 15
0
        public static bool IsVirtualGoodEquipped(string goodItemId)
        {
            if (!Application.isEditor)
            {
                StoreUtils.LogDebug(TAG, "SOOMLA/UNITY Calling IsVirtualGoodEquipped with: " + goodItemId);
#if UNITY_ANDROID
                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
                bool result = false;
                int  err    = storeInventory_IsVirtualGoodEquipped(goodItemId, out result);

                IOS_ErrorCodes.CheckAndThrowException(err);

                return(result);
#endif
            }
            return(false);
        }