Esempio n. 1
0
        //remove empty IAPGroup references in the scene
        void RemoveContainerConnections()
        {
            //get all container objects from the Shop Manager,
            //then populate a list with all IAPGroups
            List <Container> containers = new List <Container>();

            containers.AddRange(shop.containers);
            List <IAPGroup> allGroups = new List <IAPGroup>();

            allGroups.AddRange(script.IAPs);
            allGroups.AddRange(script.IGCs);

            //loop over lists and compare them
            for (int i = 0; i < containers.Count; i++)
            {
                //if we found an IAPGroup in the Shop Manager component
                //that does not exist anymore, remove it from the scene containers
                IAPGroup g = allGroups.Find(x => x.id == containers[i].id);
                if (g == null)
                {
                    shop.containers.Remove(shop.containers.Find(x => x.id == containers[i].id));
                }
            }
            containers.Clear();
        }
        /// <summary>
        /// Unlocks items if the requirement for them has been met. You can
        /// call this method at runtime whenever the player made some
        /// progress, to ensure your shop items reflect the current state.
        /// </summary>
        public static void UnlockItems()
        {
            //this method is based on data from the database,
            //so if we don't have a DBManager instance don't continue
            if (!DBManager.GetInstance())
            {
                return;
            }

            //get list of all shop groups from IAPManager
            List <IAPGroup> list = IAPManager.GetInstance().IAPs;

            //loop over groups
            for (int i = 0; i < list.Count; i++)
            {
                //cache current group
                IAPGroup group = list[i];

                //loop over items
                for (int j = 0; j < group.items.Count; j++)
                {
                    //cache IAP object
                    IAPObject obj = group.items[j];
                    if (obj.req == null)
                    {
                        continue;
                    }

                    //cache reference to IAP item instance
                    IAPItem item = GetIAPItem(obj.id);

                    //check if the item reference is empty or set to purchased already
                    if (item == null || DBManager.isPurchased(obj.id))
                    {
                        continue;
                    }

                    //check if a requirement is set up for this item,
                    //then unlock if the requirement has been met
                    if (!string.IsNullOrEmpty(obj.req.entry) &&
                        DBManager.isRequirementMet(obj.req))
                    {
                        if (IAPManager.isDebug)
                        {
                            Debug.Log("requirement met for: " + obj.id);
                        }
                        item.Unlock();
                    }
                }
            }
        }
Esempio n. 3
0
        // initialize IAP ids:
        // populate IAP dictionary and arrays with product ids
        private void InitIds()
        {
            //create temporary list for all IAPGroups,
            //as well as a list only for real money purchases
            List <IAPGroup> idsList = GetIAPs();
            List <string>   ids     = new List <string>();

            if (idsList.Count == 0)
            {
                Debug.LogError("Initializing IAPManager, but IAP List is empty."
                               + " Did you set up IAPs in the IAP Settings?");
            }

            //loop over all groups
            for (int i = 0; i < idsList.Count; i++)
            {
                //cache current group
                IAPGroup group = idsList[i];
                //loop over items in this group
                for (int j = 0; j < group.items.Count; j++)
                {
                    //cache item
                    IAPObject obj = group.items[j];
                    if (String.IsNullOrEmpty(obj.id))
                    {
                        Debug.LogError("Found IAP Object in IAP Settings without an ID."
                                       + " This will cause errors during runtime.");
                    }

                    //add this IAPObject to the dictionary of id <> IAPObject
                    IAPObjects.Add(obj.id, obj);
                    //if it's an IAP for real money, also add it to the id list
                    if (obj.type == IAPType.consumable || obj.type == IAPType.nonConsumable ||
                        obj.type == IAPType.subscription)
                    {
                        ids.Add(obj.GetIdentifier());
                    }
                }
            }

            //don't add the restore button to the list of online purchases
            if (ids.Contains("restore"))
            {
                ids.Remove("restore");
            }
            //convert and store list of real money IAP ids as string array,
            //this array is being used for initializing Google/Apple's billing system
            this.ids = ids.ToArray();
        }
