private void DrawItems() { if (CurrentTemplate.ItemDefinitions == null || CurrentTemplate.ItemDefinitions.Count == 0) { return; } GUILayout.Label("Items", EditorStyles.boldLabel); EditorGUILayout.BeginVertical(); itemsScrollPos = EditorGUILayout.BeginScrollView(itemsScrollPos, GUILayout.Width(300), GUILayout.Height(100)); // DrawItems /// Storage variable if one of them is gonna be removed. Products.Item m_itemToRemove = null; foreach (var @base in CurrentTemplate.ItemDefinitions) { EditorGUILayout.BeginHorizontal(); GUILayout.Label(@base.Id); if (GUILayout.Button("Edit")) { ItemEditor.Init(@base, (product) => { // New Item created. int target = CurrentTemplate.ItemDefinitions.FindIndex(x => x.Id.Equals(@base.Id)); if (target != -1) { CurrentTemplate.ItemDefinitions[target] = product; 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) { // Find products, using this id. if (CurrentTemplate.Products != null) { CurrentTemplate.Products.RemoveAll(x => x.ItemId == m_itemToRemove.Id); } // Remove the item. CurrentTemplate.ItemDefinitions.Remove(m_itemToRemove); // Update the template. UpdateTemplate(); } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); }