Picker

Base class for the custom pickers.

Options

  • AutoFocus bool

    Set focus to the last Selectable object in the Picker.

  • Close Button Button

    Button to close picker.

  • Hide on Modal Click bool

    Close picker on click on the background if the modal option enabled.

Show() Method Parameters

All parameters are optional.
  • defaultValue TValue

    Default value.</param>

  • onSelect Action<TValue>

    Callback with selected value.

  • onCancel Action

    Callback when picker closed without any value selected.

  • modalSprite Sprite

    Background image for the modal dialog.
    Can be changed with SetModal().
  • modalColor Color?

    Background color for the modal dialog.
    Can be changed with SetModal().
  • canvas Canvas

    Canvas. Can be changed with SetCanvas().

ShowAsync() Method Parameters

All parameters are optional.
Returns TPicker.Result with selected value or success mark.
  • defaultValue TValue

    Default value.</param>

  • modalSprite Sprite

    Background image for the modal dialog.
    Can be changed with SetModal().
  • modalColor Color?

    Background color for the modal dialog.
    Can be changed with SetModal().
  • canvas Canvas

    Canvas. Can be changed with SetCanvas().

TPicker.Result Fields

  • Value TValue

    Selected value or a default value if nothing is selected.

  • Success bool

    true if the value was selected; false if the picker was canceled or closed without a value chosen.

Example

namespace UIWidgets.Examples
{
        using UIWidgets;
        using UnityEngine;

        public class PickerIntTest : MonoBehaviour
        {
                [SerializeField]
                PickerInt PickerTemplate;

                int currentValue = 0;

                async public void TestAsync()
                {
                        // create picker instance
                        var picker = PickerTemplate.Clone();

                        // copy values
                        picker.ListView.DataSource = PickerTemplate.ListView.DataSource;

                        // show picker
                        var value = await picker.ShowAsync(currentValue);
                        if (value.Success)
                        {
                                currentValue = value;
                                Debug.Log("value: " + value);
                        }
                        else
                        {
                                Debug.Log("canceled");
                        }
                }

                /// <summary>
                /// Show picker with callbacks and log selected value.
                /// </summary>
                public void TestCallbacks()
                {
                        // create picker instance
                        var picker = PickerTemplate.Clone();

                        // copy values
                        picker.ListView.DataSource = PickerTemplate.ListView.DataSource;

                        // show picker
                        picker.Show(currentValue, ValueSelected, Canceled);
                }

                void ValueSelected(int value)
                {
                        currentValue = value;
                        Debug.Log(string.Format("value: {0}", value));
                }

                void Canceled()
                {
                        Debug.Log("canceled");
                }
        }
}