Beispiel #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
        }
Beispiel #2
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
        }
        /// <summary>
        /// Crea una extension a partir de un item base
        /// </summary>
        /// <param name="baseItem">Item base</param>
        public static VirtualItemDecorator MakeItem(VirtualItem baseItem)
        {
            VirtualItemDecorator item;

            if (baseItem is EquippableVG)
            {
                item = new EquippableVGDecorator(baseItem as EquippableVG);
            }
            else if (baseItem is LifetimeVG)
            {
                item = new LifetimeVGDecorator(baseItem as LifetimeVG);
            }
            else if (baseItem is VirtualGood)
            {
                item = new VirtualGoodDecorator(baseItem as VirtualGood);
            }
            else if (baseItem is PurchasableVirtualItem)
            {
                item = new PurchasableVirtualItemDecorator(baseItem as PurchasableVirtualItem);
            }
            else
            {
                item = new VirtualItemDecorator(baseItem as VirtualItem);
            }

            return item;
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="baseItem">Item base</param>
 public VirtualItemDecorator(VirtualItem baseItem)
     : base(baseItem)
 {
     try
     {
         Balance = StoreInventory.GetItemBalance(ID);
     }
     catch (Exception e)
     {
         Debug.LogWarning("ITEM " + ID + ": " + e.Message);
         Balance = 0;
     }
 }
Beispiel #5
0
        public static List <VirtualGood> GetVirtualGoods()
        {
            StoreUtils.LogDebug(TAG, "Trying to fetch goods");
            List <VirtualGood> virtualGoods = new List <VirtualGood>();

#if UNITY_EDITOR
            virtualGoods.AddRange(storeAssets.GetGoods());
#elif UNITY_ANDROID
            AndroidJNI.PushLocalFrame(100);
            using (AndroidJavaObject jniVirtualGoods = new AndroidJavaClass("com.soomla.unity.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
            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);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="baseItem">Item base</param>
 public MarketDecorator(VirtualItem baseItem)
 {
     BaseItem = baseItem;
 }