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 }
public static List <NonConsumableItem> GetNonConsumableItems() { StoreUtils.LogDebug(TAG, "Trying to fetch noncons"); List <NonConsumableItem> nonConsumableItems = new List <NonConsumableItem>(); #if UNITY_ANDROID && !UNITY_EDITOR AndroidJNI.PushLocalFrame(100); using (AndroidJavaObject jniNonConsumableItems = new AndroidJavaClass("com.soomla.unity.StoreInfo").CallStatic <AndroidJavaObject>("getNonConsumableItems")) { for (int i = 0; i < jniNonConsumableItems.Call <int>("size"); i++) { using (AndroidJavaObject jniNon = jniNonConsumableItems.Call <AndroidJavaObject>("get", i)) { nonConsumableItems.Add(new NonConsumableItem(jniNon)); } } } AndroidJNI.PopLocalFrame(IntPtr.Zero); #elif UNITY_IOS && !UNITY_EDITOR IntPtr p = IntPtr.Zero; int err = storeInfo_GetNonConsumableItems(out p); IOS_ErrorCodes.CheckAndThrowException(err); string nonConsumableJson = Marshal.PtrToStringAnsi(p); Marshal.FreeHGlobal(p); StoreUtils.LogDebug(TAG, "Got json: " + nonConsumableJson); JSONObject nonConsArr = new JSONObject(nonConsumableJson); foreach (JSONObject obj in nonConsArr.list) { nonConsumableItems.Add(new NonConsumableItem(obj)); } #endif return(nonConsumableItems); }
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); }
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 }
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 }
public static List <UpgradeVG> GetUpgradesForVirtualGood(string goodItemId) { StoreUtils.LogDebug(TAG, "Trying to fetch upgrades for " + goodItemId); List <UpgradeVG> vgus = new List <UpgradeVG>(); #if UNITY_ANDROID AndroidJNI.PushLocalFrame(100); using (AndroidJavaObject jniUpgradeVGs = new AndroidJavaClass("com.soomla.unity.StoreInfo").CallStatic <AndroidJavaObject>("getGoodUpgrades")) { for (int i = 0; i < jniUpgradeVGs.Call <int>("size"); i++) { using (AndroidJavaObject jnivgu = jniUpgradeVGs.Call <AndroidJavaObject>("get", i)) { vgus.Add(new UpgradeVG(jnivgu)); } } } AndroidJNI.PopLocalFrame(IntPtr.Zero); #elif UNITY_IOS IntPtr p = IntPtr.Zero; int err = storeInfo_GetUpgradesForVirtualGood(goodItemId, out p); IOS_ErrorCodes.CheckAndThrowException(err); string upgradesJson = Marshal.PtrToStringAnsi(p); Marshal.FreeHGlobal(p); StoreUtils.LogDebug(TAG, "Got json: " + upgradesJson); JSONObject upgradesArr = new JSONObject(upgradesJson); foreach (JSONObject obj in upgradesArr.list) { vgus.Add(new UpgradeVG(obj)); } #endif return(vgus); }
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 }
public static List <VirtualCurrencyPack> GetVirtualCurrencyPacks() { StoreUtils.LogDebug(TAG, "Trying to fetch packs"); List <VirtualCurrencyPack> vcps = new List <VirtualCurrencyPack>(); #if UNITY_ANDROID && !UNITY_EDITOR AndroidJNI.PushLocalFrame(100); using (AndroidJavaObject jniVirtualCurrencyPacks = new AndroidJavaClass("com.soomla.store.data.StoreInfo").CallStatic <AndroidJavaObject>("getCurrencyPacks")) { for (int i = 0; i < jniVirtualCurrencyPacks.Call <int>("size"); i++) { using (AndroidJavaObject jnivcp = jniVirtualCurrencyPacks.Call <AndroidJavaObject>("get", i)) { vcps.Add(new VirtualCurrencyPack(jnivcp)); } } } AndroidJNI.PopLocalFrame(IntPtr.Zero); #elif UNITY_IOS && !UNITY_EDITOR IntPtr p = IntPtr.Zero; int err = storeInfo_GetVirtualCurrencyPacks(out p); IOS_ErrorCodes.CheckAndThrowException(err); string packsJson = Marshal.PtrToStringAnsi(p); Marshal.FreeHGlobal(p); StoreUtils.LogDebug(TAG, "Got json: " + packsJson); JSONObject packsArr = new JSONObject(packsJson); foreach (JSONObject obj in packsArr.list) { vcps.Add(new VirtualCurrencyPack(obj)); } #endif return(vcps); }
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 }
public static List <VirtualCategory> GetVirtualCategories() { StoreUtils.LogDebug(TAG, "Trying to fetch categories"); List <VirtualCategory> virtualCategories = new List <VirtualCategory>(); #if UNITY_ANDROID && !UNITY_EDITOR AndroidJNI.PushLocalFrame(100); using (AndroidJavaObject jniVirtualCategories = new AndroidJavaClass("com.soomla.unity.StoreInfo").CallStatic <AndroidJavaObject>("getCategories")) { for (int i = 0; i < jniVirtualCategories.Call <int>("size"); i++) { using (AndroidJavaObject jniCat = jniVirtualCategories.Call <AndroidJavaObject>("get", i)) { virtualCategories.Add(new VirtualCategory(jniCat)); } } } AndroidJNI.PopLocalFrame(IntPtr.Zero); #elif UNITY_IOS && !UNITY_EDITOR IntPtr p = IntPtr.Zero; int err = storeInfo_GetVirtualCategories(out p); IOS_ErrorCodes.CheckAndThrowException(err); string categoriesJson = Marshal.PtrToStringAnsi(p); Marshal.FreeHGlobal(p); StoreUtils.LogDebug(TAG, "Got json: " + categoriesJson); JSONObject categoriesArr = new JSONObject(categoriesJson); foreach (JSONObject obj in categoriesArr.list) { virtualCategories.Add(new VirtualCategory(obj)); } #endif return(virtualCategories); }
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 } }
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 } }
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 } }
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 } }
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); }
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); }
/** 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); }
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); }
/** 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); }