コード例 #1
0
        //draws the in app purchase editor
        void DrawIAP(List<IAPGroup> list)
        {
            EditorGUILayout.BeginHorizontal();
            GUI.backgroundColor = Color.yellow;

            //draw yellow button for adding a new IAP group
            if (GUILayout.Button("Add new Category"))
            {
                //create new group, give it a generic name based on
                //the current unix time and add it to the list of groups
                IAPGroup newGroup = new IAPGroup();
                string timestamp = GenerateUnixTime();
                newGroup.name = "Grp " + timestamp;
                newGroup.id = timestamp;
                list.Add(newGroup);
                return;
            }

            GUI.backgroundColor = Color.white;
            EditorGUILayout.EndHorizontal();

            //begin a scrolling view inside this tab, pass in current Vector2 scroll position 
            scrollPosIAP = EditorGUILayout.BeginScrollView(scrollPosIAP, GUILayout.Height(462));
            GUILayout.Space(20);

            //loop over IAP groups
            for (int i = 0; i < list.Count; i++)
            {
                //cache group
                IAPGroup group = list[i];
                //populate shop container variables if ShopManager is present
                Container shopGroup = null;
                if (shop)
                {
                    shopGroup = shop.GetContainer(group.id);
                    if (shopGroup == null)
                    {
                        shopGroup = new Container();
                        shopGroup.id = group.id;
                        shop.containers.Add(shopGroup);
                    }
                }

                EditorGUILayout.BeginHorizontal();
                GUI.backgroundColor = Color.yellow;
                //button for adding a new IAPObject (product) to this group
                if (GUILayout.Button("New Object", GUILayout.Width(120)))
                {
                    IAPObject newObj = new IAPObject();
                    //add platform dependent ids to the local list
                    int platforms = System.Enum.GetValues(typeof(IAPPlatform)).Length;
                    for (int j = 0; j < platforms; j++)
                        newObj.localId.Add(new IAPIdentifier());

                    group.items.Add(newObj);
                    break;
                }

                //draw group properties
                GUI.backgroundColor = Color.white;
                EditorGUILayout.LabelField("Category:", GUILayout.Width(60));
                group.name = EditorGUILayout.TextField(group.name, GUILayout.Width(90));
                GUILayout.FlexibleSpace();

                if (!shop)
                    EditorGUILayout.LabelField("No ShopManager prefab found in this scene!", GUILayout.Width(300));
                else
                {
                    EditorGUILayout.LabelField("Prefab:", GUILayout.Width(45));
                    shopGroup.prefab = (GameObject)EditorGUILayout.ObjectField(shopGroup.prefab, typeof(GameObject), false, GUILayout.Width(100));
                    GUILayout.Space(10);
                    EditorGUILayout.LabelField("Parent:", GUILayout.Width(45));
                    shopGroup.parent = (Transform)EditorGUILayout.ObjectField(shopGroup.parent, typeof(Transform), true, GUILayout.Width(100));
                }
                
                GUILayout.FlexibleSpace();

                //button width for up & down buttons. These should always be at the same width,
                //so if there's only one button (e.g. if there's only one group), the width must be extended
                int groupUpWidth = 22;
                int groupDownWidth = 22;
                if (i == 0) groupDownWidth = 48;
                if (i == list.Count - 1) groupUpWidth = 48;

                //draw up & down buttons for re-ordering groups
                //this will simply switch references in the list
                //hotControl and keyboardControl unsets current mouse focus
                if (i > 0 && GUILayout.Button("▲", GUILayout.Width(groupUpWidth)))
                {
                    list[i] = list[i - 1];
                    list[i - 1] = group;
                    EditorGUIUtility.hotControl = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }
                if (i < list.Count - 1 && GUILayout.Button("▼", GUILayout.Width(groupDownWidth)))
                {
                    list[i] = list[i + 1];
                    list[i + 1] = group;
                    EditorGUIUtility.hotControl = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }

                //button for removing a group including items
                GUI.backgroundColor = Color.gray;
                if (GUILayout.Button("X", GUILayout.Width(20)))
                {
                    if(shop) shop.containers.Remove(shopGroup);
                    list.RemoveAt(i);
                    break;
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

                //draw header information for each item property
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(58);
                EditorGUILayout.LabelField("ID:", GUILayout.Width(100));
                EditorGUILayout.LabelField("Icon:", GUILayout.Width(65));
                EditorGUILayout.LabelField("Type:", GUILayout.Width(80));
                EditorGUILayout.LabelField("Fetch:", GUILayout.Width(100));
                EditorGUILayout.LabelField("Title:", GUILayout.Width(145));
                if (group.items.Count == 1) GUILayout.Space(50);
                EditorGUILayout.LabelField("Description:", GUILayout.Width(150));
                EditorGUILayout.LabelField("Specific Settings:", GUILayout.Width(135));
                EditorGUILayout.LabelField("Price:", GUILayout.Width(100));
                EditorGUILayout.EndHorizontal();

                //loop over items in this group
                for (int j = 0; j < group.items.Count; j++)
                {
                    //cache item reference
                    IAPObject obj = group.items[j];

                    EditorGUILayout.BeginHorizontal();

                    obj.platformFoldout = EditorGUILayout.Foldout(obj.platformFoldout, "");
                    IAPType selectedType = obj.type;

                    //draw IAPObject (item/product) properties
                    obj.id = EditorGUILayout.TextField(obj.id, GUILayout.Width(100));
                    obj.icon = EditorGUILayout.ObjectField(obj.icon, typeof(Sprite), false, GUILayout.Width(65)) as Sprite;
                    obj.type = (IAPType)EditorGUILayout.EnumPopup(obj.type, GUILayout.Width(90));
                    obj.fetch = EditorGUILayout.Toggle(obj.fetch, GUILayout.Width(20));
                    obj.title = EditorGUILayout.TextField(obj.title);
                    obj.description = EditorGUILayout.TextField(obj.description);

                    if (obj.type != selectedType)
                    {
                        obj.specific = "";
                        obj.amount = 0;
                    }

                    DrawTypeSettings(obj);

                    obj.realPrice = EditorGUILayout.TextField(obj.realPrice, GUILayout.Width(60));

                    //button for adding a requirement to this item
                    if (!string.IsNullOrEmpty(obj.req.entry))
                        GUI.backgroundColor = Color.yellow;
                    if (GUILayout.Button("R", GUILayout.Width(20)))
                    {
                        reqEditor = (RequirementEditor)EditorWindow.GetWindowWithRect(typeof(RequirementEditor), new Rect(0, 0, 300, 150), false, "Requirement");
                        reqEditor.obj = obj;
                    }

                    GUI.backgroundColor = Color.white;
                    //do the same here as with the group up & down buttons
                    //(see above)
                    int buttonUpWidth = 22;
                    int buttonDownWidth = 22;
                    if (j == 0) buttonDownWidth = 48;
                    if (j == group.items.Count - 1) buttonUpWidth = 48;

                    //draw up & down buttons for re-ordering items in a group
                    //this will simply switch references in the list
                    if (j > 0 && GUILayout.Button("▲", GUILayout.Width(buttonUpWidth)))
                    {
                        group.items[j] = group.items[j - 1];
                        group.items[j - 1] = obj;
                        EditorGUIUtility.hotControl = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }
                    if (j < group.items.Count - 1 && GUILayout.Button("▼", GUILayout.Width(buttonDownWidth)))
                    {
                        group.items[j] = group.items[j + 1];
                        group.items[j + 1] = obj;
                        EditorGUIUtility.hotControl = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }

                    //button for removing an item of the group
                    GUI.backgroundColor = Color.gray;
                    if (GUILayout.Button("X"))
                    {
                        group.items.RemoveAt(j);
                        break;
                    }
                    GUI.backgroundColor = Color.white;
                    EditorGUILayout.EndHorizontal();

                    //draw platform override foldout
                    if (obj.platformFoldout)
                    {
                        EditorGUILayout.LabelField("Platform ID Overrides");
                        for (int k = 0; k < obj.localId.Count; k++)
                        {
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Space(40);
                            obj.localId[k].overridden = EditorGUILayout.BeginToggleGroup("", obj.localId[k].overridden);
                            EditorGUILayout.BeginHorizontal();
                            obj.localId[k].id = EditorGUILayout.TextField(obj.localId[k].id, GUILayout.Width(120));
                            EditorGUILayout.LabelField(((IAPPlatform)k).ToString());
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.EndToggleGroup();
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                GUILayout.Space(30);
            }

            //ends the scrollview defined above
            EditorGUILayout.EndScrollView();
        }
コード例 #2
0
        //draws the in game content editor
        void DrawIGC(List<IAPGroup> list)
        {
            EditorGUILayout.BeginHorizontal();
            GUI.backgroundColor = Color.yellow;

            //draw currencies up to a maximum of 9
            //(there is no limitation, but 9 currencies do fit in the window nicely,
            //and there really shouldnt be a reason to have 9+ different currencies)
            if (script.currency.Count < 9)
            {
                //button for adding a new currency
                if (GUILayout.Button("Add Currency"))
                {
                    //create new currency, then loop over items
                    //and add a new currency slot for each of them 
                    IAPCurrency currency = new IAPCurrency();
                    script.currency.Add(currency);
                    return;
                }
            }
            else
            {
                //for more than 9 currencies,
                //we show a transparent button with no functionality
                GUI.backgroundColor = new Color(1, 0.9f, 0, 0.4f);
                if (GUILayout.Button("Add Currency"))
                { }
            }

            GUI.backgroundColor = Color.yellow;
            //draw yellow button for adding a new IAP group
            if (GUILayout.Button("Add new Category"))
            {
                //create new group, give it a generic name based on
                //the current system time and add it to the list of groups
                IAPGroup newGroup = new IAPGroup();
                string timestamp = GenerateUnixTime();
                newGroup.name = "Grp " + timestamp;
                newGroup.id = timestamp;
                list.Add(newGroup);
                return;
            }

            GUI.backgroundColor = Color.white;
            EditorGUILayout.EndHorizontal();

            //begin a scrolling view inside tab, pass in current Vector2 scroll position 
            scrollPosIGC = EditorGUILayout.BeginScrollView(scrollPosIGC, GUILayout.Height(462));
            GUILayout.Space(10);

            //only draw a box behind currencies if there are any
            if (script.currency.Count > 0)
            {
                EditorGUILayout.LabelField("Currencies:", EditorStyles.boldLabel);
                GUILayout.Space(10);
                GUI.Box(new Rect(10, 35, script.currency.Count * 110, 65), "");
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.Space(10);
            //loop through currencies
            for (int i = 0; i < script.currency.Count; i++)
            {
                IAPCurrency current = script.currency[i];
                EditorGUILayout.BeginVertical();
                //draw currency properties,
                //such as name and amount
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Name", GUILayout.Width(44));
                current.name = EditorGUILayout.TextField(current.name, GUILayout.Width(54));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Default", GUILayout.Width(44));
                script.currency[i].amount = EditorGUILayout.IntField(script.currency[i].amount, GUILayout.Width(54));
                EditorGUILayout.EndHorizontal();

                //button for deleting a currency
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(52);
                GUI.backgroundColor = Color.gray;
                if (GUILayout.Button("X", GUILayout.Width(54)))
                {
                    //ask again before deleting the currency,
                    //as deleting it could cause angry customers!
                    //it's probably better not to remove currencies in production versions
                    if (EditorUtility.DisplayDialog("Delete Currency?",
                        "Existing users might lose their funds associated with this currency when updating.",
                        "Continue", "Abort"))
                    {
                        //then remove the currency
                        script.currency.RemoveAt(i);
                        break;
                    }
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();
            GUILayout.Space(30);

            //loop over IAP groups
            for (int i = 0; i < list.Count; i++)
            {
                //cache group
                IAPGroup group = list[i];
                Container shopGroup = null;
                if (shop)
                {
                    shopGroup = shop.GetContainer(group.id);
                    if (shopGroup == null)
                    {
                        shopGroup = new Container();
                        shopGroup.id = group.id;
                        shop.containers.Add(shopGroup);
                    }
                }

                EditorGUILayout.BeginHorizontal();
                GUI.backgroundColor = Color.yellow;
                //button for adding a new IAPObject (product) to this group
                if (GUILayout.Button("New Object", GUILayout.Width(120)))
                {
                    IAPObject obj = new IAPObject();
                    group.items.Add(obj);
                    break;
                }
                GUI.backgroundColor = Color.white;

                //draw group properties
                EditorGUILayout.LabelField("Category:", GUILayout.Width(60));
                group.name = EditorGUILayout.TextField(group.name, GUILayout.Width(90));
                GUILayout.FlexibleSpace();

                if (!shop)
                    EditorGUILayout.LabelField("No ShopManager prefab found in this scene!", GUILayout.Width(300));
                else
                {
                    EditorGUILayout.LabelField("Prefab:", GUILayout.Width(45));
                    shopGroup.prefab = (GameObject)EditorGUILayout.ObjectField(shopGroup.prefab, typeof(GameObject), false, GUILayout.Width(100));
                    GUILayout.Space(10);
                    EditorGUILayout.LabelField("Parent:", GUILayout.Width(45));
                    shopGroup.parent = (Transform)EditorGUILayout.ObjectField(shopGroup.parent, typeof(Transform), true, GUILayout.Width(100));
                }

                GUILayout.FlexibleSpace();

                //same as in DrawIAP(),
                //move group up & down buttons
                int groupUpWidth = 22;
                int groupDownWidth = 22;
                if (i == 0) groupDownWidth = 48;
                if (i == list.Count - 1) groupUpWidth = 48;

                if (i > 0 && GUILayout.Button("▲", GUILayout.Width(groupUpWidth)))
                {
                    list[i] = list[i - 1];
                    list[i - 1] = group;
                    EditorGUIUtility.hotControl = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }
                if (i < list.Count - 1 && GUILayout.Button("▼", GUILayout.Width(groupDownWidth)))
                {
                    list[i] = list[i + 1];
                    list[i + 1] = group;
                    EditorGUIUtility.hotControl = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }

                //button for removing a group including items
                GUI.backgroundColor = Color.gray;
                if (GUILayout.Button("X", GUILayout.Width(20)))
                {
                    if(shop) shop.containers.Remove(shopGroup);
                    list.RemoveAt(i);
                    break;
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

                //draw header information for each item property
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("ID:", GUILayout.Width(120));
                EditorGUILayout.LabelField("Icon:", GUILayout.Width(65));
                EditorGUILayout.LabelField("Type:", GUILayout.Width(165));
                EditorGUILayout.LabelField("Title:", GUILayout.Width(122));
                if (group.items.Count == 1) GUILayout.Space(50);
                EditorGUILayout.LabelField("Description:", GUILayout.Width(150));
                EditorGUILayout.LabelField("Specific Settings:", GUILayout.Width(135));
                EditorGUILayout.LabelField("Price:", GUILayout.Width(100));
                EditorGUILayout.EndHorizontal();

                //loop over items in this group
                for (int j = 0; j < group.items.Count; j++)
                {
                    //cache item reference
                    IAPObject obj = group.items[j];
                    EditorGUILayout.BeginHorizontal();
                    IAPType selectedType = obj.type;

                    //draw IAPObject (item/product) properties
                    obj.id = EditorGUILayout.TextField(obj.id, GUILayout.Width(120));
                    obj.icon = EditorGUILayout.ObjectField(obj.icon, typeof(Sprite), false, GUILayout.Width(65)) as Sprite;
                    obj.type = (IAPType)EditorGUILayout.EnumPopup(obj.type, GUILayout.Width(110));
                    obj.title = EditorGUILayout.TextField(obj.title);
                    obj.description = EditorGUILayout.TextField(obj.description);

                    if (obj.type != selectedType)
                    {
                        obj.specific = "";
                        obj.amount = 0;
                    }

                    DrawTypeSettings(obj);

                    //price field
                    int priceIndex = 0;
                    for (int k = 0; k < currencyNames.Length; k++)
                    {
                        if (obj.virtualPrice.name == currencyNames[k])
                            priceIndex = k;
                    }
                    priceIndex = EditorGUILayout.Popup(priceIndex, currencyNames, GUILayout.Width(60));
                    obj.virtualPrice.name = currencyNames[priceIndex];
                    obj.virtualPrice.amount = EditorGUILayout.IntField(obj.virtualPrice.amount, GUILayout.Width(60));

                    //same as in DrawIAP(), requirement button
                    if (!string.IsNullOrEmpty(obj.req.entry))
                        GUI.backgroundColor = Color.yellow;
                    if (GUILayout.Button("R", GUILayout.Width(20)))
                    {
                        reqEditor = (RequirementEditor)EditorWindow.GetWindowWithRect(typeof(RequirementEditor), new Rect(0, 0, 300, 150), false, "Requirement");
                        reqEditor.obj = obj;
                    }

                    GUI.backgroundColor = Color.white;
                    //same as in DrawIAP(), move item up & down buttons
                    int buttonUpWidth = 22;
                    int buttonDownWidth = 22;
                    if (j == 0) buttonDownWidth = 48;
                    if (j == group.items.Count - 1) buttonUpWidth = 48;

                    if (j > 0 && GUILayout.Button("▲", GUILayout.Width(buttonUpWidth)))
                    {
                        group.items[j] = group.items[j - 1];
                        group.items[j - 1] = obj;
                        EditorGUIUtility.hotControl = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }
                    if (j < group.items.Count - 1 && GUILayout.Button("▼", GUILayout.Width(buttonDownWidth)))
                    {
                        group.items[j] = group.items[j + 1];
                        group.items[j + 1] = obj;
                        EditorGUIUtility.hotControl = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }

                    //button for removing an item of the group
                    GUI.backgroundColor = Color.gray;
                    if (GUILayout.Button("X"))
                    {
                        group.items.RemoveAt(j);
                        break;
                    }
                    GUI.backgroundColor = Color.white;
                    EditorGUILayout.EndHorizontal();
                }
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                GUILayout.Space(30);
            }

            //ends the scrollview defined above
            EditorGUILayout.EndScrollView();
        }
コード例 #3
0
        //draws the in game content editor
        void DrawIGC(List <IAPGroup> list)
        {
            EditorGUILayout.BeginHorizontal();
            GUI.backgroundColor = Color.yellow;

            //draw currencies up to a maximum of 7
            //(there is no limitation, but 7 currencies do fit in the window nicely,
            //and there really shouldnt be a reason to have 7+ different currencies)
            if (script.currency.Count < 7)
            {
                //button for adding a new currency
                if (GUILayout.Button("Add Currency"))
                {
                    //switch current currency selection to the first entry
                    currencyIndex = 0;
                    //create new currency, then loop over items
                    //and add a new currency slot for each of them
                    script.currency.Add(new IAPCurrency());
                    for (int i = 0; i < list.Count; i++)
                    {
                        for (int j = 0; j < list[i].items.Count; j++)
                        {
                            list[i].items[j].virtualPrice.Add(new IAPCurrency());
                        }
                    }
                    return;
                }
            }
            else
            {
                //for more than 7 currencies,
                //we show a transparent button with no functionality
                GUI.backgroundColor = new Color(1, 0.9f, 0, 0.4f);
                if (GUILayout.Button("Add Currency"))
                {
                }
            }

            //draw yellow button for adding a new IAP group
            if (GUILayout.Button("Add new Group"))
            {
                //create new group, give it a generic name based on
                //the current system time and add it to the list of groups
                IAPGroup newGroup  = new IAPGroup();
                string   timestamp = GenerateUnixTime();
                newGroup.name = "Grp " + timestamp;
                newGroup.id   = timestamp;
                list.Add(newGroup);
                return;
            }

            GUI.backgroundColor = Color.white;
            EditorGUILayout.EndHorizontal();

            //begin a scrolling view inside tab, pass in current Vector2 scroll position
            scrollPosIGC = EditorGUILayout.BeginScrollView(scrollPosIGC, GUILayout.Height(350));
            GUILayout.Space(20);
            EditorGUILayout.BeginHorizontal();
            //only draw a box behind currencies if there are any
            if (script.currency.Count > 0)
            {
                GUI.Box(new Rect(3, 15, 796, 95), "");
            }

            //loop through currencies
            for (int i = 0; i < script.currency.Count; i++)
            {
                EditorGUILayout.BeginVertical();
                //draw currency properties,
                //such as name and amount
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Name", GUILayout.Width(44));
                script.currency[i].name = EditorGUILayout.TextField(script.currency[i].name, GUILayout.Width(54));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Default", GUILayout.Width(44));
                script.currency[i].amount = EditorGUILayout.IntField(script.currency[i].amount, GUILayout.Width(54));
                EditorGUILayout.EndHorizontal();

                //button for deleting a currency
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(52);
                GUI.backgroundColor = Color.gray;
                if (GUILayout.Button("X", GUILayout.Width(54)))
                {
                    //ask again before deleting the currency,
                    //as deleting it could cause angry customers!
                    //it's probably better not to remove currencies in production versions
                    if (EditorUtility.DisplayDialog("Delete Currency?",
                                                    "Existing users might lose their funds associated with this currency when updating.",
                                                    "Continue", "Abort"))
                    {
                        //loop over items and remove the
                        //associated currency slot for each of them
                        for (int j = 0; j < list.Count; j++)
                        {
                            for (int k = 0; k < list[j].items.Count; k++)
                            {
                                list[j].items[k].virtualPrice.RemoveAt(i);
                            }
                        }
                        //then remove the currency
                        script.currency.RemoveAt(i);
                        //reposition current currency index
                        if (script.currency.Count > 0)
                        {
                            currencyIndex = 0;
                        }
                        else
                        {
                            currencyIndex = -1;
                        }
                        break;
                    }
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            //draw currency selector, if there are any
            if (script.currency.Count > 0)
            {
                GUILayout.Space(10);
                EditorGUILayout.BeginHorizontal();
                //get all currency names,
                //then draw a popup list for selecting the desired index
                currencyNames = GetCurrencyNames();
                EditorGUILayout.LabelField("Selected Currency:", GUILayout.Width(120));
                currencyIndex = EditorGUILayout.Popup(currencyIndex, currencyNames, GUILayout.Width(140));
                EditorGUILayout.EndHorizontal();
                GUILayout.Space(20);
            }

            //loop over IAP groups
            for (int i = 0; i < list.Count; i++)
            {
                //cache group
                IAPGroup group = list[i];
                //version 1.2 backwards compatibility fix (empty IAPGroup ids)
                if (string.IsNullOrEmpty(group.id))
                {
                    group.id = GenerateUnixTime();
                }

                Container shopGroup = null;
                if (shop)
                {
                    shopGroup = shop.GetContainer(group.id);
                    if (shopGroup == null)
                    {
                        shopGroup    = new Container();
                        shopGroup.id = group.id;
                        shop.containers.Add(shopGroup);
                    }
                }

                EditorGUILayout.BeginHorizontal();
                GUI.backgroundColor = Color.yellow;
                //button for adding a new IAPObject (product) to this group
                if (GUILayout.Button("New Product", GUILayout.Width(120)))
                {
                    IAPObject newObj = new IAPObject();
                    for (int j = 0; j < script.currency.Count; j++)
                    {
                        newObj.virtualPrice.Add(new IAPCurrency());
                    }
                    group.items.Add(newObj);
                    break;
                }
                GUI.backgroundColor = Color.white;

                //draw group properties
                EditorGUILayout.LabelField("Group:", GUILayout.Width(45));
                group.name = EditorGUILayout.TextField(group.name, GUILayout.Width(90));
                GUILayout.Space(10);
                EditorGUILayout.LabelField("Sort:", GUILayout.Width(35));
                orderType = (OrderType)EditorGUILayout.EnumPopup(orderType, GUILayout.Width(60));
                GUILayout.Space(10);

                if (!shop)
                {
                    EditorGUILayout.LabelField("No ShopManager prefab found in this scene!", GUILayout.Width(300));
                }
                else
                {
                    EditorGUILayout.LabelField("Prefab:", GUILayout.Width(45));
                    shopGroup.prefab = (GameObject)EditorGUILayout.ObjectField(shopGroup.prefab, typeof(GameObject), false, GUILayout.Width(100));
                    GUILayout.Space(10);
                    EditorGUILayout.LabelField("Parent:", GUILayout.Width(45));
                    shopGroup.parent = (Transform)EditorGUILayout.ObjectField(shopGroup.parent, typeof(Transform), true, GUILayout.Width(100));
                }

                GUILayout.FlexibleSpace();
                if (orderType != OrderType.none)
                {
                    group.items = orderProducts(group.items);
                    break;
                }

                //same as in DrawIAP(),
                //move group up & down buttons
                int groupUpWidth   = 22;
                int groupDownWidth = 22;
                if (i == 0)
                {
                    groupDownWidth = 48;
                }
                if (i == list.Count - 1)
                {
                    groupUpWidth = 48;
                }

                if (i > 0 && GUILayout.Button("▲", GUILayout.Width(groupUpWidth)))
                {
                    list[i]     = list[i - 1];
                    list[i - 1] = group;
                    EditorGUIUtility.hotControl      = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }
                if (i < list.Count - 1 && GUILayout.Button("▼", GUILayout.Width(groupDownWidth)))
                {
                    list[i]     = list[i + 1];
                    list[i + 1] = group;
                    EditorGUIUtility.hotControl      = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }

                //button for removing a group including items
                GUI.backgroundColor = Color.gray;
                if (GUILayout.Button("X", GUILayout.Width(20)))
                {
                    if (shop)
                    {
                        shop.containers.Remove(shopGroup);
                    }
                    list.RemoveAt(i);
                    break;
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

                //draw header information for each item property
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("ID:", GUILayout.Width(110));
                GUILayout.Space(20);
                EditorGUILayout.LabelField("Icon:", GUILayout.Width(75));
                GUILayout.Space(20);
                EditorGUILayout.LabelField("Type:", GUILayout.Width(100));
                GUILayout.Space(20);
                int spaceTitleToDescription = 90;
                if (group.items.Count == 1)
                {
                    spaceTitleToDescription = 110;
                }
                EditorGUILayout.LabelField("Title:", GUILayout.Width(spaceTitleToDescription));
                GUILayout.Space(20);
                int spaceDescriptionToPrice = 135;
                if (group.items.Count == 1)
                {
                    spaceDescriptionToPrice = 145;
                }
                EditorGUILayout.LabelField("Description:", GUILayout.Width(spaceDescriptionToPrice));
                GUILayout.Space(20);
                EditorGUILayout.LabelField("Price:", GUILayout.Width(40));
                GUILayout.Space(80);
                EditorGUILayout.EndHorizontal();

                //loop over items in this group
                for (int j = 0; j < group.items.Count; j++)
                {
                    //cache item reference
                    IAPObject obj = group.items[j];
                    EditorGUILayout.BeginHorizontal();

                    //draw IAPObject (item/product) properties
                    obj.id   = EditorGUILayout.TextField(obj.id, GUILayout.Width(120));
                    obj.icon = EditorGUILayout.ObjectField(obj.icon, typeof(Sprite), false, GUILayout.Width(65)) as Sprite;
                    obj.type = (IAPType)EditorGUILayout.EnumPopup(obj.type, GUILayout.Width(110));
                    //don't allow consumable/non consumable/subscription IAP types, they must be virtual
                    if (obj.type == IAPType.consumable)
                    {
                        obj.type = IAPType.consumableVirtual;
                    }
                    else if (obj.type == IAPType.nonConsumable || obj.type == IAPType.subscription)
                    {
                        obj.type = IAPType.nonConsumableVirtual;
                    }
                    //other item properties
                    obj.title       = EditorGUILayout.TextField(obj.title);
                    obj.description = EditorGUILayout.TextField(obj.description);

                    //if a currency has been selected previously,
                    //draw an input field for the selected currency
                    if (currencyIndex > -1)
                    {
                        //version 1.1 compability fix (virtual currency int -> IAPCurrency conversion)
                        if (obj.virtualPrice == null || currencyIndex > obj.virtualPrice.Count - 1)
                        {
                            GUI.backgroundColor = Color.gray;
                            if (GUILayout.Button("X"))
                            {
                                group.items.RemoveAt(j);
                                break;
                            }
                            GUI.backgroundColor = Color.white;
                            EditorGUILayout.EndHorizontal();
                            continue;
                        }

                        EditorGUILayout.BeginHorizontal();
                        IAPCurrency cur = obj.virtualPrice[currencyIndex];
                        cur.name = currencyNames[currencyIndex];
                        EditorGUILayout.LabelField(cur.name, GUILayout.Width(40));
                        cur.amount = EditorGUILayout.IntField(cur.amount, GUILayout.Width(60));
                        EditorGUILayout.EndHorizontal();
                    }
                    else
                    {
                        GUILayout.FlexibleSpace();
                    }

                    //same as in DrawIAP(), requirement button
                    if (!string.IsNullOrEmpty(obj.req.entry) || !string.IsNullOrEmpty(obj.req.nextId))
                    {
                        GUI.backgroundColor = Color.yellow;
                    }
                    if (GUILayout.Button("R", GUILayout.Width(20)))
                    {
                        reqEditor     = (RequirementEditor)EditorWindow.GetWindowWithRect(typeof(RequirementEditor), new Rect(0, 0, 300, 170), false, "Requirement");
                        reqEditor.obj = obj;
                    }

                    GUI.backgroundColor = Color.white;
                    //same as in DrawIAP(),
                    //move item up & down buttons
                    int buttonUpWidth   = 22;
                    int buttonDownWidth = 22;
                    if (j == 0)
                    {
                        buttonDownWidth = 48;
                    }
                    if (j == group.items.Count - 1)
                    {
                        buttonUpWidth = 48;
                    }

                    if (j > 0 && GUILayout.Button("▲", GUILayout.Width(buttonUpWidth)))
                    {
                        group.items[j]                   = group.items[j - 1];
                        group.items[j - 1]               = obj;
                        EditorGUIUtility.hotControl      = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }
                    if (j < group.items.Count - 1 && GUILayout.Button("▼", GUILayout.Width(buttonDownWidth)))
                    {
                        group.items[j]                   = group.items[j + 1];
                        group.items[j + 1]               = obj;
                        EditorGUIUtility.hotControl      = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }

                    //button for removing an item of the group
                    GUI.backgroundColor = Color.gray;
                    if (GUILayout.Button("X"))
                    {
                        group.items.RemoveAt(j);
                        break;
                    }
                    GUI.backgroundColor = Color.white;
                    EditorGUILayout.EndHorizontal();
                }
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                GUILayout.Space(30);
            }

            //ends the scrollview defined above
            EditorGUILayout.EndScrollView();
        }
コード例 #4
0
        //draws the in app purchase editor
        //for a specific OS
        void DrawIAP(List <IAPGroup> list)
        {
            EditorGUILayout.BeginHorizontal();
            GUI.backgroundColor = Color.yellow;

            //draw yellow button for adding a new IAP group
            if (GUILayout.Button("Add new Group"))
            {
                //create new group, give it a generic name based on
                //the current unix time and add it to the list of groups
                IAPGroup newGroup  = new IAPGroup();
                string   timestamp = GenerateUnixTime();
                newGroup.name = "Grp " + timestamp;
                newGroup.id   = timestamp;
                list.Add(newGroup);
                return;
            }

            GUI.backgroundColor = Color.white;
            EditorGUILayout.EndHorizontal();

            //begin a scrolling view inside this tab, pass in current Vector2 scroll position
            scrollPosIAP = EditorGUILayout.BeginScrollView(scrollPosIAP, GUILayout.Height(350));
            GUILayout.Space(20);

            //loop over IAP groups for this OS
            for (int i = 0; i < list.Count; i++)
            {
                //cache group
                IAPGroup group = list[i];
                //version 1.2 backwards compatibility fix (empty IAPGroup ids)
                if (string.IsNullOrEmpty(group.id))
                {
                    group.id = GenerateUnixTime();
                }

                //populate shop container variables if ShopManager is present
                Container shopGroup = null;
                if (shop)
                {
                    shopGroup = shop.GetContainer(group.id);
                    if (shopGroup == null)
                    {
                        shopGroup    = new Container();
                        shopGroup.id = group.id;
                        shop.containers.Add(shopGroup);
                    }
                }

                EditorGUILayout.BeginHorizontal();
                GUI.backgroundColor = Color.yellow;
                //button for adding a new IAPObject (product) to this group
                if (GUILayout.Button("New Product", GUILayout.Width(120)))
                {
                    IAPObject newObj = new IAPObject();
                    //add platform dependent ids to the local list
                    int platforms = System.Enum.GetValues(typeof(IAPPlatform)).Length;
                    for (int j = 0; j < platforms; j++)
                    {
                        newObj.localId.Add(new IAPIdentifier());
                    }

                    group.items.Add(newObj);
                    break;
                }

                //draw group properties
                GUI.backgroundColor = Color.white;
                EditorGUILayout.LabelField("Group:", GUILayout.Width(45));
                group.name = EditorGUILayout.TextField(group.name, GUILayout.Width(90));
                GUILayout.Space(10);
                EditorGUILayout.LabelField("Sort:", GUILayout.Width(35));
                orderType = (OrderType)EditorGUILayout.EnumPopup(orderType, GUILayout.Width(60));
                GUILayout.Space(10);

                if (!shop)
                {
                    EditorGUILayout.LabelField("No ShopManager prefab found in this scene!", GUILayout.Width(300));
                }
                else
                {
                    EditorGUILayout.LabelField("Prefab:", GUILayout.Width(45));
                    shopGroup.prefab = (GameObject)EditorGUILayout.ObjectField(shopGroup.prefab, typeof(GameObject), false, GUILayout.Width(100));
                    GUILayout.Space(10);
                    EditorGUILayout.LabelField("Parent:", GUILayout.Width(45));
                    shopGroup.parent = (Transform)EditorGUILayout.ObjectField(shopGroup.parent, typeof(Transform), true, GUILayout.Width(100));
                }

                GUILayout.FlexibleSpace();
                //check for order type and, if it
                //isn't equal to 'none', start ordering
                if (orderType != OrderType.none)
                {
                    group.items = orderProducts(group.items);
                    break;
                }

                //button width for up & down buttons
                //these should always be at the same width, so if there's
                //only one button (e.g. if there's only one group),
                //the width must be extended
                int groupUpWidth   = 22;
                int groupDownWidth = 22;
                if (i == 0)
                {
                    groupDownWidth = 48;
                }
                if (i == list.Count - 1)
                {
                    groupUpWidth = 48;
                }

                //draw up & down buttons for re-ordering groups
                //this will simply switch references in the list
                //hotControl and keyboardControl unsets current mouse focus
                if (i > 0 && GUILayout.Button("▲", GUILayout.Width(groupUpWidth)))
                {
                    list[i]     = list[i - 1];
                    list[i - 1] = group;
                    EditorGUIUtility.hotControl      = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }
                if (i < list.Count - 1 && GUILayout.Button("▼", GUILayout.Width(groupDownWidth)))
                {
                    list[i]     = list[i + 1];
                    list[i + 1] = group;
                    EditorGUIUtility.hotControl      = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }

                //button for removing a group including items
                GUI.backgroundColor = Color.gray;
                if (GUILayout.Button("X", GUILayout.Width(20)))
                {
                    if (shop)
                    {
                        shop.containers.Remove(shopGroup);
                    }
                    list.RemoveAt(i);
                    break;
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

                //draw header information for each item property
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(100);
                EditorGUILayout.LabelField("ID:", GUILayout.Width(45));
                GUILayout.Space(20);
                EditorGUILayout.LabelField("Icon:", GUILayout.Width(75));
                GUILayout.Space(20);
                EditorGUILayout.LabelField("Type:", GUILayout.Width(42));
                GUILayout.Space(20);
                EditorGUILayout.LabelField("Fetch:", GUILayout.Width(55));
                GUILayout.Space(20);
                int spaceTitleToDescription = 80;
                if (group.items.Count == 1)
                {
                    spaceTitleToDescription = 125;
                }
                EditorGUILayout.LabelField("Title:", GUILayout.Width(spaceTitleToDescription));
                GUILayout.Space(20);
                EditorGUILayout.LabelField("Description:", GUILayout.Width(100));
                GUILayout.Space(20);
                EditorGUILayout.LabelField("Price:", GUILayout.Width(100));
                EditorGUILayout.EndHorizontal();

                //loop over items in this group
                for (int j = 0; j < group.items.Count; j++)
                {
                    //cache item reference
                    IAPObject obj = group.items[j];
                    EditorGUILayout.BeginHorizontal();

                    //version < 2.1 compatibility (add per-platform ids)
                    int platforms = System.Enum.GetValues(typeof(IAPPlatform)).Length;
                    for (int k = obj.localId.Count; k < platforms; k++)
                    {
                        obj.localId.Add(new IAPIdentifier());
                    }

                    obj.platformFoldout = EditorGUILayout.Foldout(obj.platformFoldout, "");

                    //draw IAPObject (item/product) properties
                    obj.id   = EditorGUILayout.TextField(obj.id, GUILayout.Width(100));
                    obj.icon = EditorGUILayout.ObjectField(obj.icon, typeof(Sprite), false, GUILayout.Width(65)) as Sprite;
                    obj.type = (IAPType)EditorGUILayout.EnumPopup(obj.type, GUILayout.Width(110));
                    //don't allow virtual IAP types, they must be consumable/non consumable/subscription
                    if (obj.type == IAPType.consumableVirtual)
                    {
                        obj.type = IAPType.consumable;
                    }
                    else if (obj.type == IAPType.nonConsumableVirtual)
                    {
                        obj.type = IAPType.nonConsumable;
                    }
                    obj.fetch       = EditorGUILayout.Toggle(obj.fetch, GUILayout.Width(20));
                    obj.title       = EditorGUILayout.TextField(obj.title);
                    obj.description = EditorGUILayout.TextField(obj.description);
                    obj.realPrice   = EditorGUILayout.TextField(obj.realPrice, GUILayout.Width(80));

                    //button for adding a requirement to this item
                    if (!string.IsNullOrEmpty(obj.req.entry) || !string.IsNullOrEmpty(obj.req.nextId))
                    {
                        GUI.backgroundColor = Color.yellow;
                    }
                    if (GUILayout.Button("R", GUILayout.Width(20)))
                    {
                        reqEditor     = (RequirementEditor)EditorWindow.GetWindowWithRect(typeof(RequirementEditor), new Rect(0, 0, 300, 170), false, "Requirement");
                        reqEditor.obj = obj;
                    }

                    GUI.backgroundColor = Color.white;
                    //do the same here as with the group up & down buttons
                    //(see above)
                    int buttonUpWidth   = 22;
                    int buttonDownWidth = 22;
                    if (j == 0)
                    {
                        buttonDownWidth = 48;
                    }
                    if (j == group.items.Count - 1)
                    {
                        buttonUpWidth = 48;
                    }

                    //draw up & down buttons for re-ordering items in a group
                    //this will simply switch references in the list
                    if (j > 0 && GUILayout.Button("▲", GUILayout.Width(buttonUpWidth)))
                    {
                        group.items[j]                   = group.items[j - 1];
                        group.items[j - 1]               = obj;
                        EditorGUIUtility.hotControl      = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }
                    if (j < group.items.Count - 1 && GUILayout.Button("▼", GUILayout.Width(buttonDownWidth)))
                    {
                        group.items[j]                   = group.items[j + 1];
                        group.items[j + 1]               = obj;
                        EditorGUIUtility.hotControl      = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }

                    //button for removing an item of the group
                    GUI.backgroundColor = Color.gray;
                    if (GUILayout.Button("X"))
                    {
                        group.items.RemoveAt(j);
                        break;
                    }
                    GUI.backgroundColor = Color.white;
                    EditorGUILayout.EndHorizontal();

                    //draw platform override foldout
                    if (obj.platformFoldout)
                    {
                        EditorGUILayout.LabelField("Platform Overrides");
                        for (int k = 0; k < obj.localId.Count; k++)
                        {
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Space(40);
                            obj.localId[k].overridden = EditorGUILayout.BeginToggleGroup("", obj.localId[k].overridden);
                            EditorGUILayout.BeginHorizontal();
                            obj.localId[k].id = EditorGUILayout.TextField(obj.localId[k].id, GUILayout.Width(120));
                            EditorGUILayout.LabelField(((IAPPlatform)k).ToString());
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.EndToggleGroup();
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                GUILayout.Space(30);
            }

            //ends the scrollview defined above
            EditorGUILayout.EndScrollView();
        }
コード例 #5
0
        //draws the in game content editor
        void DrawIGC(List<IAPGroup> list)
        {
            EditorGUILayout.BeginHorizontal();
            GUI.backgroundColor = Color.yellow;

            //draw currencies up to a maximum of 7
            //(there is no limitation, but 7 currencies do fit in the window nicely,
            //and there really shouldnt be a reason to have 7+ different currencies)
            if (script.currency.Count < 7)
            {
                //button for adding a new currency
                if (GUILayout.Button("Add Currency"))
                {
                    //switch current currency selection to the first entry
                    currencyIndex = 0;
                    //create new currency, then loop over items
                    //and add a new currency slot for each of them
                    script.currency.Add(new IAPCurrency());
                    for (int i = 0; i < list.Count; i++)
                        for (int j = 0; j < list[i].items.Count; j++)
                            list[i].items[j].virtualPrice.Add(new IAPCurrency());
                    return;
                }
            }
            else
            {
                //for more than 7 currencies,
                //we show a transparent button with no functionality
                GUI.backgroundColor = new Color(1, 0.9f, 0, 0.4f);
                if (GUILayout.Button("Add Currency"))
                { }
            }

            //draw yellow button for adding a new IAP group
            if (GUILayout.Button("Add new Group"))
            {
                //create new group, give it a generic name based on
                //the current system time and add it to the list of groups
                IAPGroup newGroup = new IAPGroup();
                string timestamp = GenerateUnixTime();
                newGroup.name = "Grp " + timestamp;
                newGroup.id = timestamp;
                list.Add(newGroup);
                return;
            }

            GUI.backgroundColor = Color.white;
            EditorGUILayout.EndHorizontal();

            //begin a scrolling view inside tab, pass in current Vector2 scroll position
            scrollPosIGC = EditorGUILayout.BeginScrollView(scrollPosIGC, GUILayout.Height(350));
            GUILayout.Space(20);
            EditorGUILayout.BeginHorizontal();
            //only draw a box behind currencies if there are any
            if (script.currency.Count > 0)
                GUI.Box(new Rect(3, 15, 796, 95), "");

            //loop through currencies
            for (int i = 0; i < script.currency.Count; i++)
            {
                EditorGUILayout.BeginVertical();
                //draw currency properties,
                //such as name and amount
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Name", GUILayout.Width(44));
                script.currency[i].name = EditorGUILayout.TextField(script.currency[i].name, GUILayout.Width(54));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Default", GUILayout.Width(44));
                script.currency[i].amount = EditorGUILayout.IntField(script.currency[i].amount, GUILayout.Width(54));
                EditorGUILayout.EndHorizontal();

                //button for deleting a currency
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(52);
                GUI.backgroundColor = Color.gray;
                if (GUILayout.Button("X", GUILayout.Width(54)))
                {
                    //ask again before deleting the currency,
                    //as deleting it could cause angry customers!
                    //it's probably better not to remove currencies in production versions
                    if (EditorUtility.DisplayDialog("Delete Currency?",
                        "Existing users might lose their funds associated with this currency when updating.",
                        "Continue", "Abort"))
                    {
                        //loop over items and remove the
                        //associated currency slot for each of them
                        for (int j = 0; j < list.Count; j++)
                            for (int k = 0; k < list[j].items.Count; k++)
                                list[j].items[k].virtualPrice.RemoveAt(i);
                        //then remove the currency
                        script.currency.RemoveAt(i);
                        //reposition current currency index
                        if (script.currency.Count > 0)
                            currencyIndex = 0;
                        else
                            currencyIndex = -1;
                        break;
                    }
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            //draw currency selector, if there are any
            if (script.currency.Count > 0)
            {
                GUILayout.Space(10);
                EditorGUILayout.BeginHorizontal();
                //get all currency names,
                //then draw a popup list for selecting the desired index
                currencyNames = GetCurrencyNames();
                EditorGUILayout.LabelField("Selected Currency:", GUILayout.Width(120));
                currencyIndex = EditorGUILayout.Popup(currencyIndex, currencyNames, GUILayout.Width(140));
                EditorGUILayout.EndHorizontal();
                GUILayout.Space(20);
            }

            //loop over IAP groups
            for (int i = 0; i < list.Count; i++)
            {
                //cache group
                IAPGroup group = list[i];
                //version 1.2 backwards compatibility fix (empty IAPGroup ids)
                if (string.IsNullOrEmpty(group.id))
                    group.id = GenerateUnixTime();

                Container shopGroup = null;
                if (shop)
                {
                    shopGroup = shop.GetContainer(group.id);
                    if (shopGroup == null)
                    {
                        shopGroup = new Container();
                        shopGroup.id = group.id;
                        shop.containers.Add(shopGroup);
                    }
                }

                EditorGUILayout.BeginHorizontal();
                GUI.backgroundColor = Color.yellow;
                //button for adding a new IAPObject (product) to this group
                if (GUILayout.Button("New Product", GUILayout.Width(120)))
                {
                    IAPObject newObj = new IAPObject();
                    for (int j = 0; j < script.currency.Count; j++)
                        newObj.virtualPrice.Add(new IAPCurrency());
                    group.items.Add(newObj);
                    break;
                }
                GUI.backgroundColor = Color.white;

                //draw group properties
                EditorGUILayout.LabelField("Group:", GUILayout.Width(45));
                group.name = EditorGUILayout.TextField(group.name, GUILayout.Width(90));
                GUILayout.Space(10);
                EditorGUILayout.LabelField("Sort:", GUILayout.Width(35));
                orderType = (OrderType)EditorGUILayout.EnumPopup(orderType, GUILayout.Width(60));
                GUILayout.Space(10);

                if (!shop)
                    EditorGUILayout.LabelField("No ShopManager prefab found in this scene!", GUILayout.Width(300));
                else
                {
                    EditorGUILayout.LabelField("Prefab:", GUILayout.Width(45));
                    shopGroup.prefab = (GameObject)EditorGUILayout.ObjectField(shopGroup.prefab, typeof(GameObject), false, GUILayout.Width(100));
                    GUILayout.Space(10);
                    EditorGUILayout.LabelField("Parent:", GUILayout.Width(45));
                    shopGroup.parent = (Transform)EditorGUILayout.ObjectField(shopGroup.parent, typeof(Transform), true, GUILayout.Width(100));
                }

                GUILayout.FlexibleSpace();
                if (orderType != OrderType.none)
                {
                    group.items = orderProducts(group.items);
                    break;
                }

                //same as in DrawIAP(),
                //move group up & down buttons
                int groupUpWidth = 22;
                int groupDownWidth = 22;
                if (i == 0) groupDownWidth = 48;
                if (i == list.Count - 1) groupUpWidth = 48;

                if (i > 0 && GUILayout.Button("▲", GUILayout.Width(groupUpWidth)))
                {
                    list[i] = list[i - 1];
                    list[i - 1] = group;
                    EditorGUIUtility.hotControl = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }
                if (i < list.Count - 1 && GUILayout.Button("▼", GUILayout.Width(groupDownWidth)))
                {
                    list[i] = list[i + 1];
                    list[i + 1] = group;
                    EditorGUIUtility.hotControl = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }

                //button for removing a group including items
                GUI.backgroundColor = Color.gray;
                if (GUILayout.Button("X", GUILayout.Width(20)))
                {
                    if(shop) shop.containers.Remove(shopGroup);
                    list.RemoveAt(i);
                    break;
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));

                //draw header information for each item property
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("ID:", GUILayout.Width(110));
                GUILayout.Space(20);
                EditorGUILayout.LabelField("Icon:", GUILayout.Width(75));
                GUILayout.Space(20);
                EditorGUILayout.LabelField("Type:", GUILayout.Width(100));
                GUILayout.Space(20);
                int spaceTitleToDescription = 90;
                if (group.items.Count == 1) spaceTitleToDescription = 110;
                EditorGUILayout.LabelField("Title:", GUILayout.Width(spaceTitleToDescription));
                GUILayout.Space(20);
                int spaceDescriptionToPrice = 135;
                if (group.items.Count == 1) spaceDescriptionToPrice = 145;
                EditorGUILayout.LabelField("Description:", GUILayout.Width(spaceDescriptionToPrice));
                GUILayout.Space(20);
                EditorGUILayout.LabelField("Price:", GUILayout.Width(40));
                GUILayout.Space(80);
                EditorGUILayout.EndHorizontal();

                //loop over items in this group
                for (int j = 0; j < group.items.Count; j++)
                {
                    //cache item reference
                    IAPObject obj = group.items[j];
                    EditorGUILayout.BeginHorizontal();

                    //draw IAPObject (item/product) properties
                    obj.id = EditorGUILayout.TextField(obj.id, GUILayout.Width(120));
                    obj.icon = EditorGUILayout.ObjectField(obj.icon, typeof(Sprite), false, GUILayout.Width(65)) as Sprite;
                    obj.type = (IAPType)EditorGUILayout.EnumPopup(obj.type, GUILayout.Width(110));
                    //don't allow consumable/non consumable/subscription IAP types, they must be virtual
                    if (obj.type == IAPType.consumable) obj.type = IAPType.consumableVirtual;
                    else if (obj.type == IAPType.nonConsumable || obj.type == IAPType.subscription)
                        obj.type = IAPType.nonConsumableVirtual;
                    //other item properties
                    obj.title = EditorGUILayout.TextField(obj.title);
                    obj.description = EditorGUILayout.TextField(obj.description);

                    //if a currency has been selected previously,
                    //draw an input field for the selected currency
                    if (currencyIndex > -1)
                    {
                        //version 1.1 compability fix (virtual currency int -> IAPCurrency conversion)
                        if (obj.virtualPrice == null || currencyIndex > obj.virtualPrice.Count - 1)
                        {
                            GUI.backgroundColor = Color.gray;
                            if (GUILayout.Button("X"))
                            {
                                group.items.RemoveAt(j);
                                break;
                            }
                            GUI.backgroundColor = Color.white;
                            EditorGUILayout.EndHorizontal();
                            continue;
                        }

                        EditorGUILayout.BeginHorizontal();
                        IAPCurrency cur = obj.virtualPrice[currencyIndex];
                        cur.name = currencyNames[currencyIndex];
                        EditorGUILayout.LabelField(cur.name, GUILayout.Width(40));
                        cur.amount = EditorGUILayout.IntField(cur.amount, GUILayout.Width(60));
                        EditorGUILayout.EndHorizontal();
                    }
                    else
                        GUILayout.FlexibleSpace();

                    //same as in DrawIAP(), requirement button
                    if (!string.IsNullOrEmpty(obj.req.entry) || !string.IsNullOrEmpty(obj.req.nextId))
                        GUI.backgroundColor = Color.yellow;
                    if (GUILayout.Button("R", GUILayout.Width(20)))
                    {
                        reqEditor = (RequirementEditor)EditorWindow.GetWindowWithRect(typeof(RequirementEditor), new Rect(0, 0, 300, 170), false, "Requirement");
                        reqEditor.obj = obj;
                    }

                    GUI.backgroundColor = Color.white;
                    //same as in DrawIAP(),
                    //move item up & down buttons
                    int buttonUpWidth = 22;
                    int buttonDownWidth = 22;
                    if (j == 0) buttonDownWidth = 48;
                    if (j == group.items.Count - 1) buttonUpWidth = 48;

                    if (j > 0 && GUILayout.Button("▲", GUILayout.Width(buttonUpWidth)))
                    {
                        group.items[j] = group.items[j - 1];
                        group.items[j - 1] = obj;
                        EditorGUIUtility.hotControl = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }
                    if (j < group.items.Count - 1 && GUILayout.Button("▼", GUILayout.Width(buttonDownWidth)))
                    {
                        group.items[j] = group.items[j + 1];
                        group.items[j + 1] = obj;
                        EditorGUIUtility.hotControl = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }

                    //button for removing an item of the group
                    GUI.backgroundColor = Color.gray;
                    if (GUILayout.Button("X"))
                    {
                        group.items.RemoveAt(j);
                        break;
                    }
                    GUI.backgroundColor = Color.white;
                    EditorGUILayout.EndHorizontal();
                }
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                GUILayout.Space(30);
            }

            //ends the scrollview defined above
            EditorGUILayout.EndScrollView();
        }
コード例 #6
0
ファイル: IAPEditor.cs プロジェクト: mutatis/sprawl-brawl
        //draws the in app purchase editor
        //for a specific OS
        void DrawIAP(List<IAPGroup> list)
        {
            //begin a scrolling view inside this tab, pass in current Vector2 scroll position
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
            GUILayout.Space(10);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Virtual Currencies:", EditorStyles.boldLabel, GUILayout.Width(125), GUILayout.Height(20));

            //button for adding a new currency
            GUI.backgroundColor = Color.yellow;
            if (GUILayout.Button("Add Currency"))
            {
                //switch current currency selection to the first entry
                currencyIndex = 0;
                //create new currency, then loop over items
                //and add a new currency slot for each of them
                script.currency.Add(new IAPCurrency());
                for (int i = 0; i < list.Count; i++)
                    for (int j = 0; j < list[i].items.Count; j++)
                        list[i].items[j].virtualPrice.Add(new IAPCurrency());
                return;
            }
            GUI.backgroundColor = Color.white;
            EditorGUILayout.EndHorizontal();

            //begin a scrolling view inside this tab, pass in current Vector2 scroll position
            scrollPosCurrency = EditorGUILayout.BeginScrollView(scrollPosCurrency, GUILayout.Height(105));

            EditorGUILayout.BeginHorizontal();
            //only draw a box behind currencies if there are any
            if (script.currency.Count > 0)
                GUI.Box(new Rect(0, 0, iapEditor.maxSize.x, 90), "");

            //loop through currencies
            for (int i = 0; i < script.currency.Count; i++)
            {
                EditorGUILayout.BeginVertical();
                //draw currency properties,
                //such as name and amount
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Name", GUILayout.Width(44));
                script.currency[i].name = EditorGUILayout.TextField(script.currency[i].name, GUILayout.Width(54));
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Default", GUILayout.Width(44));
                script.currency[i].amount = EditorGUILayout.IntField(script.currency[i].amount, GUILayout.Width(54));
                EditorGUILayout.EndHorizontal();

                //button for deleting a currency
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(52);
                GUI.backgroundColor = Color.gray;
                if (GUILayout.Button("X", GUILayout.Width(54)))
                {
                    //ask again before deleting the currency,
                    //as deleting it could cause angry customers!
                    //it's probably better not to remove currencies in production versions
                    if (EditorUtility.DisplayDialog("Delete Currency?",
                        "Existing users might lose their funds associated with this currency when updating.",
                        "Continue", "Abort"))
                    {
                        //loop over items and remove the
                        //associated currency slot for each of them
                        for (int j = 0; j < list.Count; j++)
                            for (int k = 0; k < list[j].items.Count; k++)
                            {
                                if(list[j].items[k].virtualPrice != null
                                   && list[j].items[k].virtualPrice.Count > i)
                                    list[j].items[k].virtualPrice.RemoveAt (i);
                            }
                        //then remove the currency
                        script.currency.RemoveAt(i);
                        //reposition current currency index
                        if (script.currency.Count > 0)
                            currencyIndex = 0;
                        else
                            currencyIndex = -1;
                        break;
                    }
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            //draw currency selector, if there are any
            if (script.currency.Count > 0)
            {
                GUILayout.Space(10);
                EditorGUILayout.BeginHorizontal();
                //get all currency names,
                //then draw a popup list for selecting the desired index
                currencyNames = GetCurrencyNames();
                EditorGUILayout.LabelField("Selected Currency:", GUILayout.Width(120));
                currencyIndex = EditorGUILayout.Popup(currencyIndex, currencyNames, GUILayout.Width(140));
                EditorGUILayout.EndHorizontal();
            }

            //ends the scrollview defined above
            EditorGUILayout.EndScrollView();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("In App Purchases:", EditorStyles.boldLabel, GUILayout.Width(125), GUILayout.Height(20));

            //draw yellow button for adding a new IAP group
            GUI.backgroundColor = Color.yellow;
            if (GUILayout.Button("Add new Category"))
            {
                //create new group, give it a generic name based on
                //the current unix time and add it to the list of groups
                IAPGroup newGroup = new IAPGroup();
                string timestamp = GenerateUnixTime();
                newGroup.name = "Grp " + timestamp;
                newGroup.id = timestamp;
                list.Add(newGroup);
                return;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            //loop over IAP groups for this OS
            for (int i = 0; i < list.Count; i++)
            {
                //cache group
                IAPGroup group = list[i];
                //populate shop container variables if ShopManager is present
                ShopContainer shopContainer = null;
                if (shop)
                {
                    shopContainer = shop.GetContainer(group.id);
                    if (shopContainer == null)
                    {
                        shopContainer = new ShopContainer();
                        shopContainer.id = group.id;
                        shop.containers.Add(shopContainer);
                    }
                }

                GUI.backgroundColor = Color.yellow;
                EditorGUILayout.BeginHorizontal();
                int productSelection = 0;
                productSelection = EditorGUILayout.Popup(productSelection, productTypes);

                //button for adding a new IAPObject (product) to this group
                if (productSelection > 0)
                {
                    IAPObject newObj = new IAPObject();

                    switch (productSelection)
                    {
                        case 1:
                            Debug.LogError("Can't create products for real money. You need to import a billing plugin first!" +
                                           " Open 'Window > Simple IAP System > Plugin Setup' if you want to use one.");
                            return;
                        case 2:
                            newObj.isVirtual = true;
                            for(int j = 0; j < script.currency.Count; j++)
                                newObj.virtualPrice.Add(new IAPCurrency());
                            break;
                    }

                    group.items.Add(newObj);
                    break;
                }

                //draw group properties
                GUI.backgroundColor = Color.white;
                EditorGUILayout.LabelField("Group:", GUILayout.Width(45));
                group.name = EditorGUILayout.TextField(group.name, GUILayout.Width(90));
                GUILayout.Space(10);
                EditorGUILayout.LabelField("Sort:", GUILayout.Width(35));
                orderType = (OrderType)EditorGUILayout.EnumPopup(orderType, GUILayout.Width(60));
                GUILayout.Space(10);

                if (!shop)
                {
                    GUI.contentColor = Color.yellow;
                    EditorGUILayout.LabelField("No ShopManager prefab found in this scene!", GUILayout.Width(300));
                    GUI.contentColor = Color.white;
                }
                else
                {
                    EditorGUILayout.LabelField("Prefab:", GUILayout.Width(45));
                    shopContainer.prefab = (GameObject)EditorGUILayout.ObjectField(shopContainer.prefab, typeof(GameObject), false, GUILayout.Width(100));
                    GUILayout.Space(10);
                    EditorGUILayout.LabelField("Container:", GUILayout.Width(65));
                    shopContainer.parent = (IAPContainer)EditorGUILayout.ObjectField(shopContainer.parent, typeof(IAPContainer), true, GUILayout.Width(100));
                }

                GUILayout.FlexibleSpace();
                //check for order type and, if it
                //isn't equal to 'none', start ordering
                if (orderType != OrderType.none)
                {
                    group.items = orderProducts(group.items);
                    break;
                }

                //button width for up & down buttons
                //these should always be at the same width, so if there's
                //only one button (e.g. if there's only one group),
                //the width must be extended
                int groupUpWidth = 22;
                int groupDownWidth = 22;
                if (i == 0) groupDownWidth = 48;
                if (i == list.Count - 1) groupUpWidth = 48;

                //draw up & down buttons for re-ordering groups
                //this will simply switch references in the list
                //hotControl and keyboardControl unsets current mouse focus
                if (i > 0 && GUILayout.Button("▲", GUILayout.Width(groupUpWidth)))
                {
                    list[i] = list[i - 1];
                    list[i - 1] = group;
                    EditorGUIUtility.hotControl = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }
                if (i < list.Count - 1 && GUILayout.Button("▼", GUILayout.Width(groupDownWidth)))
                {
                    list[i] = list[i + 1];
                    list[i + 1] = group;
                    EditorGUIUtility.hotControl = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }

                //button for removing a group including items
                GUI.backgroundColor = Color.gray;
                if (GUILayout.Button("X", GUILayout.Width(20)))
                {
                    if(shop) shop.containers.Remove(shopContainer);
                    list.RemoveAt(i);
                    break;
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                GUILayout.Space(20);

                List<Rect> headerRect = GetHeaders();

                //loop over items in this group
                for (int j = 0; j < group.items.Count; j++)
                {
                    //cache item reference
                    IAPObject obj = group.items[j];
                    EditorGUILayout.BeginHorizontal();

                    //new platforms future compatibility
                    int platforms = System.Enum.GetValues(typeof(IAPPlatform)).Length;
                    for (int k = obj.localIDs.Count; k < platforms; k++)
                        obj.localIDs.Add(new IAPIdentifier());

                    GUILayout.Box("", GUILayout.Height(15), GUILayout.Width(15));
                    Rect foldoutRect = GUILayoutUtility.GetLastRect();
                    if(!obj.isVirtual)
                        obj.platformFoldout = EditorGUI.Foldout(foldoutRect, obj.platformFoldout, "");

                    //draw IAPObject (item/product) properties
                    obj.id = EditorGUILayout.TextField(obj.id, GUILayout.MaxWidth(150));
                    obj.icon = EditorGUILayout.ObjectField(obj.icon, typeof(Sprite), false, GUILayout.MaxWidth(65)) as Sprite;

                    IAPType oldType = obj.type;
                    obj.type = (IAPType)EditorGUILayout.EnumPopup(obj.type, GUILayout.MaxWidth(110));
                    if (obj.type != oldType && !obj.type.ToString().Contains("Virtual"))
                    {
                        Debug.LogError("Can't create products for real money. You need to import a billing plugin first!" +
                                        "Open 'Window > Simple IAP System > Plugin Setup' if you want to use one.");
                        obj.type = IAPType.consumableVirtual;
                    }

                    obj.title = EditorGUILayout.TextField(obj.title, GUILayout.MaxWidth(180));
                    obj.description = EditorGUILayout.TextField(obj.description);

                    if (obj.isVirtual)
                    {
                        IAPCurrency cur = null;
                        if(currencyIndex >= 0 && obj.virtualPrice.Count > currencyIndex)
                            cur = obj.virtualPrice[currencyIndex];

                        if (cur == null)
                        {
                            EditorGUILayout.LabelField("No currency!", GUILayout.MinWidth(70), GUILayout.MaxWidth(100));
                        }
                        else
                        {
                            cur.name = currencyNames[currencyIndex];
                            EditorGUILayout.LabelField(cur.name, GUILayout.MinWidth(30), GUILayout.MaxWidth(40));
                            cur.amount = EditorGUILayout.IntField (cur.amount, GUILayout.MinWidth(35), GUILayout.Width(50));
                        }
                    }
                    else
                    {
                        obj.realPrice = EditorGUILayout.TextField (obj.realPrice, GUILayout.MaxWidth(80));
                        obj.fetch = EditorGUILayout.Toggle (obj.fetch, GUILayout.MaxWidth(20));
                    }

                    //button for adding a requirement to this item
                    if (!string.IsNullOrEmpty(obj.req.entry) || !string.IsNullOrEmpty(obj.req.nextId))
                        GUI.backgroundColor = Color.yellow;
                    if (GUILayout.Button("R", GUILayout.Width(20)))
                    {
                        reqEditor = (RequirementEditor)EditorWindow.GetWindowWithRect(typeof(RequirementEditor), new Rect(0, 0, 300, 170), false, "Requirement");
                        reqEditor.obj = obj;
                    }

                    GUI.backgroundColor = Color.white;
                    //do the same here as with the group up & down buttons
                    //(see above)
                    int buttonUpWidth = 22;
                    int buttonDownWidth = 22;
                    if (j == 0) buttonDownWidth = 48;
                    if (j == group.items.Count - 1) buttonUpWidth = 48;

                    //draw up & down buttons for re-ordering items in a group
                    //this will simply switch references in the list
                    if (j > 0 && GUILayout.Button("▲", GUILayout.Width(buttonUpWidth)))
                    {
                        group.items[j] = group.items[j - 1];
                        group.items[j - 1] = obj;
                        EditorGUIUtility.hotControl = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }
                    if (j < group.items.Count - 1 && GUILayout.Button("▼", GUILayout.Width(buttonDownWidth)))
                    {
                        group.items[j] = group.items[j + 1];
                        group.items[j + 1] = obj;
                        EditorGUIUtility.hotControl = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }

                    if(group.items.Count == 1)
                        GUILayout.Space(52);

                    //button for removing an item of the group
                    GUI.backgroundColor = Color.gray;
                    if (GUILayout.Button("X", GUILayout.Width(20)))
                    {
                        group.items.RemoveAt(j);
                        break;
                    }
                    GUI.backgroundColor = Color.white;
                    EditorGUILayout.EndHorizontal();

                    //draw platform override foldout
                    if (obj.platformFoldout)
                    {
                        EditorGUILayout.LabelField("Platform Overrides");
                        for (int k = 0; k < obj.localIDs.Count; k++)
                        {
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Space(40);
                            obj.localIDs[k].overridden = EditorGUILayout.BeginToggleGroup("", obj.localIDs[k].overridden);
                            EditorGUILayout.BeginHorizontal();
                            obj.localIDs[k].id = EditorGUILayout.TextField(obj.localIDs[k].id, GUILayout.Width(120));
                            EditorGUILayout.LabelField(((IAPPlatform)k).ToString());
                            EditorGUILayout.EndHorizontal();
                            EditorGUILayout.EndToggleGroup();
                            EditorGUILayout.EndHorizontal();
                        }
                    }
                }

                for (int j = 0; j < headerRect.Count; j++)
                    EditorGUI.LabelField(new Rect(headerRect[j].x, headerRect[j].y - 20, 100, 20), headerNames[j]);

                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                GUILayout.Space(30);
            }

            //ends the scrollview defined above
            EditorGUILayout.EndScrollView();
        }
コード例 #7
0
        //draws the in app purchase editor
        //for a specific OS
        void DrawIAP(List <IAPGroup> list)
        {
            //begin a scrolling view inside this tab, pass in current Vector2 scroll position
            scrollPos = EditorGUILayout.BeginScrollView(scrollPos);

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Import from JSON"))
            {
                string path = EditorUtility.OpenFolderPanel("Import IAP Settings from JSON", "", "");

                if (path.Length != 0)
                {
                    script.currencies = IAPEditorExporter.FromJSON(System.IO.File.ReadAllText(path + "/SimpleIAPSystem_Currencies.json"));
                    currencyIndex     = script.currencies.Count > 0 ? 0 : -1;
                    script.IAPs       = IAPEditorExporter.FromJSON(System.IO.File.ReadAllText(path + "/SimpleIAPSystem_IAPSettings.json"), script.currencies);
                    return;
                }
            }

            if (GUILayout.Button("Export to JSON"))
            {
                string path = EditorUtility.SaveFolderPanel("Save IAP Settings as JSON", "", "");

                if (path.Length != 0)
                {
                    System.IO.File.WriteAllBytes(path + "/SimpleIAPSystem_IAPSettings.json", System.Text.Encoding.UTF8.GetBytes(IAPEditorExporter.ToJSON(script.IAPs)));
                    System.IO.File.WriteAllBytes(path + "/SimpleIAPSystem_IAPSettings_PlayFab.json", System.Text.Encoding.UTF8.GetBytes(IAPEditorExporter.ToJSON(script.IAPs, true)));
                    System.IO.File.WriteAllBytes(path + "/SimpleIAPSystem_Currencies.json", System.Text.Encoding.UTF8.GetBytes(IAPEditorExporter.ToJSON(script.currencies)));
                }
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(10);
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Virtual Currencies:", EditorStyles.boldLabel, GUILayout.Width(125), GUILayout.Height(20));

            //button for adding a new currency
            GUI.backgroundColor = Color.yellow;
            if (GUILayout.Button("Add Currency"))
            {
                //switch current currency selection to the first entry
                currencyIndex = 0;
                //create new currency, then loop over items
                //and add a new currency slot for each of them
                script.currencies.Add(new IAPCurrency());
                for (int i = 0; i < list.Count; i++)
                {
                    for (int j = 0; j < list[i].items.Count; j++)
                    {
                        list[i].items[j].virtualPrice.Add(new IAPCurrency());
                    }
                }
                return;
            }
            GUI.backgroundColor = Color.white;
            EditorGUILayout.EndHorizontal();

            //begin a scrolling view inside this tab, pass in current Vector2 scroll position
            scrollPosCurrency = EditorGUILayout.BeginScrollView(scrollPosCurrency, GUILayout.Height(105));

            EditorGUILayout.BeginHorizontal();
            //only draw a box behind currencies if there are any
            if (script.currencies.Count > 0)
            {
                GUI.Box(new Rect(0, 0, iapEditor.maxSize.x, 90), "");
            }

            //loop through currencies
            for (int i = 0; i < script.currencies.Count; i++)
            {
                EditorGUILayout.BeginVertical();
                //draw currency properties,
                //such as name and amount
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Name", GUILayout.Width(44));
                script.currencies[i].name = EditorGUILayout.TextField(script.currencies[i].name, GUILayout.Width(54)).ToLower();
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.LabelField("Default", GUILayout.Width(44));
                script.currencies[i].amount = EditorGUILayout.IntField(script.currencies[i].amount, GUILayout.Width(54));
                EditorGUILayout.EndHorizontal();

                //button for deleting a currency
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(52);
                GUI.backgroundColor = Color.gray;
                if (GUILayout.Button("X", GUILayout.Width(54)))
                {
                    //ask again before deleting the currency,
                    //as deleting it could cause angry customers!
                    //it's probably better not to remove currencies in production versions
                    if (EditorUtility.DisplayDialog("Delete Currency?",
                                                    "Existing users might lose their funds associated with this currency when updating.",
                                                    "Continue", "Abort"))
                    {
                        //loop over items and remove the
                        //associated currency slot for each of them
                        for (int j = 0; j < list.Count; j++)
                        {
                            for (int k = 0; k < list[j].items.Count; k++)
                            {
                                if (list[j].items[k].virtualPrice != null &&
                                    list[j].items[k].virtualPrice.Count > i)
                                {
                                    list[j].items[k].virtualPrice.RemoveAt(i);
                                }
                            }
                        }
                        //then remove the currency
                        script.currencies.RemoveAt(i);
                        //reposition current currency index
                        if (script.currencies.Count > 0)
                        {
                            currencyIndex = 0;
                        }
                        else
                        {
                            currencyIndex = -1;
                        }
                        break;
                    }
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.EndVertical();
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            //draw currency selector, if there are any
            if (script.currencies.Count > 0)
            {
                GUILayout.Space(10);
                EditorGUILayout.BeginHorizontal();
                //get all currency names,
                //then draw a popup list for selecting the desired index
                currencyNames = GetCurrencyNames();
                EditorGUILayout.LabelField("Selected Currency:", GUILayout.Width(120));
                currencyIndex = EditorGUILayout.Popup(currencyIndex, currencyNames, GUILayout.Width(140));
                EditorGUILayout.EndHorizontal();
            }

            //ends the scrollview defined above
            EditorGUILayout.EndScrollView();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("In App Purchases:", EditorStyles.boldLabel, GUILayout.Width(125), GUILayout.Height(20));

            //draw yellow button for adding a new IAP group
            GUI.backgroundColor = Color.yellow;
            if (GUILayout.Button("Add new Category"))
            {
                //create new group, give it a generic name based on
                //the current unix time and add it to the list of groups
                IAPGroup newGroup  = new IAPGroup();
                string   timestamp = GenerateUnixTime();
                newGroup.name = "Grp " + timestamp;
                newGroup.id   = timestamp;
                list.Add(newGroup);
                return;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            //loop over IAP groups for this OS
            for (int i = 0; i < list.Count; i++)
            {
                //cache group
                IAPGroup group = list[i];
                //populate shop container variables if ShopManager is present
                ShopContainer shopContainer = null;
                if (shop)
                {
                    shopContainer = shop.GetContainer(group.id);
                    if (shopContainer == null)
                    {
                        shopContainer    = new ShopContainer();
                        shopContainer.id = group.id;
                        shop.containers.Add(shopContainer);
                    }
                }

                GUI.backgroundColor = Color.yellow;
                EditorGUILayout.BeginHorizontal();
                int productSelection = 0;
                productSelection = EditorGUILayout.Popup(productSelection, productTypes);

                //button for adding a new IAPObject (product) to this group
                if (productSelection > 0)
                {
                    IAPObject newObj = new IAPObject();

                    switch (productSelection)
                    {
                    case 2:
                        newObj.editorType = IAPType.Currency;
                        for (int j = 0; j < script.currencies.Count; j++)
                        {
                            newObj.virtualPrice.Add(new IAPCurrency());
                        }
                        break;

                    case 3:
                        newObj.editorType = IAPType.Virtual;
                        for (int j = 0; j < script.currencies.Count; j++)
                        {
                            newObj.virtualPrice.Add(new IAPCurrency());
                        }
                        break;
                    }

                    group.items.Add(newObj);
                    break;
                }

                //draw group properties
                GUI.backgroundColor = Color.white;
                EditorGUILayout.LabelField("Group:", GUILayout.Width(45));
                group.name = EditorGUILayout.TextField(group.name, GUILayout.Width(90));
                GUILayout.Space(10);
                EditorGUILayout.LabelField("Sort:", GUILayout.Width(35));
                orderType = (OrderType)EditorGUILayout.EnumPopup(orderType, GUILayout.Width(60));
                GUILayout.Space(10);

                if (!shop)
                {
                    GUI.contentColor = Color.yellow;
                    EditorGUILayout.LabelField("No ShopManager prefab found in this scene!", GUILayout.Width(300));
                    GUI.contentColor = Color.white;
                }
                else
                {
                    EditorGUILayout.LabelField("Prefab:", GUILayout.Width(45));
                    shopContainer.prefab = (GameObject)EditorGUILayout.ObjectField(shopContainer.prefab, typeof(GameObject), false, GUILayout.Width(100));
                    GUILayout.Space(10);
                    EditorGUILayout.LabelField("Container:", GUILayout.Width(65));
                    shopContainer.parent = (IAPContainer)EditorGUILayout.ObjectField(shopContainer.parent, typeof(IAPContainer), true, GUILayout.Width(100));
                }

                GUILayout.FlexibleSpace();
                //check for order type and, if it
                //isn't equal to 'none', start ordering
                if (orderType != OrderType.none)
                {
                    group.items = orderProducts(group.items);
                    break;
                }

                //button width for up & down buttons
                //these should always be at the same width, so if there's
                //only one button (e.g. if there's only one group),
                //the width must be extended
                int groupUpWidth   = 22;
                int groupDownWidth = 22;
                if (i == 0)
                {
                    groupDownWidth = 48;
                }
                if (i == list.Count - 1)
                {
                    groupUpWidth = 48;
                }

                //draw up & down buttons for re-ordering groups
                //this will simply switch references in the list
                //hotControl and keyboardControl unsets current mouse focus
                if (i > 0 && GUILayout.Button("▲", GUILayout.Width(groupUpWidth)))
                {
                    list[i]     = list[i - 1];
                    list[i - 1] = group;
                    EditorGUIUtility.hotControl      = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }
                if (i < list.Count - 1 && GUILayout.Button("▼", GUILayout.Width(groupDownWidth)))
                {
                    list[i]     = list[i + 1];
                    list[i + 1] = group;
                    EditorGUIUtility.hotControl      = 0;
                    EditorGUIUtility.keyboardControl = 0;
                }

                //button for removing a group including items
                GUI.backgroundColor = Color.gray;
                if (GUILayout.Button("X", GUILayout.Width(20)))
                {
                    if (shop)
                    {
                        shop.containers.Remove(shopContainer);
                    }
                    list.RemoveAt(i);
                    break;
                }
                GUI.backgroundColor = Color.white;
                EditorGUILayout.EndHorizontal();
                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                GUILayout.Space(20);

                List <Rect> headerRect = GetHeaders();

                //loop over items in this group
                for (int j = 0; j < group.items.Count; j++)
                {
                    //cache item reference
                    IAPObject obj = group.items[j];
                    EditorGUILayout.BeginHorizontal();

                    GUILayout.Box("", GUILayout.Height(15), GUILayout.Width(15));
                    Rect foldoutRect = GUILayoutUtility.GetLastRect();
                    if (obj.editorType != IAPType.Virtual)
                    {
                        obj.platformFoldout = EditorGUI.Foldout(foldoutRect, obj.platformFoldout, "");
                    }

                    //draw IAPObject (item/product) properties
                    obj.id = EditorGUILayout.TextField(obj.id, GUILayout.MaxWidth(150));
                    if (!string.IsNullOrEmpty(obj.id))
                    {
                        obj.id = obj.id.Replace(" ", "");
                    }
                    obj.icon       = EditorGUILayout.ObjectField(obj.icon, typeof(Sprite), false, GUILayout.MaxWidth(65)) as Sprite;
                    obj.editorType = (IAPType)EditorGUILayout.EnumPopup(obj.editorType, GUILayout.MaxWidth(70));

                    EditorGUI.BeginDisabledGroup(obj.editorType == IAPType.Currency);
                    if (obj.editorType == IAPType.Currency)
                    {
                        obj.type = ProductType.Consumable;
                    }
                    obj.type = (ProductType)EditorGUILayout.EnumPopup(obj.type, GUILayout.MaxWidth(110));
                    EditorGUI.EndDisabledGroup();

                    obj.title       = EditorGUILayout.TextField(obj.title, GUILayout.MaxWidth(180));
                    obj.description = EditorGUILayout.TextField(obj.description);

                    EditorGUI.BeginDisabledGroup(obj.editorType == IAPType.Virtual);
                    obj.realPrice = EditorGUILayout.TextField(obj.realPrice, GUILayout.MaxWidth(55));
                    EditorGUI.EndDisabledGroup();

                    if (obj.editorType == IAPType.Virtual && (int)obj.type > 1)
                    {
                        Debug.LogWarning("Subscriptions are not available for virtual products. Resetting to Consumable.");
                        obj.type = ProductType.Consumable;
                    }

                    EditorGUI.BeginDisabledGroup(obj.editorType == IAPType.Default);
                    IAPCurrency cur = null;
                    if (obj.editorType != IAPType.Default && currencyIndex >= 0 && obj.virtualPrice.Count > currencyIndex)
                    {
                        cur = obj.virtualPrice[currencyIndex];
                    }

                    if (cur == null)
                    {
                        EditorGUILayout.LabelField("", GUILayout.MinWidth(75), GUILayout.MaxWidth(104));
                    }
                    else
                    {
                        cur.name = currencyNames[currencyIndex];
                        EditorGUILayout.LabelField(cur.name, GUILayout.MinWidth(35), GUILayout.MaxWidth(50));
                        cur.amount = EditorGUILayout.IntField(cur.amount, GUILayout.MinWidth(35), GUILayout.MaxWidth(50));
                    }
                    EditorGUI.EndDisabledGroup();

                    EditorGUI.BeginDisabledGroup(obj.type != ProductType.Consumable || obj.editorType == IAPType.Currency || obj.id == "restore");
                    obj.usageCount = Mathf.Clamp(EditorGUILayout.IntField(obj.usageCount, GUILayout.MaxWidth(35)), 0, int.MaxValue);
                    EditorGUI.EndDisabledGroup();

                    if (obj.type != ProductType.Consumable)
                    {
                        obj.usageCount = 1;
                    }
                    obj.fetch = EditorGUILayout.Toggle(obj.fetch, GUILayout.MaxWidth(20));

                    //button for adding a requirement to this item
                    if (!string.IsNullOrEmpty(obj.req.entry) || !string.IsNullOrEmpty(obj.req.nextId))
                    {
                        GUI.backgroundColor = Color.yellow;
                    }
                    if (GUILayout.Button("R", GUILayout.Width(20)))
                    {
                        reqEditor     = (RequirementEditor)GetWindowWithRect(typeof(RequirementEditor), new Rect(0, 0, 300, 170), false, "Requirement");
                        reqEditor.obj = obj;
                    }

                    GUI.backgroundColor = Color.white;
                    //do the same here as with the group up & down buttons
                    //(see above)
                    int buttonUpWidth   = 22;
                    int buttonDownWidth = 22;
                    if (j == 0)
                    {
                        buttonDownWidth = 48;
                    }
                    if (j == group.items.Count - 1)
                    {
                        buttonUpWidth = 48;
                    }

                    //draw up & down buttons for re-ordering items in a group
                    //this will simply switch references in the list
                    if (j > 0 && GUILayout.Button("▲", GUILayout.Width(buttonUpWidth)))
                    {
                        group.items[j]                   = group.items[j - 1];
                        group.items[j - 1]               = obj;
                        EditorGUIUtility.hotControl      = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }
                    if (j < group.items.Count - 1 && GUILayout.Button("▼", GUILayout.Width(buttonDownWidth)))
                    {
                        group.items[j]                   = group.items[j + 1];
                        group.items[j + 1]               = obj;
                        EditorGUIUtility.hotControl      = 0;
                        EditorGUIUtility.keyboardControl = 0;
                    }

                    if (group.items.Count == 1)
                    {
                        GUILayout.Space(52);
                    }

                    //button for removing an item of the group
                    GUI.backgroundColor = Color.gray;
                    if (GUILayout.Button("X", GUILayout.Width(20)))
                    {
                        group.items.RemoveAt(j);
                        break;
                    }
                    GUI.backgroundColor = Color.white;
                    EditorGUILayout.EndHorizontal();

                    //draw platform override foldout
                    if (obj.platformFoldout)
                    {
                        EditorGUILayout.LabelField("Platform Overrides");
                        if (GUILayout.Button("+", GUILayout.MaxWidth(35)))
                        {
                            obj.storeIDs.Add(new StoreID("None", ""));
                        }

                        for (int k = 0; k < obj.storeIDs.Count; k++)
                        {
                            EditorGUILayout.BeginHorizontal();
                            GUILayout.Space(40);
                            obj.storeIDs[k].store = EditorGUILayout.EnumPopup((IAPPlatform)System.Enum.Parse(typeof(IAPPlatform), obj.storeIDs[k].store), GUILayout.MaxWidth(150)).ToString();
                            obj.storeIDs[k].id    = EditorGUILayout.TextField(obj.storeIDs[k].id, GUILayout.Width(150));
                            if (!string.IsNullOrEmpty(obj.storeIDs[k].id))
                            {
                                obj.storeIDs[k].id = obj.storeIDs[k].id.Replace(" ", "");
                            }

                            GUI.backgroundColor = Color.gray;
                            if (GUILayout.Button("X", GUILayout.MaxWidth(20)))
                            {
                                obj.storeIDs.RemoveAt(k);
                                if (obj.storeIDs.Count == 0)
                                {
                                    obj.platformFoldout = false;
                                }
                                break;
                            }
                            GUI.backgroundColor = Color.white;
                            EditorGUILayout.EndHorizontal();
                        }

                        GUILayout.Space(10);
                    }
                }

                for (int j = 0; j < headerRect.Count; j++)
                {
                    EditorGUI.LabelField(new Rect(headerRect[j].x, headerRect[j].y - 20, 100, 20), headerNames[j]);
                }

                GUILayout.Box("", GUILayout.ExpandWidth(true), GUILayout.Height(1));
                GUILayout.Space(30);
            }

            //ends the scrollview defined above
            EditorGUILayout.EndScrollView();
        }