Exemple #1
0
        public static void Initialize(IStoreAssets storeAssets)
        {
            #if UNITY_ANDROID
            Debug.Log("pushing data to StoreAssets on java side");

            AndroidJNI.PushLocalFrame(100);

            using(AndroidJavaClass jniStoreAssets = new AndroidJavaClass("com.soomla.unity.StoreAssets")) {

                //storeAssets version
                jniStoreAssets.CallStatic("setVersion", storeAssets.GetVersion());

                Dictionary<int, AndroidJavaObject> jniCategories = new Dictionary<int, AndroidJavaObject>();
                //virtual categories
                using(AndroidJavaObject jniVirtualCategories = jniStoreAssets.GetStatic<AndroidJavaObject>("virtualCategories")) {
                    jniVirtualCategories.Call("clear");
                    AndroidJNI.PushLocalFrame(100);
                    foreach(VirtualCategory vc in storeAssets.GetVirtualCategories()){
                        jniCategories[vc.Id] = vc.toAndroidJavaObject(jniStoreAssets);
                        jniVirtualCategories.Call<bool>("add", jniCategories[vc.Id]);
                    }
                    AndroidJNI.PopLocalFrame(IntPtr.Zero);
                }

                //non consumable items
                using(AndroidJavaObject jniNonConsumableItems = jniStoreAssets.GetStatic<AndroidJavaObject>("nonConsumableItems")) {
                    jniNonConsumableItems.Call("clear");
                    AndroidJNI.PushLocalFrame(100);
                    foreach(NonConsumableItem non in storeAssets.GetNonConsumableItems()){
                        using(AndroidJavaObject obj = non.toAndroidJavaObject()) {
                            jniNonConsumableItems.Call<bool>("add", obj);
                        }
                    }
                    AndroidJNI.PopLocalFrame(IntPtr.Zero);
                }

                Dictionary<string, AndroidJavaObject> jniCurrencies = new Dictionary<string, AndroidJavaObject>();
                //Virtual currencies
                using(AndroidJavaObject jniVirtualCurrencies = jniStoreAssets.GetStatic<AndroidJavaObject>("virtualCurrencies")) {
                    jniVirtualCurrencies.Call("clear");
                    AndroidJNI.PushLocalFrame(100);
                    foreach(VirtualCurrency vc in storeAssets.GetVirtualCurrencies()){
                        jniCurrencies[vc.ItemId] = vc.toAndroidJavaObject();
                        jniVirtualCurrencies.Call<bool>("add", jniCurrencies[vc.ItemId]);
                    }
                    AndroidJNI.PopLocalFrame(IntPtr.Zero);
                }

                //Virtual currency packs
                using(AndroidJavaObject jniVirtualCurrencyPacks = jniStoreAssets.GetStatic<AndroidJavaObject>("virtualCurrencyPacks")) {
                    jniVirtualCurrencyPacks.Call("clear");
                    AndroidJNI.PushLocalFrame(100);
                    foreach(VirtualCurrencyPack vcp in storeAssets.GetVirtualCurrencyPacks()){
                        using(AndroidJavaObject obj = vcp.toAndroidJavaObject(jniCurrencies[vcp.Currency.ItemId])) {
                            jniVirtualCurrencyPacks.Call<bool>("add", obj);
                        }
                    }
                    AndroidJNI.PopLocalFrame(IntPtr.Zero);
                }

                //Virtual goods
                using(AndroidJavaObject jniVirtualGoods = jniStoreAssets.GetStatic<AndroidJavaObject>("virtualGoods")) {
                    jniVirtualGoods.Call("clear");
                    foreach(VirtualGood vg in storeAssets.GetVirtualGoods()){
                        AndroidJNI.PushLocalFrame(100);
                        using(AndroidJavaObject obj = vg.toAndroidJavaObject(jniStoreAssets, jniCategories[vg.Category.Id])) {
                            jniVirtualGoods.Call<bool>("add", obj);
                        }
                        AndroidJNI.PopLocalFrame(IntPtr.Zero);
                    }
                }

                foreach(KeyValuePair<int, AndroidJavaObject> kvp in jniCategories) {
                    kvp.Value.Dispose();
                }

                foreach(KeyValuePair<string, AndroidJavaObject> kvp in jniCurrencies) {
                    kvp.Value.Dispose();
                }
            }

            AndroidJNI.PopLocalFrame(IntPtr.Zero);
            Debug.Log("done! (pushing data to StoreAssets on java side)");
            #elif UNITY_IOS
            Debug.Log("pushing data to StoreAssets on ios side");

            storeAssets_Init();

            // storeAssets version
            storeAssets_SetVersion(storeAssets.GetVersion());
            //virtual categories
            foreach(VirtualCategory vc in storeAssets.GetVirtualCategories()){
                storeAssets_AddCategory(vc.Name, vc.Id, vc.Equipping.ToString());
            }
            //ios market items
            foreach(NonConsumableItem non in storeAssets.GetNonConsumableItems()){
                storeAssets_AddNonConsumable(non.Name, non.Description, non.ItemId, non.MarketItem.Price, non.MarketItem.ProductId);
            }
            //Virtual currencies
            foreach(VirtualCurrency vc in storeAssets.GetVirtualCurrencies()){
                storeAssets_AddCurrency(vc.Name, vc.Description, vc.ItemId);
            }
            //Virtual currency packs
            foreach(VirtualCurrencyPack vcp in storeAssets.GetVirtualCurrencyPacks()){
                storeAssets_AddCurrencyPack(vcp.Name, vcp.Description, vcp.ItemId, vcp.MarketItem.Price, vcp.MarketItem.ProductId, vcp.CurrencyAmount, vcp.Currency.ItemId);
            }
            //Virtual goods
            foreach(VirtualGood vg in storeAssets.GetVirtualGoods()){
                string json = vg.PriceModel.toJSONObject().print();
                storeAssets_AddVirtualGood(vg.Name, vg.Description, vg.ItemId, vg.Category.Id, json);
            }

            Debug.Log("done! (pushing data to StoreAssets on ios side)");
            #endif
        }