Beispiel #1
0
    private void declareProductId(SoomlaScriptBuilder builder, string id, MarketInfo marketInfo)
    {
        bool hasOverrides = false;

        // for iOS
        if (marketInfo.useIos)
        {
            builder.AppendLine("#if UNITY_IOS");
            builder.AppendLine(string.Format("public const string {0}_PRODUCT_ID = \"{1}\";", id.ToUpper(), marketInfo.iosId));
            hasOverrides = true;
        }
        // for Android
        if (marketInfo.useAndroid)
        {
            if (hasOverrides)
            {
                builder.AppendLine("#elif UNITY_ANDROID");
            }
            else
            {
                builder.AppendLine("#if UNITY_ANDROID");
            }
            builder.AppendLine(string.Format("public const string {0}_PRODUCT_ID = \"{1}\";", id.ToUpper(), marketInfo.androidId));
            hasOverrides = true;
        }
        // default value
        if (hasOverrides)
        {
            builder.AppendLine("#else");
        }
        builder.AppendLine(string.Format("public const string {0}_PRODUCT_ID = \"{1}\";", id.ToUpper(), marketInfo.productId));
        if (hasOverrides)
        {
            builder.AppendLine("#endif");
        }
    }
	private void declareProductId(SoomlaScriptBuilder builder, string id, MarketInfo marketInfo) {
		bool hasOverrides = false;
		// for iOS
		if (marketInfo.useIos) {
			builder.AppendLine("#if UNITY_IOS");
			builder.AppendLine(string.Format("public const string {0}_PRODUCT_ID = \"{1}\";", id.ToUpper(), marketInfo.iosId));
			hasOverrides = true;
		}
		// for Android
		if (marketInfo.useAndroid) {
			if (hasOverrides) {
				builder.AppendLine("#elif UNITY_ANDROID");
			} else {
				builder.AppendLine("#if UNITY_ANDROID");
			}
			builder.AppendLine(string.Format("public const string {0}_PRODUCT_ID = \"{1}\";", id.ToUpper(), marketInfo.androidId));
			hasOverrides = true;
		}
		// default value
		if (hasOverrides) {
			builder.AppendLine("#else");
		}
		builder.AppendLine(string.Format("public const string {0}_PRODUCT_ID = \"{1}\";", id.ToUpper(), marketInfo.productId));
        if (hasOverrides) {
            builder.AppendLine("#endif");
        }
    }
    public void generateSoomlaAssets()
    {
        string goodsVariables = "";
        
        SoomlaScriptBuilder builder = new SoomlaScriptBuilder();
		builder.AppendLine("using UnityEngine;");
		builder.AppendLine("using System.Collections;");
		builder.AppendLine("using System.Collections.Generic;");
		builder.AppendLine("using Soomla.Store;");
		builder.AppendLine ();

		builder.AppendLine ("/// <summary>");
		builder.AppendLine ("/// This class defines our game's economy, which includes virtual goods, virtual currencies");
		builder.AppendLine ("/// and currency packs, virtual categories");
		builder.AppendLine ("/// </summary>");
		builder.AppendLine("public class SoomlaAssets : IStoreAssets {");
		builder.IndentLevel++;
		builder.AppendLine();

		builder.AppendLine ("/** Static Final Members **/");
		builder.AppendLine ();

        for (int i = 0; i < currencies.Count; i++) {
			builder.AppendLine(string.Format("public const string {0}_ITEM_ID = \"{1}\";", currencies[i].ID.ToUpper(), currencies[i].ID));
			builder.AppendLine();
		}
        
		builder.AppendLine();
        for (int i = 0; i < currencyPacks.Count; i++) {
			builder.AppendLine(string.Format("public const string {0}_ITEM_ID = \"{1}\";", currencyPacks[i].ID.ToUpper(), currencyPacks[i].ID));
			declareProductId(builder, currencyPacks[i].ID, currencyPacks[i].marketInfo);

			builder.AppendLine();
		}
        
        builder.AppendLine();
        for (int i = 0; i < goods.Count; i++) {
			builder.AppendLine(string.Format("public const string {0}_ITEM_ID = \"{1}\";", goods[i].ID.ToUpper(), goods[i].ID));
			if (goods[i].typePurchase == ZFGood.PurchaseInfo.Market) {
				declareProductId(builder, goods[i].ID, goods[i].marketInfo);
            }
			goodsVariables += goods[i].ID.ToUpper() + "_ITEM_ID, ";
			builder.AppendLine();
		}
        
        builder.AppendLine ();
		builder.AppendLine ();
		//create constructors for each soomla object
		//	Virtual Currencies
		builder.AppendLine ("/** Virtual Currencies **/");
		builder.AppendLine ();

		for (int i = 0; i < currencies.Count; i++) {
			builder.AppendLine("public static VirtualCurrency " + currencies[i].ID.ToUpper() + " = new VirtualCurrency(");
			builder.IndentLevel ++;
			builder.AppendLine("\"" + currencies[i].name + "\",\t\t\t\t\t//name");
			builder.AppendLine("\"\",\t\t\t\t//description");
			builder.AppendLine(currencies[i].ID.ToUpper() + "_ITEM_ID\t\t\t\t//item id");
			builder.IndentLevel --;
			builder.AppendLine(");");
			builder.AppendLine();
        }
        
		builder.AppendLine();
		builder.AppendLine ("/** Virtual Currency Packs **/");
		builder.AppendLine ();

		//	Virtual Currency Packs
		for (int i = 0; i < currencyPacks.Count; i++) {
			builder.AppendLine("public static VirtualCurrencyPack " + currencyPacks[i].ID.ToUpper() + " = new VirtualCurrencyPack(");
			builder.IndentLevel ++;
			builder.AppendLine("\"" + currencyPacks[i].name + "\",\t\t\t\t\t//name");
			builder.AppendLine("\"" + currencyPacks[i].description + "\",\t\t\t\t//description");
			builder.AppendLine(currencyPacks[i].ID.ToUpper() + "_ITEM_ID,\t\t\t\t//item id");
			builder.AppendLine(currencyPacks[i].currency_amount + ",\t\t\t\t//number of currencies in the pack");
			builder.AppendLine(currencyPacks[i].currency_itemId.ToUpper() + "_ITEM_ID,\t\t\t\t//the currency associated with this pack");
			builder.AppendLine("new PurchaseWithMarket(" + currencyPacks[i].ID.ToUpper() + "_PRODUCT_ID, " + currencyPacks[i].marketInfo.price + ")");
			builder.IndentLevel --;
			builder.AppendLine(");");
            builder.AppendLine();
        }
        
		builder.AppendLine ();
		builder.AppendLine ("/** Virtual Goods **/");
		builder.AppendLine ();

		//	Virtual Goods
		for (int i = 0; i < goods.Count; i++) { 
			builder.AppendLine(string.Format("public static VirtualGood {0} = new {1}(", goods[i].ID.ToUpper(), goods[i].goodType));
           	builder.IndentLevel ++;


			if (goods[i].goodType == ZFGood.GoodType.SingleUsePackVG) {
				builder.AppendLine("\"" + goods[i].good_itemId + "\",\t\t\t\t//item id");
				builder.AppendLine(goods[i].good_amount + ",\t\t\t\t//number of goods in the pack");
			} else if (goods[i].goodType == ZFGood.GoodType.EquippableVG) {
				builder.AppendLine("EquippableVG.EquippingModel.LOCAL,");
			}
                
			builder.AppendLine("\"" + goods[i].name + "\",\t\t\t\t\t//name");
			builder.AppendLine("\"" + goods[i].description + "\",\t\t\t\t//description");
			builder.AppendLine(goods[i].ID.ToUpper() + "_ITEM_ID,\t\t\t\t//item id");

			if(goods[i].typePurchase == ZFGood.PurchaseInfo.Market) {
				builder.AppendLine("new PurchaseWithMarket(" + goods[i].ID.ToUpper() + "_PRODUCT_ID, " + goods[i].marketInfo.price + ")\t\t\t\t//the way this virtual good is purchased");
			} else {
				builder.AppendLine("new PurchaseWithVirtualItem(" + goods[i].virtualInfo.pvi_itemId.ToUpper() + "_ITEM_ID, " + goods[i].virtualInfo.pvi_amount + ")\t\t\t\t//the way this virtual good is purchased");
            }
            builder.IndentLevel --;
            builder.AppendLine(");");
			builder.AppendLine();
		}
       
		builder.AppendLine();
		builder.AppendLine ("/** Virtual Categories **/");
		builder.AppendLine ("// The muffin rush theme doesn't support categories, so we just put everything under a general category.");
        // add GENERAL_CATEGORY
		// remove last ", "
		goodsVariables = goodsVariables.Remove (goodsVariables.Length - 2, 2);
		builder.AppendLine("public static VirtualCategory GENERAL_CATEGORY = new VirtualCategory(");
		builder.IndentLevel ++;
		builder.AppendLine("\"General\", new List<string>(new string[] {" + goodsVariables + "})");
        builder.IndentLevel --;
		builder.AppendLine(");");
		builder.AppendLine();


		//get() methods for Soomla objects
		// implement GetVersion
		builder.AppendLine ("/// <summary>");
		builder.AppendLine ("/// see parent.");
		builder.AppendLine ("/// </summary>");
		builder.AppendLine("public int GetVersion() {");
		builder.IndentLevel ++;
		builder.AppendLine("return 0;");
        builder.IndentLevel --;
		builder.AppendLine("}");
        builder.AppendLine();

		// implement GetCurrencies
		string currenciesSequence = "";
		for (int i = 0; i < currencies.Count; i++) {
			currenciesSequence += currencies[i].ID.ToUpper();
			if (i != currencies.Count - 1) {
				currenciesSequence += ", ";
            }
		}

		builder.AppendLine ("/// <summary>");
		builder.AppendLine ("/// see parent.");
		builder.AppendLine ("/// </summary>");
		builder.AppendLine("public VirtualCurrency[] GetCurrencies() {");
		builder.IndentLevel ++;
		builder.AppendLine("return new VirtualCurrency[]{" + currenciesSequence + "};");
		builder.IndentLevel --;
		builder.AppendLine("}");
		builder.AppendLine();

		// implement GetCurrencyPacks
		string currencyPacksSequence = "";
		for (int i = 0; i < currencyPacks.Count; i++) {
			currencyPacksSequence += currencyPacks[i].ID.ToUpper();
			if (i != currencyPacks.Count - 1) {
				currencyPacksSequence += ", ";
			}
		}

		builder.AppendLine ("/// <summary>");
		builder.AppendLine ("/// see parent.");
		builder.AppendLine ("/// </summary>");
		builder.AppendLine("public VirtualCurrencyPack[] GetCurrencyPacks() {");
		builder.IndentLevel ++;
		builder.AppendLine("return new VirtualCurrencyPack[]{" + currencyPacksSequence + "};");
		builder.IndentLevel --;
        builder.AppendLine("}");
        builder.AppendLine();
        
		// implement GetGoods
		string goodsSequence = "";
		for (int i = 0; i < goods.Count; i++) {
			goodsSequence += goods[i].ID.ToUpper();
			if (i != goods.Count - 1) {
				goodsSequence += ", ";
			}
		}

		builder.AppendLine ("/// <summary>");
		builder.AppendLine ("/// see parent.");
		builder.AppendLine ("/// </summary>");
		builder.AppendLine("public VirtualGood[] GetGoods() {");
		builder.IndentLevel ++;
		builder.AppendLine("return new VirtualGood[]{" + goodsSequence + "};");
		builder.IndentLevel --;
        builder.AppendLine("}");
        builder.AppendLine();

		// implement GetCategories
		builder.AppendLine ("/// <summary>");
		builder.AppendLine ("/// see parent.");
		builder.AppendLine ("/// </summary>");
		builder.AppendLine("public VirtualCategory[] GetCategories() {");
		builder.IndentLevel ++;
		builder.AppendLine("return new VirtualCategory[]{GENERAL_CATEGORY};");
		builder.IndentLevel --;
        builder.AppendLine("}");
        builder.AppendLine();
        

        // end class
		builder.IndentLevel--;
		builder.AppendLine("}");

		string path = @"Assets/SoomlaAssets.cs";
		using (StreamWriter sw = File.CreateText(path))
		{
			sw.Write(builder.ToString());
		}
	}
