Replaced OnSelectionChanged with event(s) accessible from the inspector (DropDownList & AutoCompleteComboBox)
parent
6565b1a6d1
commit
8549c3ba6a
|
@ -15,8 +15,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
public List<string> AvailableOptions;
|
public List<string> AvailableOptions;
|
||||||
|
|
||||||
public System.Action<int> OnSelectionChanged; // fires when selection is changed;
|
|
||||||
|
|
||||||
//private bool isInitialized = false;
|
//private bool isInitialized = false;
|
||||||
private bool _isPanelActive = false;
|
private bool _isPanelActive = false;
|
||||||
private bool _hasDrawnOnce = false;
|
private bool _hasDrawnOnce = false;
|
||||||
|
@ -134,6 +132,27 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
private bool _selectionIsValid = false;
|
private bool _selectionIsValid = false;
|
||||||
|
|
||||||
|
[System.Serializable]
|
||||||
|
public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<string, bool> {
|
||||||
|
}
|
||||||
|
|
||||||
|
[System.Serializable]
|
||||||
|
public class SelectinTextChangedEvent : UnityEngine.Events.UnityEvent<string> {
|
||||||
|
}
|
||||||
|
|
||||||
|
[System.Serializable]
|
||||||
|
public class SelectionValidityChangedEvent : UnityEngine.Events.UnityEvent<bool> {
|
||||||
|
}
|
||||||
|
|
||||||
|
// fires when input text is changed;
|
||||||
|
public SelectinTextChangedEvent OnSelectinTextChanged;
|
||||||
|
// fires when when an Item gets selected / deselected (including when items are added/removed once this is possible)
|
||||||
|
public SelectionValidityChangedEvent OnSelectionValidityChanged;
|
||||||
|
// fires in both cases
|
||||||
|
public SelectionChangedEvent OnSelectionChanged;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void Awake()
|
public void Awake()
|
||||||
{
|
{
|
||||||
Initialize();
|
Initialize();
|
||||||
|
@ -369,7 +388,15 @@ namespace UnityEngine.UI.Extensions
|
||||||
{
|
{
|
||||||
ToggleDropdownPanel(false);
|
ToggleDropdownPanel(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool validity_changed = (_panelItems.Contains (Text) == _selectionIsValid);
|
||||||
_selectionIsValid = _panelItems.Contains (Text);
|
_selectionIsValid = _panelItems.Contains (Text);
|
||||||
|
OnSelectionChanged.Invoke (Text, _selectionIsValid);
|
||||||
|
OnSelectinTextChanged.Invoke (Text);
|
||||||
|
if(validity_changed){
|
||||||
|
OnSelectionValidityChanged.Invoke (_selectionIsValid);
|
||||||
|
}
|
||||||
|
|
||||||
SetInputTextColor ();
|
SetInputTextColor ();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,6 @@ namespace UnityEngine.UI.Extensions
|
||||||
public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it
|
public DropDownListItem SelectedItem { get; private set; } //outside world gets to get this, not set it
|
||||||
|
|
||||||
public List<DropDownListItem> Items;
|
public List<DropDownListItem> Items;
|
||||||
public System.Action<int> OnSelectionChanged; // fires when selection is changed;
|
|
||||||
public bool OverrideHighlighted = true;
|
public bool OverrideHighlighted = true;
|
||||||
|
|
||||||
//private bool isInitialized = false;
|
//private bool isInitialized = false;
|
||||||
|
@ -109,6 +108,15 @@ namespace UnityEngine.UI.Extensions
|
||||||
|
|
||||||
public bool SelectFirstItemOnStart = false;
|
public bool SelectFirstItemOnStart = false;
|
||||||
|
|
||||||
|
[System.Serializable]
|
||||||
|
public class SelectionChangedEvent : UnityEngine.Events.UnityEvent<int> {
|
||||||
|
}
|
||||||
|
// fires when item is changed;
|
||||||
|
public SelectionChangedEvent OnSelectionChanged;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
Initialize();
|
Initialize();
|
||||||
|
@ -239,7 +247,7 @@ namespace UnityEngine.UI.Extensions
|
||||||
private void OnItemClicked(int indx)
|
private void OnItemClicked(int indx)
|
||||||
{
|
{
|
||||||
Debug.Log("item " + indx + " clicked");
|
Debug.Log("item " + indx + " clicked");
|
||||||
if (indx != _selectedIndex && OnSelectionChanged != null) OnSelectionChanged(indx);
|
if (indx != _selectedIndex && OnSelectionChanged != null) OnSelectionChanged.Invoke(indx);
|
||||||
|
|
||||||
_selectedIndex = indx;
|
_selectedIndex = indx;
|
||||||
ToggleDropdownPanel(true);
|
ToggleDropdownPanel(true);
|
||||||
|
|
Loading…
Reference in New Issue