diff --git a/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs b/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs index 04274c1..a59f39e 100644 --- a/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs +++ b/Runtime/Scripts/Controls/ComboBox/AutoCompleteComboBox.cs @@ -213,6 +213,43 @@ namespace UnityEngine.UI.Extensions } */ + public void AddItem(string item) + { + AvailableOptions.Add(item); + RebuildPanel(); + } + + public void RemoveItem(string item) + { + AvailableOptions.Remove(item); + RebuildPanel(); + } + + public void SetAvailableOptions(List newOptions) + { + AvailableOptions.Clear(); + AvailableOptions = newOptions; + RebuildPanel(); + } + + public void SetAvailableOptions(string[] newOptions) + { + AvailableOptions.Clear(); + + for (int i = 0; i < newOptions.Length; i++) + { + AvailableOptions.Add(newOptions[i]); + } + + RebuildPanel(); + } + + public void ResetItems() + { + AvailableOptions.Clear(); + RebuildPanel(); + } + /// /// Rebuilds the contents of the panel in response to items being added. /// diff --git a/Runtime/Scripts/Controls/ComboBox/ComboBox.cs b/Runtime/Scripts/Controls/ComboBox/ComboBox.cs index 156cd1a..02da2ff 100644 --- a/Runtime/Scripts/Controls/ComboBox/ComboBox.cs +++ b/Runtime/Scripts/Controls/ComboBox/ComboBox.cs @@ -131,34 +131,41 @@ 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) + public void AddItem(string item) { - 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 + AvailableOptions.Add(item); + RebuildPanel(); + } + + public void RemoveItem(string item) + { + AvailableOptions.Remove(item); + RebuildPanel(); + } + + public void SetAvailableOptions(List newOptions) + { + AvailableOptions.Clear(); + AvailableOptions = newOptions; + RebuildPanel(); + } + + public void SetAvailableOptions(string[] newOptions) + { + AvailableOptions.Clear(); + + for (int i = 0; i < newOptions.Length; i++) + { + AvailableOptions.Add(newOptions[i]); + } + RebuildPanel(); + } + + public void ResetItems() + { + AvailableOptions.Clear(); RebuildPanel(); } - */ /// /// Rebuilds the contents of the panel in response to items being added.