/// <summary> /// Initializes <c>StoreInfo</c>. /// On first initialization, when the database doesn't have any previous version of the store /// metadata, <c>StoreInfo</c> gets loaded from the given <c>IStoreAssets</c>. /// After the first initialization, <c>StoreInfo</c> will be initialized from the database. /// /// IMPORTANT: If you want to override the current <c>StoreInfo</c>, you'll have to bump /// the version of your implementation of <c>IStoreAssets</c> in order to remove the /// metadata when the application loads. Bumping the version is done by returning a higher /// number in <c>IStoreAssets</c>'s <c>getVersion</c>. /// </summary> /// <param name="storeAssets">your game's economy</param> override protected void _setStoreAssets(IStoreAssets storeAssets) { SoomlaUtils.LogDebug(TAG, "pushing IStoreAssets to StoreInfo on iOS side"); string storeAssetsJSON = IStoreAssetsToJSON(storeAssets); int version = storeAssets.GetVersion(); int err = storeInfo_SetStoreAssets(storeAssetsJSON, version); IOS_ErrorCodes.CheckAndThrowException(err); SoomlaUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on iOS side)"); }
/// <summary> /// Initializes <c>StoreInfo</c>. /// On first initialization, when the database doesn't have any previous version of the store /// metadata, <c>StoreInfo</c> gets loaded from the given <c>IStoreAssets</c>. /// After the first initialization, <c>StoreInfo</c> will be initialized from the database. /// /// IMPORTANT: If you want to override the current <c>StoreInfo</c>, you'll have to bump /// the version of your implementation of <c>IStoreAssets</c> in order to remove the /// metadata when the application loads. Bumping the version is done by returning a higher /// number in <c>IStoreAssets</c>'s <c>getVersion</c>. /// </summary> override protected void _setStoreAssets(IStoreAssets storeAssets) { SoomlaUtils.LogDebug(TAG, "pushing data to StoreAssets on wp side"); string storeAssetsJSON = IStoreAssetsToJSON(storeAssets); int version = storeAssets.GetVersion(); SoomlaWpStore.data.GenericStoreAssets.GetInstance().Prepare(version, storeAssetsJSON); SoomlaWpStore.data.StoreInfo.setStoreAssets(SoomlaWpStore.data.GenericStoreAssets.GetInstance()); SoomlaUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on wp side)"); }
/// <summary> /// Initializes <c>StoreInfo</c>. /// On first initialization, when the database doesn't have any previous version of the store /// metadata, <c>StoreInfo</c> gets loaded from the given <c>IStoreAssets</c>. /// After the first initialization, <c>StoreInfo</c> will be initialized from the database. /// /// IMPORTANT: If you want to override the current <c>StoreInfo</c>, you'll have to bump /// the version of your implementation of <c>IStoreAssets</c> in order to remove the /// metadata when the application loads. Bumping the version is done by returning a higher /// number in <c>IStoreAssets</c>'s <c>getVersion</c>. /// </summary> /// <param name="storeAssets">your game's economy</param> override protected void _setStoreAssets(IStoreAssets storeAssets) { SoomlaUtils.LogDebug(TAG, "pushing IStoreAssets to StoreInfo on iOS side"); string storeAssetsJSON = IStoreAssetsToJSON(storeAssets); int version = storeAssets.GetVersion(); int err = storeInfo_SetStoreAssets(storeAssetsJSON, version); IOS_ErrorCodes.CheckAndThrowException(err); SoomlaUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on iOS side)"); }
/// <summary> /// Initializes <c>StoreInfo</c>. /// On first initialization, when the database doesn't have any previous version of the store /// metadata, <c>StoreInfo</c> gets loaded from the given <c>IStoreAssets</c>. /// After the first initialization, <c>StoreInfo</c> will be initialized from the database. /// /// IMPORTANT: If you want to override the current <c>StoreInfo</c>, you'll have to bump /// the version of your implementation of <c>IStoreAssets</c> in order to remove the /// metadata when the application loads. Bumping the version is done by returning a higher /// number in <c>IStoreAssets</c>'s <c>getVersion</c>. /// </summary> override protected void _setStoreAssets(IStoreAssets storeAssets) { SoomlaUtils.LogDebug(TAG, "pushing data to StoreAssets on wp side"); string storeAssetsJSON = IStoreAssetsToJSON(storeAssets); int version = storeAssets.GetVersion(); SoomlaWpStore.data.GenericStoreAssets.GetInstance().Prepare(version, storeAssetsJSON); SoomlaWpStore.data.StoreInfo.setStoreAssets(SoomlaWpStore.data.GenericStoreAssets.GetInstance()); SoomlaUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on wp side)"); }
/// <summary> /// Initializes <c>StoreInfo</c>. /// On first initialization, when the database doesn't have any previous version of the store /// metadata, <c>StoreInfo</c> gets loaded from the given <c>IStoreAssets</c>. /// After the first initialization, <c>StoreInfo</c> will be initialized from the database. /// /// IMPORTANT: If you want to override the current <c>StoreInfo</c>, you'll have to bump /// the version of your implementation of <c>IStoreAssets</c> in order to remove the /// metadata when the application loads. Bumping the version is done by returning a higher /// number in <c>IStoreAssets</c>'s <c>getVersion</c>. /// </summary> override protected void _setStoreAssets(IStoreAssets storeAssets) { SoomlaUtils.LogDebug(TAG, "pushing IStoreAssets to StoreInfo on java side"); AndroidJNI.PushLocalFrame(100); string storeAssetsJSON = IStoreAssetsToJSON(storeAssets); int version = storeAssets.GetVersion(); using(AndroidJavaClass jniStoreInfoClass = new AndroidJavaClass("com.soomla.store.data.StoreInfo")) { jniStoreInfoClass.CallStatic("setStoreAssets", version, storeAssetsJSON); } AndroidJNI.PopLocalFrame(IntPtr.Zero); SoomlaUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on java side)"); }
/// <summary> /// Initializes <c>StoreInfo</c>. /// On first initialization, when the database doesn't have any previous version of the store /// metadata, <c>StoreInfo</c> gets loaded from the given <c>IStoreAssets</c>. /// After the first initialization, <c>StoreInfo</c> will be initialized from the database. /// /// IMPORTANT: If you want to override the current <c>StoreInfo</c>, you'll have to bump /// the version of your implementation of <c>IStoreAssets</c> in order to remove the /// metadata when the application loads. Bumping the version is done by returning a higher /// number in <c>IStoreAssets</c>'s <c>getVersion</c>. /// </summary> override protected void _setStoreAssets(IStoreAssets storeAssets) { SoomlaUtils.LogDebug(TAG, "pushing IStoreAssets to StoreInfo on java side"); AndroidJNI.PushLocalFrame(100); string storeAssetsJSON = IStoreAssetsToJSON(storeAssets); int version = storeAssets.GetVersion(); using (AndroidJavaClass jniStoreInfoClass = new AndroidJavaClass("com.soomla.store.data.StoreInfo")) { jniStoreInfoClass.CallStatic("setStoreAssets", version, storeAssetsJSON); } AndroidJNI.PopLocalFrame(IntPtr.Zero); SoomlaUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on java side)"); }
/** * Initializes <code>StoreInfo</code>. * On first initialization, when the database doesn't have any previous version of the store * metadata, <code>StoreInfo</code> gets loaded from the given <code>IStoreAssets</code>. * After the first initialization, <code>StoreInfo</code> will be initialized from the database. * * IMPORTANT: If you want to override the current <code>StoreInfo</code>, you'll have to bump * the version of your implementation of <code>IStoreAssets</code> in order to remove the * metadata when the application loads. Bumping the version is done by returning a higher number * in {@link com.soomla.store.IStoreAssets#getVersion()}. */ public static void setStoreAssets(IStoreAssets storeAssets){ if (storeAssets == null){ SoomlaUtils.LogError(TAG, "The given store assets can't be null!"); return; } mCurrentAssetsVersion = storeAssets.GetVersion(); checkMetadataVersion(); // we always initialize from the database, unless this is the first time the game is // loaded - in that case we initialize with setStoreAssets. if (!initializeFromDB()){ initializeWithStoreAssets(storeAssets); } }
/** * Initializes <code>StoreInfo</code>. * On first initialization, when the database doesn't have any previous version of the store * metadata, <code>StoreInfo</code> gets loaded from the given <code>IStoreAssets</code>. * After the first initialization, <code>StoreInfo</code> will be initialized from the database. * * IMPORTANT: If you want to override the current <code>StoreInfo</code>, you'll have to bump * the version of your implementation of <code>IStoreAssets</code> in order to remove the * metadata when the application loads. Bumping the version is done by returning a higher number * in {@link com.soomla.store.IStoreAssets#getVersion()}. */ public static void setStoreAssets(IStoreAssets storeAssets) { if (storeAssets == null) { SoomlaUtils.LogError(TAG, "The given store assets can't be null!"); return; } mCurrentAssetsVersion = storeAssets.GetVersion(); checkMetadataVersion(); // we always initialize from the database, unless this is the first time the game is // loaded - in that case we initialize with setStoreAssets. if (!initializeFromDB()) { initializeWithStoreAssets(storeAssets); } }
public static void Initialize(IStoreAssets storeAssets) { // StoreUtils.LogDebug(TAG, "Adding currency"); JSONObject currencies = new JSONObject(JSONObject.Type.ARRAY); foreach(VirtualCurrency vi in storeAssets.GetCurrencies()) { currencies.Add(vi.toJSONObject()); } // StoreUtils.LogDebug(TAG, "Adding packs"); JSONObject packs = new JSONObject(JSONObject.Type.ARRAY); foreach(VirtualCurrencyPack vi in storeAssets.GetCurrencyPacks()) { packs.Add(vi.toJSONObject()); } // StoreUtils.LogDebug(TAG, "Adding goods"); JSONObject suGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject ltGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject eqGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject upGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject paGoods = new JSONObject(JSONObject.Type.ARRAY); foreach(VirtualGood g in storeAssets.GetGoods()){ if (g is SingleUseVG) { suGoods.Add(g.toJSONObject()); } else if (g is EquippableVG) { eqGoods.Add(g.toJSONObject()); } else if (g is UpgradeVG) { upGoods.Add(g.toJSONObject()); } else if (g is LifetimeVG) { ltGoods.Add(g.toJSONObject()); } else if (g is SingleUsePackVG) { paGoods.Add(g.toJSONObject()); } } JSONObject goods = new JSONObject(JSONObject.Type.OBJECT); goods.AddField(JSONConsts.STORE_GOODS_SU, suGoods); goods.AddField(JSONConsts.STORE_GOODS_LT, ltGoods); goods.AddField(JSONConsts.STORE_GOODS_EQ, eqGoods); goods.AddField(JSONConsts.STORE_GOODS_UP, upGoods); goods.AddField(JSONConsts.STORE_GOODS_PA, paGoods); // StoreUtils.LogDebug(TAG, "Adding categories"); JSONObject categories = new JSONObject(JSONObject.Type.ARRAY); foreach(VirtualCategory vi in storeAssets.GetCategories()) { categories.Add(vi.toJSONObject()); } // StoreUtils.LogDebug(TAG, "Adding nonConsumables"); JSONObject nonConsumables = new JSONObject(JSONObject.Type.ARRAY); foreach(NonConsumableItem vi in storeAssets.GetNonConsumableItems()) { nonConsumables.Add(vi.toJSONObject()); } // StoreUtils.LogDebug(TAG, "Preparing StoreAssets JSONObject"); JSONObject storeAssetsObj = new JSONObject(JSONObject.Type.OBJECT); storeAssetsObj.AddField(JSONConsts.STORE_CATEGORIES, categories); storeAssetsObj.AddField(JSONConsts.STORE_CURRENCIES, currencies); storeAssetsObj.AddField(JSONConsts.STORE_CURRENCYPACKS, packs); storeAssetsObj.AddField(JSONConsts.STORE_GOODS, goods); storeAssetsObj.AddField(JSONConsts.STORE_NONCONSUMABLES, nonConsumables); string storeAssetsJSON = storeAssetsObj.print(); #if UNITY_ANDROID && !UNITY_EDITOR StoreUtils.LogDebug(TAG, "pushing data to StoreAssets on java side"); using(AndroidJavaClass jniStoreAssets = new AndroidJavaClass("com.soomla.unity.StoreAssets")) { jniStoreAssets.CallStatic("prepare", storeAssets.GetVersion(), storeAssetsJSON); } StoreUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on java side)"); #elif UNITY_IOS && !UNITY_EDITOR StoreUtils.LogDebug(TAG, "pushing data to StoreAssets on ios side"); storeAssets_Init(storeAssets.GetVersion(), storeAssetsJSON); StoreUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on ios side)"); #endif }
// private static AndroidJavaClass jniStoreInfo = new AndroidJavaClass("com.soomla.unity.StoreInfo"); #endif public static void Initialize(IStoreAssets storeAssets) { #if UNITY_EDITOR StoreInfo.storeAssets = storeAssets; #endif // StoreUtils.LogDebug(TAG, "Adding currency"); JSONObject currencies = new JSONObject(JSONObject.Type.ARRAY); foreach (VirtualCurrency vi in storeAssets.GetCurrencies()) { currencies.Add(vi.toJSONObject()); } // StoreUtils.LogDebug(TAG, "Adding packs"); JSONObject packs = new JSONObject(JSONObject.Type.ARRAY); foreach (VirtualCurrencyPack vi in storeAssets.GetCurrencyPacks()) { packs.Add(vi.toJSONObject()); } // StoreUtils.LogDebug(TAG, "Adding goods"); JSONObject suGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject ltGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject eqGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject upGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject paGoods = new JSONObject(JSONObject.Type.ARRAY); foreach (VirtualGood g in storeAssets.GetGoods()) { if (g is SingleUseVG) { suGoods.Add(g.toJSONObject()); } else if (g is EquippableVG) { eqGoods.Add(g.toJSONObject()); } else if (g is LifetimeVG) { ltGoods.Add(g.toJSONObject()); } else if (g is SingleUsePackVG) { paGoods.Add(g.toJSONObject()); } else if (g is UpgradeVG) { upGoods.Add(g.toJSONObject()); } } JSONObject goods = new JSONObject(JSONObject.Type.OBJECT); goods.AddField(JSONConsts.STORE_GOODS_SU, suGoods); goods.AddField(JSONConsts.STORE_GOODS_LT, ltGoods); goods.AddField(JSONConsts.STORE_GOODS_EQ, eqGoods); goods.AddField(JSONConsts.STORE_GOODS_UP, upGoods); goods.AddField(JSONConsts.STORE_GOODS_PA, paGoods); // StoreUtils.LogDebug(TAG, "Adding categories"); JSONObject categories = new JSONObject(JSONObject.Type.ARRAY); foreach (VirtualCategory vi in storeAssets.GetCategories()) { categories.Add(vi.toJSONObject()); } // StoreUtils.LogDebug(TAG, "Adding nonConsumables"); JSONObject nonConsumables = new JSONObject(JSONObject.Type.ARRAY); foreach (NonConsumableItem vi in storeAssets.GetNonConsumableItems()) { nonConsumables.Add(vi.toJSONObject()); } // StoreUtils.LogDebug(TAG, "Preparing StoreAssets JSONObject"); JSONObject storeAssetsObj = new JSONObject(JSONObject.Type.OBJECT); storeAssetsObj.AddField(JSONConsts.STORE_CATEGORIES, categories); storeAssetsObj.AddField(JSONConsts.STORE_CURRENCIES, currencies); storeAssetsObj.AddField(JSONConsts.STORE_CURRENCYPACKS, packs); storeAssetsObj.AddField(JSONConsts.STORE_GOODS, goods); storeAssetsObj.AddField(JSONConsts.STORE_NONCONSUMABLES, nonConsumables); string storeAssetsJSON = storeAssetsObj.print(); #if UNITY_ANDROID StoreUtils.LogDebug(TAG, "pushing data to StoreAssets on java side"); using (AndroidJavaClass jniStoreAssets = new AndroidJavaClass("com.soomla.unity.StoreAssets")) { jniStoreAssets.CallStatic("prepare", storeAssets.GetVersion(), storeAssetsJSON); } StoreUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on java side)"); #elif UNITY_IOS StoreUtils.LogDebug(TAG, "pushing data to StoreAssets on ios side"); storeAssets_Init(storeAssets.GetVersion(), storeAssetsJSON); StoreUtils.LogDebug(TAG, "done! (pushing data to StoreAssets on ios side)"); #endif }
public static void Initialize(IStoreAssets storeAssets) { // StoreUtils.LogDebug(TAG, "Adding currency"); JSONObject currencies = new JSONObject(JSONObject.Type.ARRAY); foreach(VirtualCurrency vi in storeAssets.GetCurrencies()) { currencies.Add(vi.toJSONObject()); } // StoreUtils.LogDebug(TAG, "Adding packs"); JSONObject packs = new JSONObject(JSONObject.Type.ARRAY); foreach(VirtualCurrencyPack vi in storeAssets.GetCurrencyPacks()) { packs.Add(vi.toJSONObject()); } // StoreUtils.LogDebug(TAG, "Adding goods"); JSONObject suGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject ltGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject eqGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject upGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject paGoods = new JSONObject(JSONObject.Type.ARRAY); foreach(VirtualGood g in storeAssets.GetGoods()){ if (g is SingleUseVG) { suGoods.Add(g.toJSONObject()); } else if (g is EquippableVG) { eqGoods.Add(g.toJSONObject()); } else if (g is UpgradeVG) { upGoods.Add(g.toJSONObject()); } else if (g is LifetimeVG) { ltGoods.Add(g.toJSONObject()); } else if (g is SingleUsePackVG) { paGoods.Add(g.toJSONObject()); } } JSONObject goods = new JSONObject(JSONObject.Type.OBJECT); goods.AddField(JSONConsts.STORE_GOODS_SU, suGoods); goods.AddField(JSONConsts.STORE_GOODS_LT, ltGoods); goods.AddField(JSONConsts.STORE_GOODS_EQ, eqGoods); goods.AddField(JSONConsts.STORE_GOODS_UP, upGoods); goods.AddField(JSONConsts.STORE_GOODS_PA, paGoods); // StoreUtils.LogDebug(TAG, "Adding categories"); JSONObject categories = new JSONObject(JSONObject.Type.ARRAY); foreach(VirtualCategory vi in storeAssets.GetCategories()) { categories.Add(vi.toJSONObject()); } // StoreUtils.LogDebug(TAG, "Adding nonConsumables"); JSONObject nonConsumables = new JSONObject(JSONObject.Type.ARRAY); foreach(NonConsumableItem vi in storeAssets.GetNonConsumableItems()) { nonConsumables.Add(vi.toJSONObject()); } // StoreUtils.LogDebug(TAG, "Preparing StoreAssets JSONObject"); JSONObject storeAssetsObj = new JSONObject(JSONObject.Type.OBJECT); storeAssetsObj.AddField(JSONConsts.STORE_CATEGORIES, categories); storeAssetsObj.AddField(JSONConsts.STORE_CURRENCIES, currencies); storeAssetsObj.AddField(JSONConsts.STORE_CURRENCYPACKS, packs); storeAssetsObj.AddField(JSONConsts.STORE_GOODS, goods); storeAssetsObj.AddField(JSONConsts.STORE_NONCONSUMABLES, nonConsumables); string storeAssetsJSON = storeAssetsObj.print(); instance._initialize(storeAssets.GetVersion(), storeAssetsJSON); }
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 }
/// <summary> /// Initializes <c>StoreInfo</c>. /// On first initialization, when the database doesn't have any previous version of the store /// metadata, <c>StoreInfo</c> gets loaded from the given <c>IStoreAssets</c>. /// After the first initialization, <c>StoreInfo</c> will be initialized from the database. /// /// IMPORTANT: If you want to override the current <c>StoreInfo</c>, you'll have to bump /// the version of your implementation of <c>IStoreAssets</c> in order to remove the /// metadata when the application loads. Bumping the version is done by returning a higher /// number in <c>IStoreAssets</c>'s <c>getVersion</c>. /// </summary> /// <param name="storeAssets">your game's economy</param> public static void Initialize(IStoreAssets storeAssets) { // Utils.LogDebug(TAG, "Adding currency"); JSONObject currencies = new JSONObject(JSONObject.Type.ARRAY); foreach (VirtualCurrency vi in storeAssets.GetCurrencies()) { currencies.Add(vi.toJSONObject()); } // Utils.LogDebug(TAG, "Adding packs"); JSONObject packs = new JSONObject(JSONObject.Type.ARRAY); foreach (VirtualCurrencyPack vi in storeAssets.GetCurrencyPacks()) { packs.Add(vi.toJSONObject()); } // Utils.LogDebug(TAG, "Adding goods"); JSONObject suGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject ltGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject eqGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject upGoods = new JSONObject(JSONObject.Type.ARRAY); JSONObject paGoods = new JSONObject(JSONObject.Type.ARRAY); foreach (VirtualGood g in storeAssets.GetGoods()) { if (g is SingleUseVG) { suGoods.Add(g.toJSONObject()); } else if (g is EquippableVG) { eqGoods.Add(g.toJSONObject()); } else if (g is UpgradeVG) { upGoods.Add(g.toJSONObject()); } else if (g is LifetimeVG) { ltGoods.Add(g.toJSONObject()); } else if (g is SingleUsePackVG) { paGoods.Add(g.toJSONObject()); } } JSONObject goods = new JSONObject(JSONObject.Type.OBJECT); goods.AddField(JSONConsts.STORE_GOODS_SU, suGoods); goods.AddField(JSONConsts.STORE_GOODS_LT, ltGoods); goods.AddField(JSONConsts.STORE_GOODS_EQ, eqGoods); goods.AddField(JSONConsts.STORE_GOODS_UP, upGoods); goods.AddField(JSONConsts.STORE_GOODS_PA, paGoods); // Utils.LogDebug(TAG, "Adding categories"); JSONObject categories = new JSONObject(JSONObject.Type.ARRAY); foreach (VirtualCategory vi in storeAssets.GetCategories()) { categories.Add(vi.toJSONObject()); } // Utils.LogDebug(TAG, "Adding nonConsumables"); JSONObject nonConsumables = new JSONObject(JSONObject.Type.ARRAY); foreach (NonConsumableItem vi in storeAssets.GetNonConsumableItems()) { nonConsumables.Add(vi.toJSONObject()); } // Utils.LogDebug(TAG, "Preparing StoreAssets JSONObject"); JSONObject storeAssetsObj = new JSONObject(JSONObject.Type.OBJECT); storeAssetsObj.AddField(JSONConsts.STORE_CATEGORIES, categories); storeAssetsObj.AddField(JSONConsts.STORE_CURRENCIES, currencies); storeAssetsObj.AddField(JSONConsts.STORE_CURRENCYPACKS, packs); storeAssetsObj.AddField(JSONConsts.STORE_GOODS, goods); storeAssetsObj.AddField(JSONConsts.STORE_NONCONSUMABLES, nonConsumables); string storeAssetsJSON = storeAssetsObj.print(); instance._initialize(storeAssets.GetVersion(), storeAssetsJSON); }