Esempio n. 4
0
        // initialize IAP ids:
        // populate IAP dictionary and arrays with product ids
        private void InitIds()
        {
            //create a list only for real money purchases
            List <string> ids = new List <string>();

            if (IAPs.Count == 0)
            {
                Debug.LogError("Initializing IAPManager, but IAP List is empty."
                               + " Did you set up IAPs in the IAP Settings?");
            }

            //loop over all groups
            for (int i = 0; i < IAPs.Count; i++)
            {
                //cache current group
                IAPGroup group = IAPs[i];
                //loop over items in this group
                for (int j = 0; j < group.items.Count; j++)
                {
                    //cache item
                    IAPObject obj = group.items[j];

                    if (String.IsNullOrEmpty(obj.id) || IAPObjects.ContainsKey(obj.id))
                    {
                        Debug.LogError("Found IAP Object in IAP Settings without an identifier "
                                       + " or " + obj.id + " does exist already. Skipping product.");
                        continue;
                    }

                    //add this IAPObject to the dictionary of id <> IAPObject
                    IAPObjects.Add(obj.id, obj);
                    //if it's an IAP for real money, add it to the id list
                    if (!obj.isVirtual)
                    {
                        ids.Add(obj.id);
                    }
                }
            }

            //don't add the restore button to the list of online purchases
            if (ids.Contains("restore"))
            {
                ids.Remove("restore");
            }
            //convert and store list of real money IAP ids as string array
            realIDs = ids.ToArray();
        }
Esempio n. 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 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();
        }
Esempio n. 6
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();
        }
Esempio n. 7
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();
        }
Esempio n. 8
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();
        }
Esempio n. 9
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();
        }
Esempio n. 10
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);
            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();
        }
Esempio n. 11
0
        public static List <IAPGroup> FromJSON(string text, List <IAPCurrency> currencies)
        {
            List <IAPGroup> IAPs = new List <IAPGroup>();
            JSONNode        data = JSON.Parse(text)["Catalog"];

            for (int i = 0; i < data.Count; i++)
            {
                IAPGroup g = IAPs.SingleOrDefault(x => x.name == data[i]["SIS"]["Group"]["Name"].Value);
                if (g == null)
                {
                    g       = new IAPGroup();
                    g.id    = data[i]["SIS"]["Group"]["Id"].Value;
                    g.name  = data[i]["SIS"]["Group"]["Name"].Value;
                    g.items = new List <IAPObject>();
                    IAPs.Add(g);
                }

                IAPObject obj = new IAPObject();
                obj.id          = data[i]["ItemId"].Value;
                obj.title       = data[i]["DisplayName"].Value;
                obj.description = data[i]["Description"].Value;
                obj.type        = (ProductType)data[i]["SIS"]["Type"].AsInt;
                obj.realPrice   = data[i]["SIS"]["Price"].Value;
                obj.fetch       = data[i]["SIS"]["Fetch"].AsBool;
                obj.icon        = (Sprite)AssetDatabase.LoadAssetAtPath(data[i]["SIS"]["Icon"].Value, typeof(Sprite));

                if (!string.IsNullOrEmpty(data[i]["Bundle"].ToString()))
                {
                    obj.editorType   = IAPType.Currency;
                    obj.virtualPrice = new List <IAPCurrency>();

                    foreach (string key in data[i]["Bundle"]["BundledVirtualCurrencies"].AsObject.Keys)
                    {
                        for (int j = 0; j < currencies.Count; j++)
                        {
                            if (currencies[j].name.StartsWith(key, System.StringComparison.OrdinalIgnoreCase))
                            {
                                IAPCurrency cur = new IAPCurrency();
                                cur.name   = currencies[j].name;
                                cur.amount = data[i]["Bundle"]["BundledVirtualCurrencies"][key].AsInt;
                                obj.virtualPrice.Add(cur);
                                break;
                            }
                        }
                    }
                }
                else if (string.IsNullOrEmpty(data[i]["VirtualCurrencyPrices"]["RM"].Value))
                {
                    obj.editorType   = IAPType.Virtual;
                    obj.virtualPrice = new List <IAPCurrency>();

                    foreach (string key in data[i]["VirtualCurrencyPrices"].AsObject.Keys)
                    {
                        for (int j = 0; j < currencies.Count; j++)
                        {
                            if (currencies[j].name.StartsWith(key, System.StringComparison.OrdinalIgnoreCase))
                            {
                                IAPCurrency cur = new IAPCurrency();
                                cur.name   = currencies[j].name;
                                cur.amount = data[i]["VirtualCurrencyPrices"][key].AsInt;
                                obj.virtualPrice.Add(cur);
                                break;
                            }
                        }
                    }
                }

                if (obj.editorType != IAPType.Virtual)
                {
                    int platformCount = System.Enum.GetValues(typeof(IAPPlatform)).Length;
                    for (int j = 0; j < platformCount; j++)
                    {
                        if (string.IsNullOrEmpty(data[i]["SIS"]["PlatformId"][j.ToString()].Value))
                        {
                            continue;
                        }

                        obj.storeIDs.Add(new StoreID(((IAPPlatform)j).ToString(), data[i]["SIS"]["PlatformId"][j.ToString()].Value));
                    }
                }

                if (!string.IsNullOrEmpty(data[i]["SIS"]["Requirement"].ToString()))
                {
                    obj.req.entry     = data[i]["SIS"]["Requirement"]["Id"].Value;
                    obj.req.target    = data[i]["SIS"]["Requirement"]["Value"].AsInt;
                    obj.req.labelText = data[i]["SIS"]["Requirement"]["Text"].Value;
                    obj.req.nextId    = data[i]["SIS"]["Requirement"]["Next"].Value;
                }

                g.items.Add(obj);
            }

            return(IAPs);
        }
