fix: SetActive() takes care of btn. Add: ded. Hide funct

pull/453/head
Robert Wartenberg 2023-08-16 14:47:35 +02:00
parent 2a59f37653
commit 95f1956f48
1 changed files with 21 additions and 14 deletions

View File

@ -101,7 +101,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 changed between enabled and disabled;
public ControlDisabledEvent OnControlDisabled; public ControlDisabledEvent OnControlDisabled;
public void Start() public void Start()
@ -427,38 +427,45 @@ namespace UnityEngine.UI.Extensions
} }
/// <summary> /// <summary>
/// Toggle the drop down list /// Toggle the drop down list if it's active
/// </summary> /// </summary>
/// <param name="directClick"> whether an item was directly clicked on</param> /// <param name="directClick">makes no difference, only for backwards compatibility reasons</param>
public void ToggleDropdownPanel(bool directClick) public void ToggleDropdownPanel(bool directClick)
{ {
if (!isActive) return; 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)
{ /// <summary>
// scrollOffset = Mathf.RoundToInt(itemsPanelRT.anchoredPosition.y / _rectTransform.sizeDelta.y); /// 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)
{ return;
OnControlDisabled?.Invoke(status);
}
isActive = status; isActive = status;
OnControlDisabled?.Invoke(isActive);
_mainButton.btn.enabled = isActive;
} }
} }
} }