Add a way to set option of a UISwitchSelect without triggering the callback
This commit is contained in:
parent
9ea2f109c4
commit
4732fc21b2
@ -137,6 +137,20 @@ namespace DuloGames.UI
|
|||||||
/// <param name="optionIndex">Option index.</param>
|
/// <param name="optionIndex">Option index.</param>
|
||||||
public void SelectOptionByIndex(int index)
|
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
|
// Check if the option index is valid
|
||||||
if (index < 0 || index >= this.m_Options.Count)
|
if (index < 0 || index >= this.m_Options.Count)
|
||||||
return;
|
return;
|
||||||
@ -150,9 +164,9 @@ namespace DuloGames.UI
|
|||||||
this.m_SelectedItem = newOption;
|
this.m_SelectedItem = newOption;
|
||||||
|
|
||||||
// Trigger change
|
// Trigger change
|
||||||
this.TriggerChangeEvent();
|
this.TriggerChangeEvent(notify);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Selects the option by value.
|
/// Selects the option by value.
|
||||||
@ -258,14 +272,14 @@ namespace DuloGames.UI
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tiggers the change event.
|
/// Tiggers the change event.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void TriggerChangeEvent()
|
protected virtual void TriggerChangeEvent(bool invokeCallback = true)
|
||||||
{
|
{
|
||||||
// Apply the string to the label componenet
|
// Apply the string to the label componenet
|
||||||
if (this.m_Text != null)
|
if (this.m_Text != null)
|
||||||
this.m_Text.text = this.m_SelectedItem;
|
this.m_Text.text = this.m_SelectedItem;
|
||||||
|
|
||||||
// Invoke the on change event
|
// Invoke the on change event
|
||||||
if (onChange != null)
|
if (onChange != null && invokeCallback)
|
||||||
onChange.Invoke(this.selectedOptionIndex, this.m_SelectedItem);
|
onChange.Invoke(this.selectedOptionIndex, this.m_SelectedItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user