Esempio n. 12
0
        /// <summary>
        /// Initializes all IAPItem in the scene and instantiates them with their correct state.
        /// Called by IAPManager.
        /// </summary>
        public void Init()
        {
            instance = this;
            IAPItems.Clear();
            DBManager.updatedDataEvent += Refresh;

            //get manually placed items in the scene
            IAPItem[] sceneItems = Resources.FindObjectsOfTypeAll(typeof(IAPItem)) as IAPItem[];
            for (int i = 0; i < sceneItems.Length; i++)
            {
                if (string.IsNullOrEmpty(sceneItems[i].productId))
                {
                    continue;
                }

                #if UNITY_EDITOR
                if (UnityEditor.EditorUtility.IsPersistent(sceneItems[i].gameObject))
                {
                    continue;
                }
                #endif

                IAPItems.Add(sceneItems[i].productId, sceneItems[i]);
            }


            //get list of all shop groups from IAPManager
            List <IAPGroup> list  = IAPManager.GetInstance().IAPs;
            int             index = 0;

            //loop over groups
            for (int i = 0; i < list.Count; i++)
            {
                //cache current group
                IAPGroup      group     = list[i];
                ShopContainer container = GetContainer(group.id);

                //skip group if prefab or parent wasn't set
                if (container == null || container.prefab == null || container.parent == null)
                {
                    continue;
                }

                //loop over items
                for (int j = 0; j < group.items.Count; j++)
                {
                    //cache item
                    IAPObject obj = group.items[j];
                    //the item has already been placed in the scene manually
                    //dont instantiate it in a container then
                    if (IAPItems.ContainsKey(obj.id))
                    {
                        continue;
                    }

                    //instantiate shop item in the scene and attach it to the defined parent transform
                    GameObject newItem = (GameObject)Instantiate(container.prefab);
                    newItem.transform.SetParent(container.parent.transform, false);
                    newItem.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
                    //rename item to force ordering as set in the IAP Settings editor
                    newItem.name = "IAPItem " + string.Format("{0:000}", index + j);
                    //get IAPItem component of the instantiated item
                    IAPItem item = newItem.GetComponent <IAPItem>();
                    if (item == null)
                    {
                        continue;
                    }

                    //add IAPItem to dictionary for later lookup
                    IAPItems.Add(obj.id, item);

                    //upgrades overwrite, an IAP Item gets replaced with its current level
                    List <string> upgrades = IAPManager.GetIAPUpgrades(obj.id);
                    if (upgrades != null && upgrades.Count > 0)
                    {
                        for (int k = 0; k < upgrades.Count; k++)
                        {
                            IAPItems.Add(upgrades[k], item);
                        }

                        string currentUpgrade = IAPManager.GetNextUpgrade(obj.id);

                        if (!string.IsNullOrEmpty(currentUpgrade))
                        {
                            obj = IAPManager.GetIAPObject(currentUpgrade);
                        }
                    }

                    //initialize and set up item properties based on the associated IAPObject
                    //they could get overwritten by online data later
                    item.Init(obj);
                }

                index += group.items.Count;
            }

            //refresh all products initially
            RefreshAll();
        }
Esempio n. 13
0
        //initialize IAP ids:
        //populate IAP dictionary and arrays with product ids
        private void InitIds()
        {
            //create a list only for real money purchases
            List <string> ids = new List <string>();

            if (IAPs.Count == 0)
            {
                Debug.LogError("Initializing IAPManager, but IAP List is empty. Did you set up IAPs in the IAP Settings?");
            }

            //loop over all groups
            for (int i = 0; i < IAPs.Count; i++)
            {
                //cache current group
                IAPGroup group = IAPs[i];
                //loop over items in this group
                for (int j = 0; j < group.items.Count; j++)
                {
                    //cache item
                    IAPObject obj = group.items[j];

                    if (string.IsNullOrEmpty(obj.id) || IAPObjects.ContainsKey(obj.id))
                    {
                        Debug.LogError("Found IAP Object in IAP Settings without an identifier "
                                       + " or " + obj.id + " does exist already. Skipping product.");
                        continue;
                    }

                    //add this IAPObject to the dictionary of id <> IAPObject
                    IAPObjects.Add(obj.id, obj);

                    //if it's an IAP for real money, add it to the id list
                    //on PlayFab we also add virtual products for cloud save, except in validation mode
                    #if PLAYFAB
                    if (obj.editorType == IAPType.Virtual)
                    {
                        #if PLAYFAB_VALIDATION
                        continue;
                        #endif

                        //removing free products because PlayFab does not keep them in their store
                        if (obj.virtualPrice.Where(x => x.amount > 0).FirstOrDefault() == null)
                        {
                            continue;
                        }
                    }
                    #else
                    if (obj.editorType == IAPType.Virtual)
                    {
                        continue;
                    }
                    #endif

                    ids.Add(obj.id);
                }
            }

            //don't add the restore button to the list of online purchases
            if (ids.Contains("restore"))
            {
                ids.Remove("restore");
            }

            //convert and store list of real money IAP ids as string array
            realIDs = ids.ToArray();
        }
        //instantiates shop item prefabs
        void InitShop()
        {
            //reset
            IAPItems.Clear();

            //get list of all shop groups from IAPManager
            List <IAPGroup> list  = IAPManager.GetInstance().IAPs;
            int             index = 0;

            //loop over groups
            for (int i = 0; i < list.Count; i++)
            {
                //cache current group
                IAPGroup      group     = list[i];
                ShopContainer container = GetContainer(group.id);

                //skip group if prefab or parent wasn't set
                if (container == null || container.prefab == null || container.parent == null)
                {
                    if (IAPManager.isDebug)
                    {
                        Debug.LogWarning("Setting up Shop, but prefab or parent of Group: '"
                                         + group.name + "' isn't set. Skipping group.");
                    }
                    continue;
                }

                //loop over items
                for (int j = 0; j < group.items.Count; j++)
                {
                    //cache item
                    IAPObject obj = group.items[j];
                    //instantiate shop item in the scene and attach it to the defined parent transform
                    GameObject newItem = (GameObject)Instantiate(container.prefab);
                    newItem.transform.SetParent(container.parent.transform, false);
                    newItem.GetComponent <RectTransform>().anchoredPosition = Vector2.zero;
                    //rename item to force ordering as set in the IAP Settings editor
                    newItem.name = "IAPItem " + string.Format("{0:000}", index + j);
                    //get IAPItem component of the instantiated item
                    IAPItem item = newItem.GetComponent <IAPItem>();
                    if (item == null)
                    {
                        continue;
                    }

                    //add IAPItem to dictionary for later lookup
                    IAPItems.Add(obj.id, item);

                    //upgrades overwrite, an IAP Item gets replaced with its current level
                    List <string> upgrades = IAPManager.GetIAPUpgrades(obj.id);
                    if (upgrades != null && upgrades.Count > 0)
                    {
                        for (int k = 0; k < upgrades.Count; k++)
                        {
                            IAPItems.Add(upgrades[k], item);
                        }

                        string currentUpgrade = IAPManager.GetNextUpgrade(obj.id);

                        if (!string.IsNullOrEmpty(currentUpgrade))
                        {
                            obj = IAPManager.GetIAPObject(currentUpgrade);
                        }
                    }

                    //initialize and set up item properties based on the associated IAPObject
                    //they could get overwritten by online data later
                    item.Init(obj);
                }

                index += group.items.Count;
            }
        }
Esempio n. 15
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();
        }