Updates from testing

pull/413/head
Simon (darkside) Jackson 2020-09-24 21:47:00 +01:00
parent 0e99d8e63f
commit dcd43da6b8
2 changed files with 18 additions and 5 deletions

View File

@ -95,6 +95,8 @@ namespace UnityEngine.UI.Extensions
} }
} }
public float DropdownOffset = 10f;
//TODO design as foldout for Inspector //TODO design as foldout for Inspector
public Color ValidSelectionTextColor = Color.green; public Color ValidSelectionTextColor = Color.green;
public Color MatchingItemsRemainingTextColor = Color.black; public Color MatchingItemsRemainingTextColor = Color.black;
@ -226,11 +228,19 @@ namespace UnityEngine.UI.Extensions
/// </summary> /// </summary>
private void RebuildPanel() private void RebuildPanel()
{ {
if (_isPanelActive) ToggleDropdownPanel();
//panel starts with all options //panel starts with all options
_panelItems.Clear(); _panelItems.Clear();
_prunedPanelItems.Clear(); _prunedPanelItems.Clear();
panelObjects.Clear(); panelObjects.Clear();
//clear Autocomplete children in scene
foreach (Transform child in _itemsPanelRT.transform)
{
Destroy(child.gameObject);
}
foreach (string option in AvailableOptions) foreach (string option in AvailableOptions)
{ {
_panelItems.Add(option.ToLower()); _panelItems.Add(option.ToLower());
@ -334,7 +344,7 @@ namespace UnityEngine.UI.Extensions
if (_panelItems.Count < 1) return; if (_panelItems.Count < 1) return;
float dropdownHeight = _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count); float dropdownHeight = _rectTransform.sizeDelta.y * Mathf.Min(_itemsToDisplay, _panelItems.Count) + DropdownOffset;
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight); _scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, dropdownHeight);
_scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x); _scrollPanelRT.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, _rectTransform.sizeDelta.x);
@ -395,7 +405,7 @@ namespace UnityEngine.UI.Extensions
/// Toggle the drop down list /// Toggle the drop down list
/// </summary> /// </summary>
/// <param name="directClick"> whether an item was directly clicked on</param> /// <param name="directClick"> whether an item was directly clicked on</param>
public void ToggleDropdownPanel(bool directClick) public void ToggleDropdownPanel(bool directClick = false)
{ {
_isPanelActive = !_isPanelActive; _isPanelActive = !_isPanelActive;

View File

@ -21,6 +21,9 @@ namespace UnityEngine.UI.Extensions
[SerializeField] [SerializeField]
private int _itemsToDisplay; private int _itemsToDisplay;
[SerializeField]
private bool _sortItems = true;
[System.Serializable] [System.Serializable]
public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<string> public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<string>
{ {
@ -178,7 +181,7 @@ namespace UnityEngine.UI.Extensions
{ {
_panelItems.Add(option.ToLower()); _panelItems.Add(option.ToLower());
} }
_panelItems.Sort(); if(_sortItems) _panelItems.Sort();
List<GameObject> itemObjs = new List<GameObject>(panelObjects.Values); List<GameObject> itemObjs = new List<GameObject>(panelObjects.Values);
panelObjects.Clear(); panelObjects.Clear();