commit
322e804f25
|
@ -49,6 +49,9 @@ namespace UnityEngine.UI.Extensions
|
||||||
private GameObject _itemTemplate;
|
private GameObject _itemTemplate;
|
||||||
private bool _initialized;
|
private bool _initialized;
|
||||||
|
|
||||||
|
private string _defaultMainButtonCaption = null;
|
||||||
|
private Color _defaultNormalColor;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private float _scrollBarWidth = 20.0f;
|
private float _scrollBarWidth = 20.0f;
|
||||||
public float ScrollBarWidth
|
public float ScrollBarWidth
|
||||||
|
@ -61,7 +64,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private int scrollOffset; //offset of the selected item
|
|
||||||
private int _selectedIndex = -1;
|
private int _selectedIndex = -1;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
|
@ -98,7 +100,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
[System.Serializable]
|
[System.Serializable]
|
||||||
public class ControlDisabledEvent : Events.UnityEvent<bool> { }
|
public class ControlDisabledEvent : Events.UnityEvent<bool> { }
|
||||||
|
|
||||||
// fires when item is changed;
|
// fires when item changes between enabled and disabled;
|
||||||
public ControlDisabledEvent OnControlDisabled;
|
public ControlDisabledEvent OnControlDisabled;
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
|
@ -121,6 +123,9 @@ namespace UnityEngine.UI.Extensions
|
||||||
_rectTransform = GetComponent<RectTransform>();
|
_rectTransform = GetComponent<RectTransform>();
|
||||||
_mainButton = new DropDownListButton(_rectTransform.Find("MainButton").gameObject);
|
_mainButton = new DropDownListButton(_rectTransform.Find("MainButton").gameObject);
|
||||||
|
|
||||||
|
_defaultMainButtonCaption = _mainButton.txt.text;
|
||||||
|
_defaultNormalColor = _mainButton.btn.colors.normalColor;
|
||||||
|
|
||||||
_overlayRT = _rectTransform.Find("Overlay").GetComponent<RectTransform>();
|
_overlayRT = _rectTransform.Find("Overlay").GetComponent<RectTransform>();
|
||||||
_overlayRT.gameObject.SetActive(false);
|
_overlayRT.gameObject.SetActive(false);
|
||||||
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
|
_scrollPanelRT = _overlayRT.Find("ScrollPanel").GetComponent<RectTransform>();
|
||||||
|
@ -266,6 +271,24 @@ namespace UnityEngine.UI.Extensions
|
||||||
RedrawPanel();
|
RedrawPanel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ResetDropDown()
|
||||||
|
{
|
||||||
|
if (!_initialized)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_mainButton.txt.text = _defaultMainButtonCaption;
|
||||||
|
for (int i = 0; i < _itemsPanelRT.childCount; i++)
|
||||||
|
{
|
||||||
|
_panelItems[i].btnImg.color = _defaultNormalColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
_selectedIndex = -1;
|
||||||
|
_initialized = false;
|
||||||
|
Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
public void ResetItems()
|
public void ResetItems()
|
||||||
{
|
{
|
||||||
Items.Clear();
|
Items.Clear();
|
||||||
|
@ -407,38 +430,63 @@ namespace UnityEngine.UI.Extensions
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Toggle the drop down list
|
/// Toggle the drop down list if it is active
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="directClick"> whether an item was directly clicked on</param>
|
/// <param name="directClick">Retained for backwards compatibility only.</param>
|
||||||
public void ToggleDropdownPanel(bool directClick)
|
[Obsolete("DirectClick Parameter is no longer required")]
|
||||||
|
public void ToggleDropdownPanel(bool directClick = false)
|
||||||
{
|
{
|
||||||
if (!isActive) return;
|
ToggleDropdownPanel();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Toggle the drop down list if it is active
|
||||||
|
/// </summary>
|
||||||
|
public void ToggleDropdownPanel()
|
||||||
|
{
|
||||||
|
if (!isActive)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_overlayRT.transform.localScale = new Vector3(1, 1, 1);
|
_overlayRT.transform.localScale = new Vector3(1, 1, 1);
|
||||||
_scrollBarRT.transform.localScale = new Vector3(1, 1, 1);
|
_scrollBarRT.transform.localScale = new Vector3(1, 1, 1);
|
||||||
_isPanelActive = !_isPanelActive;
|
_isPanelActive = !_isPanelActive;
|
||||||
_overlayRT.gameObject.SetActive(_isPanelActive);
|
_overlayRT.gameObject.SetActive(_isPanelActive);
|
||||||
|
|
||||||
if (_isPanelActive)
|
if (_isPanelActive)
|
||||||
{
|
{
|
||||||
transform.SetAsLastSibling();
|
transform.SetAsLastSibling();
|
||||||
}
|
}
|
||||||
else if (directClick)
|
|
||||||
{
|
|
||||||
// scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Hides the drop down panel if its visible at the moment
|
||||||
|
/// </summary>
|
||||||
|
public void HideDropDownPanel()
|
||||||
|
{
|
||||||
|
if (!_isPanelActive)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ToggleDropdownPanel(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the control and sets its active status, determines whether the dropdown will open ot not
|
/// Updates the control and sets its active status, determines whether the dropdown will open ot not
|
||||||
|
/// and takes care of the underlying button to follow the status.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="status"></param>
|
/// <param name="status"></param>
|
||||||
public void SetActive(bool status)
|
public void SetActive(bool status)
|
||||||
{
|
{
|
||||||
if (status != isActive)
|
if (status == isActive)
|
||||||
{
|
{
|
||||||
OnControlDisabled?.Invoke(status);
|
return;
|
||||||
}
|
}
|
||||||
isActive = status;
|
isActive = status;
|
||||||
|
OnControlDisabled?.Invoke(isActive);
|
||||||
|
_mainButton.btn.enabled = isActive;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue