//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(); }
//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; } }
/// <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(); }
//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(); }