diff --git a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs
index 46ea9d3..40e90c4 100644
--- a/Runtime/Scripts/Controls/ComboBox/DropDownList.cs
+++ b/Runtime/Scripts/Controls/ComboBox/DropDownList.cs
@@ -5,25 +5,25 @@ using System.Collections.Generic;
namespace UnityEngine.UI.Extensions
{
- ///
- /// Extension to the UI class which creates a dropdown list
- ///
- [RequireComponent(typeof(RectTransform))]
+ ///
+ /// Extension to the UI class which creates a dropdown list
+ ///
+ [RequireComponent(typeof(RectTransform))]
[AddComponentMenu("UI/Extensions/ComboBox/Dropdown List")]
public class DropDownList : MonoBehaviour
{
public Color disabledTextColor;
public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it
- [Header("Dropdown List Items")]
- public List Items;
+ [Header("Dropdown List Items")]
+ public List Items;
- [Header("Properties")]
+ [Header("Properties")]
- [SerializeField]
- private bool isActive = true;
+ [SerializeField]
+ private bool isActive = true;
- public bool OverrideHighlighted = true;
+ public bool OverrideHighlighted = true;
//private bool isInitialized = false;
private bool _isPanelActive = false;
@@ -46,13 +46,13 @@ namespace UnityEngine.UI.Extensions
private List _panelItems = new List();
- private GameObject _itemTemplate;
+ private GameObject _itemTemplate;
private bool _initialized;
private string _defaultMainButtonCaption = null;
private Color _defaultNormalColor;
- [SerializeField]
+ [SerializeField]
private float _scrollBarWidth = 20.0f;
public float ScrollBarWidth
{
@@ -64,7 +64,7 @@ namespace UnityEngine.UI.Extensions
}
}
- // private int scrollOffset; //offset of the selected item
+ // private int scrollOffset; //offset of the selected item
private int _selectedIndex = -1;
[SerializeField]
@@ -79,42 +79,42 @@ namespace UnityEngine.UI.Extensions
}
}
- [SerializeField]
- private float dropdownOffset;
+ [SerializeField]
+ private float dropdownOffset;
- [SerializeField]
- private bool _displayPanelAbove = false;
+ [SerializeField]
+ private bool _displayPanelAbove = false;
- public bool SelectFirstItemOnStart = false;
+ public bool SelectFirstItemOnStart = false;
- [SerializeField]
- private int selectItemIndexOnStart = 0;
- private bool shouldSelectItemOnStart => SelectFirstItemOnStart || selectItemIndexOnStart > 0;
+ [SerializeField]
+ private int selectItemIndexOnStart = 0;
+ private bool shouldSelectItemOnStart => SelectFirstItemOnStart || selectItemIndexOnStart > 0;
- [System.Serializable]
+ [System.Serializable]
public class SelectionChangedEvent : Events.UnityEvent { }
- // fires when item is changed;
- [Header("Events")]
- public SelectionChangedEvent OnSelectionChanged;
+ // fires when item is changed;
+ [Header("Events")]
+ public SelectionChangedEvent OnSelectionChanged;
- [System.Serializable]
- public class ControlDisabledEvent : Events.UnityEvent { }
+ [System.Serializable]
+ public class ControlDisabledEvent : Events.UnityEvent { }
- // fires when item is changed;
- public ControlDisabledEvent OnControlDisabled;
+ // fires when item is changed;
+ public ControlDisabledEvent OnControlDisabled;
- public void Start()
- {
- Initialize();
- if (shouldSelectItemOnStart && Items.Count > 0)
- {
- SelectItemIndex(SelectFirstItemOnStart ? 0 : selectItemIndexOnStart);
- }
- RedrawPanel();
- }
+ public void Start()
+ {
+ Initialize();
+ if (shouldSelectItemOnStart && Items.Count > 0)
+ {
+ SelectItemIndex(SelectFirstItemOnStart ? 0 : selectItemIndexOnStart);
+ }
+ RedrawPanel();
+ }
- private bool Initialize()
+ private bool Initialize()
{
if (_initialized) return true;
@@ -153,32 +153,32 @@ namespace UnityEngine.UI.Extensions
Debug.LogError("Something is setup incorrectly with the dropdownlist component causing a Null Reference Exception");
success = false;
}
- _initialized = true;
+ _initialized = true;
- RebuildPanel();
+ RebuildPanel();
RedrawPanel();
return success;
}
- ///
+ ///
/// Update the drop down selection to a specific index
///
///
public void SelectItemIndex(int index)
- {
- ToggleDropdownPanel(false);
- OnItemClicked(index);
- }
+ {
+ ToggleDropdownPanel(false);
+ OnItemClicked(index);
+ }
- // 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)
+ // 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();
@@ -203,74 +203,74 @@ namespace UnityEngine.UI.Extensions
}
Items.AddRange(ddItems);
RebuildPanel();
- RedrawPanel();
- }
+ RedrawPanel();
+ }
- ///
- /// Adds an additional item to the drop down list (recommended)
- ///
- /// Item of type DropDownListItem
- public void AddItem(DropDownListItem item)
- {
+ ///
+ /// Adds an additional item to the drop down list (recommended)
+ ///
+ /// Item of type DropDownListItem
+ public void AddItem(DropDownListItem item)
+ {
Items.Add(item);
RebuildPanel();
RedrawPanel();
- }
+ }
- ///
- /// Adds an additional drop down list item using a string name
- ///
- /// Item of type String
- public void AddItem(string item)
+ ///
+ /// 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();
- RedrawPanel();
- }
+ RedrawPanel();
+ }
- ///
- /// Adds an additional drop down list item using a sprite image
- ///
- /// Item of type UI Sprite
- public void AddItem(Sprite item)
+ ///
+ /// 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();
- RedrawPanel();
- }
+ RedrawPanel();
+ }
- ///
- /// Removes an item from the drop down list (recommended)
- ///
- /// Item of type DropDownListItem
- public void RemoveItem(DropDownListItem item)
+ ///
+ /// Removes an item from the drop down list (recommended)
+ ///
+ /// Item of type DropDownListItem
+ public void RemoveItem(DropDownListItem item)
{
Items.Remove(item);
RebuildPanel();
- RedrawPanel();
- }
+ RedrawPanel();
+ }
- ///
- /// Removes an item from the drop down list item using a string name
- ///
- /// Item of type String
- public void RemoveItem(string item)
+ ///
+ /// 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();
- RedrawPanel();
- }
+ RedrawPanel();
+ }
- ///
- /// Removes an item from the drop down list item using a sprite image
- ///
- /// Item of type UI Sprite
- public void RemoveItem(Sprite item)
+ ///
+ /// 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();
- RedrawPanel();
- }
+ RedrawPanel();
+ }
public void ResetDropDown()
{
@@ -369,25 +369,25 @@ namespace UnityEngine.UI.Extensions
_mainButton.txt.text = SelectedItem.Caption;
- //update selected index color
- if (OverrideHighlighted)
- {
- for (int i = 0; i < _itemsPanelRT.childCount; i++)
- {
- _panelItems[i].btnImg.color = (_selectedIndex == i) ? _mainButton.btn.colors.highlightedColor : new Color(0, 0, 0, 0);
- }
- }
- }
+ //update selected index color
+ if (OverrideHighlighted)
+ {
+ for (int i = 0; i < _itemsPanelRT.childCount; i++)
+ {
+ _panelItems[i].btnImg.color = (_selectedIndex == i) ? _mainButton.btn.colors.highlightedColor : new Color(0, 0, 0, 0);
+ }
+ }
+ }
private void RedrawPanel()
{
float scrollbarWidth = _panelItems.Count > ItemsToDisplay ? _scrollBarWidth : 0f;//hide the scrollbar if there's not enough items
_scrollBarRT.gameObject.SetActive(_panelItems.Count > ItemsToDisplay);
- float dropdownHeight = _itemsToDisplay > 0 ? _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) : _rectTransform.sizeDelta.y * _panelItems.Count;
- dropdownHeight += dropdownOffset;
+ float dropdownHeight = _itemsToDisplay > 0 ? _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) : _rectTransform.sizeDelta.y * _panelItems.Count;
+ dropdownHeight += dropdownOffset;
- if (!_hasDrawnOnce || _rectTransform.sizeDelta != _mainButton.rectTransform.sizeDelta)
+ if (!_hasDrawnOnce || _rectTransform.sizeDelta != _mainButton.rectTransform.sizeDelta)
{
_hasDrawnOnce = true;
_mainButton.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
@@ -397,12 +397,12 @@ namespace UnityEngine.UI.Extensions
itemsRemaining = itemsRemaining < 0 ? 0 : itemsRemaining;
_scrollPanelRT.SetParent(transform, true);
- _scrollPanelRT.anchoredPosition = _displayPanelAbove ?
- new Vector2(0, dropdownOffset + dropdownHeight) :
- new Vector2(0, -(dropdownOffset + _rectTransform.sizeDelta.y));
+ _scrollPanelRT.anchoredPosition = _displayPanelAbove ?
+ new Vector2(0, dropdownOffset + dropdownHeight) :
+ new Vector2(0, -(dropdownOffset + _rectTransform.sizeDelta.y));
- //make the overlay fill the screen
- _overlayRT.SetParent(_canvas.transform, false);
+ //make the overlay fill the screen
+ _overlayRT.SetParent(_canvas.transform, false);
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _canvasRT.sizeDelta.x);
_overlayRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, _canvasRT.sizeDelta.y);
@@ -412,7 +412,7 @@ namespace UnityEngine.UI.Extensions
if (_panelItems.Count < 1) return;
- _scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
+ _scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
_itemsPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _scrollPanelRT.sizeDelta.x - scrollbarWidth - 5);
@@ -432,7 +432,7 @@ namespace UnityEngine.UI.Extensions
/// whether an item was directly clicked on
public void ToggleDropdownPanel(bool directClick)
{
- if (!isActive) return;
+ if (!isActive) return;
_overlayRT.transform.localScale = new Vector3(1, 1, 1);
_scrollBarRT.transform.localScale = new Vector3(1, 1, 1);
@@ -448,17 +448,17 @@ namespace UnityEngine.UI.Extensions
}
}
- ///
- /// Updates the control and sets its active status, determines whether the dropdown will open ot not
- ///
- ///
- public void SetActive(bool status)
- {
- if (status != isActive)
- {
- OnControlDisabled?.Invoke(status);
- }
- isActive = status;
- }
- }
+ ///
+ /// Updates the control and sets its active status, determines whether the dropdown will open ot not
+ ///
+ ///
+ public void SetActive(bool status)
+ {
+ if (status != isActive)
+ {
+ OnControlDisabled?.Invoke(status);
+ }
+ isActive = status;
+ }
+ }
}
\ No newline at end of file