Beispiel #4
0
    public void generateSoomlaAssets()
    {
        string goodsVariables = "";

        SoomlaScriptBuilder builder = new SoomlaScriptBuilder();

        builder.AppendLine("using UnityEngine;");
        builder.AppendLine("using System.Collections;");
        builder.AppendLine("using System.Collections.Generic;");
        builder.AppendLine("using Soomla.Store;");
        builder.AppendLine();

        builder.AppendLine("/// <summary>");
        builder.AppendLine("/// This class defines our game's economy, which includes virtual goods, virtual currencies");
        builder.AppendLine("/// and currency packs, virtual categories");
        builder.AppendLine("/// </summary>");
        builder.AppendLine("public class SoomlaAssets : IStoreAssets {");
        builder.IndentLevel++;
        builder.AppendLine();

        builder.AppendLine("/** Static Final Members **/");
        builder.AppendLine();

        for (int i = 0; i < currencies.Count; i++)
        {
            builder.AppendLine(string.Format("public const string {0}_ITEM_ID = \"{1}\";", currencies[i].ID.ToUpper(), currencies[i].ID));
            builder.AppendLine();
        }

        builder.AppendLine();
        for (int i = 0; i < currencyPacks.Count; i++)
        {
            builder.AppendLine(string.Format("public const string {0}_ITEM_ID = \"{1}\";", currencyPacks[i].ID.ToUpper(), currencyPacks[i].ID));
            declareProductId(builder, currencyPacks[i].ID, currencyPacks[i].marketInfo);

            builder.AppendLine();
        }

        builder.AppendLine();
        for (int i = 0; i < goods.Count; i++)
        {
            builder.AppendLine(string.Format("public const string {0}_ITEM_ID = \"{1}\";", goods[i].ID.ToUpper(), goods[i].ID));
            if (goods[i].typePurchase == ZFGood.PurchaseInfo.Market)
            {
                declareProductId(builder, goods[i].ID, goods[i].marketInfo);
            }
            goodsVariables += goods[i].ID.ToUpper() + "_ITEM_ID, ";
            builder.AppendLine();
        }

        builder.AppendLine();
        builder.AppendLine();
        //create constructors for each soomla object
        //	Virtual Currencies
        builder.AppendLine("/** Virtual Currencies **/");
        builder.AppendLine();

        for (int i = 0; i < currencies.Count; i++)
        {
            builder.AppendLine("public static VirtualCurrency " + currencies[i].ID.ToUpper() + " = new VirtualCurrency(");
            builder.IndentLevel++;
            builder.AppendLine("\"" + currencies[i].name + "\",\t\t\t\t\t//name");
            builder.AppendLine("\"\",\t\t\t\t//description");
            builder.AppendLine(currencies[i].ID.ToUpper() + "_ITEM_ID\t\t\t\t//item id");
            builder.IndentLevel--;
            builder.AppendLine(");");
            builder.AppendLine();
        }

        builder.AppendLine();
        builder.AppendLine("/** Virtual Currency Packs **/");
        builder.AppendLine();

        //	Virtual Currency Packs
        for (int i = 0; i < currencyPacks.Count; i++)
        {
            builder.AppendLine("public static VirtualCurrencyPack " + currencyPacks[i].ID.ToUpper() + " = new VirtualCurrencyPack(");
            builder.IndentLevel++;
            builder.AppendLine("\"" + currencyPacks[i].name + "\",\t\t\t\t\t//name");
            builder.AppendLine("\"" + currencyPacks[i].description + "\",\t\t\t\t//description");
            builder.AppendLine(currencyPacks[i].ID.ToUpper() + "_ITEM_ID,\t\t\t\t//item id");
            builder.AppendLine(currencyPacks[i].currency_amount + ",\t\t\t\t//number of currencies in the pack");
            builder.AppendLine(currencyPacks[i].currency_itemId.ToUpper() + "_ITEM_ID,\t\t\t\t//the currency associated with this pack");
            builder.AppendLine("new PurchaseWithMarket(" + currencyPacks[i].ID.ToUpper() + "_PRODUCT_ID, " + currencyPacks[i].marketInfo.price + ")");
            builder.IndentLevel--;
            builder.AppendLine(");");
            builder.AppendLine();
        }

        builder.AppendLine();
        builder.AppendLine("/** Virtual Goods **/");
        builder.AppendLine();

        //	Virtual Goods
        for (int i = 0; i < goods.Count; i++)
        {
            builder.AppendLine(string.Format("public static VirtualGood {0} = new {1}(", goods[i].ID.ToUpper(), goods[i].goodType));
            builder.IndentLevel++;


            if (goods[i].goodType == ZFGood.GoodType.SingleUsePackVG)
            {
                builder.AppendLine("\"" + goods[i].good_itemId + "\",\t\t\t\t//item id");
                builder.AppendLine(goods[i].good_amount + ",\t\t\t\t//number of goods in the pack");
            }
            else if (goods[i].goodType == ZFGood.GoodType.EquippableVG)
            {
                builder.AppendLine("EquippableVG.EquippingModel.LOCAL,");
            }

            builder.AppendLine("\"" + goods[i].name + "\",\t\t\t\t\t//name");
            builder.AppendLine("\"" + goods[i].description + "\",\t\t\t\t//description");
            builder.AppendLine(goods[i].ID.ToUpper() + "_ITEM_ID,\t\t\t\t//item id");

            if (goods[i].typePurchase == ZFGood.PurchaseInfo.Market)
            {
                builder.AppendLine("new PurchaseWithMarket(" + goods[i].ID.ToUpper() + "_PRODUCT_ID, " + goods[i].marketInfo.price + ")\t\t\t\t//the way this virtual good is purchased");
            }
            else
            {
                builder.AppendLine("new PurchaseWithVirtualItem(" + goods[i].virtualInfo.pvi_itemId.ToUpper() + "_ITEM_ID, " + goods[i].virtualInfo.pvi_amount + ")\t\t\t\t//the way this virtual good is purchased");
            }
            builder.IndentLevel--;
            builder.AppendLine(");");
            builder.AppendLine();
        }

        builder.AppendLine();
        builder.AppendLine("/** Virtual Categories **/");
        builder.AppendLine("// The muffin rush theme doesn't support categories, so we just put everything under a general category.");
        // add GENERAL_CATEGORY
        // remove last ", "
        goodsVariables = goodsVariables.Remove(goodsVariables.Length - 2, 2);
        builder.AppendLine("public static VirtualCategory GENERAL_CATEGORY = new VirtualCategory(");
        builder.IndentLevel++;
        builder.AppendLine("\"General\", new List<string>(new string[] {" + goodsVariables + "})");
        builder.IndentLevel--;
        builder.AppendLine(");");
        builder.AppendLine();


        //get() methods for Soomla objects
        // implement GetVersion
        builder.AppendLine("/// <summary>");
        builder.AppendLine("/// see parent.");
        builder.AppendLine("/// </summary>");
        builder.AppendLine("public int GetVersion() {");
        builder.IndentLevel++;
        builder.AppendLine("return 0;");
        builder.IndentLevel--;
        builder.AppendLine("}");
        builder.AppendLine();

        // implement GetCurrencies
        string currenciesSequence = "";

        for (int i = 0; i < currencies.Count; i++)
        {
            currenciesSequence += currencies[i].ID.ToUpper();
            if (i != currencies.Count - 1)
            {
                currenciesSequence += ", ";
            }
        }

        builder.AppendLine("/// <summary>");
        builder.AppendLine("/// see parent.");
        builder.AppendLine("/// </summary>");
        builder.AppendLine("public VirtualCurrency[] GetCurrencies() {");
        builder.IndentLevel++;
        builder.AppendLine("return new VirtualCurrency[]{" + currenciesSequence + "};");
        builder.IndentLevel--;
        builder.AppendLine("}");
        builder.AppendLine();

        // implement GetCurrencyPacks
        string currencyPacksSequence = "";

        for (int i = 0; i < currencyPacks.Count; i++)
        {
            currencyPacksSequence += currencyPacks[i].ID.ToUpper();
            if (i != currencyPacks.Count - 1)
            {
                currencyPacksSequence += ", ";
            }
        }

        builder.AppendLine("/// <summary>");
        builder.AppendLine("/// see parent.");
        builder.AppendLine("/// </summary>");
        builder.AppendLine("public VirtualCurrencyPack[] GetCurrencyPacks() {");
        builder.IndentLevel++;
        builder.AppendLine("return new VirtualCurrencyPack[]{" + currencyPacksSequence + "};");
        builder.IndentLevel--;
        builder.AppendLine("}");
        builder.AppendLine();

        // implement GetGoods
        string goodsSequence = "";

        for (int i = 0; i < goods.Count; i++)
        {
            goodsSequence += goods[i].ID.ToUpper();
            if (i != goods.Count - 1)
            {
                goodsSequence += ", ";
            }
        }

        builder.AppendLine("/// <summary>");
        builder.AppendLine("/// see parent.");
        builder.AppendLine("/// </summary>");
        builder.AppendLine("public VirtualGood[] GetGoods() {");
        builder.IndentLevel++;
        builder.AppendLine("return new VirtualGood[]{" + goodsSequence + "};");
        builder.IndentLevel--;
        builder.AppendLine("}");
        builder.AppendLine();

        // implement GetCategories
        builder.AppendLine("/// <summary>");
        builder.AppendLine("/// see parent.");
        builder.AppendLine("/// </summary>");
        builder.AppendLine("public VirtualCategory[] GetCategories() {");
        builder.IndentLevel++;
        builder.AppendLine("return new VirtualCategory[]{GENERAL_CATEGORY};");
        builder.IndentLevel--;
        builder.AppendLine("}");
        builder.AppendLine();


        // end class
        builder.IndentLevel--;
        builder.AppendLine("}");

        string path = @"Assets/SoomlaAssets.cs";

        using (StreamWriter sw = File.CreateText(path))
        {
            sw.Write(builder.ToString());
        }
    }