diff --git a/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs b/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs index a59f39e..51ecb75 100644 --- a/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs +++ b/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs @@ -184,35 +184,6 @@ namespace UnityEngine.UI.Extensions return success; } - /* currently just using items in the list instead of being able to add to it. - public void AddItems(params object[] list) - { - List ddItems = new List(); - foreach (var obj in list) - { - if (obj is DropDownListItem) - { - ddItems.Add((DropDownListItem)obj); - } - else if (obj is string) - { - ddItems.Add(new DropDownListItem(caption: (string)obj)); - } - else if (obj is Sprite) - { - ddItems.Add(new DropDownListItem(image: (Sprite)obj)); - } - else - { - throw new System.Exception("Only ComboBoxItems, Strings, and Sprite types are allowed"); - } - } - Items.AddRange(ddItems); - Items = Items.Distinct().ToList();//remove any duplicates - RebuildPanel(); - } - */ - public void AddItem(string item) { AvailableOptions.Add(item); diff --git a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs index b702d46..959c8fe 100644 --- a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs +++ b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs @@ -133,9 +133,17 @@ namespace UnityEngine.UI.Extensions return success; } - /* currently just using items in the list instead of being able to add to it. - public void AddItems(params object[] list) + // currently just using items in the list instead of being able to add to it. + /// + /// Rebuilds the list from a new collection. + /// + /// + /// NOTE, this will clear all existing items + /// + /// + public void RefreshItems(params object[] list) { + Items.Clear(); List ddItems = new List(); foreach (var obj in list) { @@ -157,10 +165,74 @@ namespace UnityEngine.UI.Extensions } } Items.AddRange(ddItems); - Items = Items.Distinct().ToList();//remove any duplicates RebuildPanel(); } - */ + + /// + /// Adds an additional item to the drop down list (recommended) + /// + /// Item of type DropDownListItem + public void AddItem(DropDownListItem item) + { + Items.Add(item); + RebuildPanel(); + } + + /// + /// Adds an additional drop down list item using a string name + /// + /// Item of type String + public void AddItem(string item) + { + Items.Add(new DropDownListItem(caption: (string)item)); + RebuildPanel(); + } + + /// + /// Adds an additional drop down list item using a sprite image + /// + /// Item of type UI Sprite + public void AddItem(Sprite item) + { + Items.Add(new DropDownListItem(image: (Sprite)item)); + RebuildPanel(); + } + + /// + /// Removes an item from the drop down list (recommended) + /// + /// Item of type DropDownListItem + public void RemoveItem(DropDownListItem item) + { + Items.Remove(item); + RebuildPanel(); + } + + /// + /// Removes an item from the drop down list item using a string name + /// + /// Item of type String + public void RemoveItem(string item) + { + Items.Remove(new DropDownListItem(caption: (string)item)); + RebuildPanel(); + } + + /// + /// Removes an item from the drop down list item using a sprite image + /// + /// Item of type UI Sprite + public void RemoveItem(Sprite item) + { + Items.Remove(new DropDownListItem(image: (Sprite)item)); + RebuildPanel(); + } + + public void ResetItems() + { + Items.Clear(); + RebuildPanel(); + } /// /// Rebuilds the contents of the panel in response to items being added.