Class MultiValueToggle
Component that supports swapping between options with left/right arrows. Fully controlled component can be configured in the inspector. You may also configure Values via the control functions of AddValue(String) and AddValues(IEnumerable<String>), or RemoveValue(String) / RemoveValues(IEnumerable<String>). It is recommended that you start from a prefab to manage via script.
Inheritance
Implements
Inherited Members
Namespace: LlamaSoftware.UI
Assembly: LlamaSoftware.UI.dll
Syntax
[RequireComponent(typeof(EventTrigger), typeof(Image))]
[DisallowMultipleComponent]
[DefaultExecutionOrder(1)]
public class MultiValueToggle : Selectable, IMoveHandler, IPointerDownHandler, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, IScrollHandler, IEventSystemHandler
Fields
AllowWrapping
If enabled, allows decrementing at index 0 to wrap to the highest index and incrementing at highest index to wrap to index 0
Declaration
public bool AllowWrapping
Field Value
| Type | Description |
|---|---|
| System.Boolean |
BackgroundImage
Background image for this control
Declaration
public Image BackgroundImage
Field Value
| Type | Description |
|---|---|
| UnityEngine.UI.Image |
ChangeCallback
UnityEvent to call when value changes
Declaration
public UnityEvent ChangeCallback
Field Value
| Type | Description |
|---|---|
| UnityEngine.Events.UnityEvent |
DotsContainer
Parent to spawn PreviewDotPrefabs into, if they are enabled. Expected to have the transform name of "Dots Container"
Declaration
public Transform DotsContainer
Field Value
| Type | Description |
|---|---|
| UnityEngine.Transform |
EnablePreviewDots
Whether or not to show the preview dots
Declaration
public bool EnablePreviewDots
Field Value
| Type | Description |
|---|---|
| System.Boolean |
FadeSwapText
Whether or not to fade swap in/out the text on change
Declaration
public bool FadeSwapText
Field Value
| Type | Description |
|---|---|
| System.Boolean |
FadeSwapTextDuration
Duration of time for the animation for swapping text. 0 would be the same as setting FadeSwapText to false.
Declaration
public float FadeSwapTextDuration
Field Value
| Type | Description |
|---|---|
| System.Single |
KeyboardDelay
Delay between processing left/right arrow key presses. Too low a value will increase the risk of accidental "double taps". Too high a value will make the component appear unresponsive
Declaration
public float KeyboardDelay
Field Value
| Type | Description |
|---|---|
| System.Single |
NextArrow
Next Arrow. Handles click event to increment the current index. Expected to be the third child of this component.
Declaration
public MultiValueToggleArrow NextArrow
Field Value
| Type | Description |
|---|---|
| MultiValueToggleArrow |
PreviewDotPrefab
Prefab to use to indicate number of steps there are and which is active.
Declaration
public Image PreviewDotPrefab
Field Value
| Type | Description |
|---|---|
| UnityEngine.UI.Image |
PreviousArrow
Previous arrow. Handles click event to decrement the current index. Expected to be the first child of this component.
Declaration
public MultiValueToggleArrow PreviousArrow
Field Value
| Type | Description |
|---|---|
| MultiValueToggleArrow |
StartIndex
The initial index to select (0 = first item)
Declaration
public int StartIndex
Field Value
| Type | Description |
|---|---|
| System.Int32 |
Text
TextMeshPro object to display values on. Expected to be the second child of this component.
Declaration
public TextMeshProUGUI Text
Field Value
| Type | Description |
|---|---|
| TMPro.TextMeshProUGUI |
Values
Do not modify this directly, use the provided methods to interact with it. Public only for inspector. List of values to allow user to select from
Declaration
public List<string> Values
Field Value
| Type | Description |
|---|---|
| System.Collections.Generic.List<System.String> |
Properties
CurrentIndex
Get only. The currently selected index.
Declaration
public int CurrentIndex { get; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
Methods
AddValue(String)
Adds a specific value to the list
Declaration
public void AddValue(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | Value to add |
AddValues(IEnumerable<String>)
Adds the specified values to the list of available values
Declaration
public void AddValues(IEnumerable<string> values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<System.String> | values | Values to add |
Awake()
Declaration
protected override void Awake()
Overrides
CanDecrement()
Whether or not this MultiValueToggle can be decremented
Declaration
public bool CanDecrement()
Returns
| Type | Description |
|---|---|
| System.Boolean | Whether or not this MultiValueToggle can be decremented |
CanIncrement()
Whether or not this MultiValueToggle can be incremented
Declaration
public bool CanIncrement()
Returns
| Type | Description |
|---|---|
| System.Boolean | Whether or not this MultiValueToggle can be incremented |
Decrement()
Decrements the current index value. Call MultiValueToggle.GetCurrentValue() in your ChangeCallback, or after calling this to get the updated result.
Declaration
public void Decrement()
Disable()
Disables the MultiValueToggle
Declaration
public void Disable()
DoStateTransition(Selectable.SelectionState, Boolean)
Declaration
protected override void DoStateTransition(Selectable.SelectionState state, bool instant)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.UI.Selectable.SelectionState | state | |
| System.Boolean | instant |
Overrides
Enable()
Enables the MultiValueToggle
Declaration
public void Enable()
GetAllValues()
Returns a copy of the list of Values
Declaration
public List<string> GetAllValues()
Returns
| Type | Description |
|---|---|
| System.Collections.Generic.List<System.String> | List of Values that can be chosen from |
GetCurrentValue()
Returns the Value at the current index
Declaration
public string GetCurrentValue()
Returns
| Type | Description |
|---|---|
| System.String | Current Value |
Increment()
Increments the current index value. Call MultiValueToggle.GetCurrentValue() in your ChangeCallback, or after calling this to get the updated result.
Declaration
public void Increment()
OnScroll(PointerEventData)
Callback for on scroll event from the EventTrigger. Propagates the scroll event to the parent scroll rect.
Declaration
public void OnScroll(PointerEventData eventData)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.EventSystems.PointerEventData | eventData |
RemoveValue(String)
Removes a specific value from the list
Declaration
public void RemoveValue(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | Value to remove |
RemoveValues(IEnumerable<String>)
Removes the specified values from the list of available values
Declaration
public void RemoveValues(IEnumerable<string> values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Collections.Generic.IEnumerable<System.String> | values | Values to remove |
SetCurrentIndex()
Gets the active value index
Declaration
public int SetCurrentIndex()
Returns
| Type | Description |
|---|---|
| System.Int32 |
SetCurrentIndex(Int32)
Sets the current index to the specified index
Declaration
public void SetCurrentIndex(int index)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | index | Index to set. |
SetValue(String)
Sets the current index to the specified value
Declaration
public void SetValue(string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | value | Value to set. Must be within the set of available Values |
UpdateParentScrollView(BaseEventData)
Intended for EventTrigger use only
Declaration
public void UpdateParentScrollView(BaseEventData pointerEvent)
Parameters
| Type | Name | Description |
|---|---|---|
| UnityEngine.EventSystems.BaseEventData | pointerEvent | Pointer Event Data from the EventTrigger |
UpdateText(Int32)
Update the inner text of the MultiValueToggle based on the current index. Will fire onChange events.
Declaration
public void UpdateText(int newIndex)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | newIndex | Index of the next value to show |