Pickers
Base class for the custom pickers.
Options
Close Button
ButtonButton to close picker.
Hide on Modal Click
boolClose picker on click on the background if the
modaloption enabled.
Show() Method Parameters
All parameters are optional.
defaultValue
TValueDefault value.</param>
onSelect
Action<TValue>Callback with selected value.
onCancel
ActionCallback when picker closed without any value selected.
modalSprite
SpriteBackground image for the modal dialog.Can be changed withSetModal().modalColor
Color?Background color for the modal dialog.Can be changed withSetModal().canvas
CanvasCanvas. Can be changed with
SetCanvas().
ShowAsync() Method Parameters
All parameters are optional.
Returns
TPicker.Result with selected value or success mark.defaultValue
TValueDefault value.</param>
modalSprite
SpriteBackground image for the modal dialog.Can be changed withSetModal().modalColor
Color?Background color for the modal dialog.Can be changed withSetModal().canvas
CanvasCanvas. Can be changed with
SetCanvas().
TPicker.Result Fields
Value
TValueSelected value or a default value if nothing is selected.
Success
booltrueif the value was selected;falseif 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");
}
}
}