private void DrawBundles() { if (CurrentTemplate.Bundles == null || CurrentTemplate.Bundles.Count == 0) { return; } GUILayout.Label("Bundles", EditorStyles.boldLabel); EditorGUILayout.BeginVertical(); bundleScrollPos = EditorGUILayout.BeginScrollView(bundleScrollPos, GUILayout.Width(300), GUILayout.Height(100)); // DrawBundles /// Storage variable if one of them is gonna be removed. Products.Bundle m_itemToRemove = null; foreach (var @base in CurrentTemplate.Bundles) { EditorGUILayout.BeginHorizontal(); GUILayout.Label(@base.Id); if (GUILayout.Button("Edit")) { BundleEditor.Init(@base, (bundle) => { // New Item created. int target = CurrentTemplate.Bundles.FindIndex(x => x.Id.Equals(bundle.Id)); if (target != -1) { CurrentTemplate.Bundles[target] = bundle; UpdateTemplate(); } }); } if (GUILayout.Button("Delete")) { if (EditorUtility.DisplayDialog("Beware!", "Do you want to delete this item? All products using this item will be removed also!!", "Go ahead", "Cancel")) { m_itemToRemove = @base; } } EditorGUILayout.EndHorizontal(); } if (m_itemToRemove != null) { // Remove the base. CurrentTemplate.Bundles.Remove(m_itemToRemove); // Update the template. UpdateTemplate(); } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); }
public static void Init(Products.Bundle targetBase = null, Action <Products.Bundle> OnComplete = null) { CompletedAction = OnComplete; if (targetBase != null) { CurrentBase = (Products.Bundle)targetBase.Clone(); } else { CurrentBase = new Products.Bundle(); } int templateProductsCount = CurrentBase.BundleItems.Count; int totalItemsCount = TemplateEditor.CurrentTemplate.ItemDefinitions.Count; selection = new int[templateProductsCount]; itemList = new string[totalItemsCount]; for (int i = 0; i < totalItemsCount; i++) { itemList[i] = TemplateEditor.CurrentTemplate.ItemDefinitions[i].Id; } // set current selections for (int i = 0; i < templateProductsCount; i++) { selection[i] = itemList.ToList().FindIndex(x => x.Equals(CurrentBase.BundleItems[i].ItemId)); } pricesEditor = new PricesEditor(); // Create window. var window = (BundleEditor)GetWindow(typeof(BundleEditor)); window.minSize = new Vector2(320, 510); window.maxSize = new Vector2(320, 510); window.Show(); }