Add a way to set option of a UISwitchSelect without triggering the callback

This commit is contained in:
Lucien 2026-06-17 16:08:26 +02:00
parent 9ea2f109c4
commit 4732fc21b2

View File

@ -136,6 +136,20 @@ namespace DuloGames.UI
/// </summary>
/// <param name="optionIndex">Option index.</param>
public void SelectOptionByIndex(int index)
{
SelectOptionByIndex(index, true);
}
/// <summary>
/// Selects the option by index.
/// </summary>
/// <param name="optionIndex">Option index.</param>
public void SelectOptionByIndexWithoutNotifying(int index)
{
SelectOptionByIndex(index, false);
}
void SelectOptionByIndex(int index, bool notify)
{
// Check if the option index is valid
if (index < 0 || index >= this.m_Options.Count)
@ -150,7 +164,7 @@ namespace DuloGames.UI
this.m_SelectedItem = newOption;
// Trigger change
this.TriggerChangeEvent();
this.TriggerChangeEvent(notify);
}
}
@ -258,14 +272,14 @@ namespace DuloGames.UI
/// <summary>
/// Tiggers the change event.
/// </summary>
protected virtual void TriggerChangeEvent()
protected virtual void TriggerChangeEvent(bool invokeCallback = true)
{
// Apply the string to the label componenet
if (this.m_Text != null)
this.m_Text.text = this.m_SelectedItem;
// Invoke the on change event
if (onChange != null)
if (onChange != null && invokeCallback)
onChange.Invoke(this.selectedOptionIndex, this.m_SelectedItem);
}
}