Picker
Base class for the custom pickers.
Note
See Windows Animations for open and closed animations.
Options
AutoFocus
boolSet focus to the last Selectable object in the Picker.
Close Button
ButtonButton to close picker.
Hide on Modal Click
boolClose picker on click on the background if the
modaloption enabled.
Events
OnAnimationStart
UnityEvent<bool>The event is raised before the animation starts.
Arguments: true if opening animation; false if closing animation.
Show() Method Parameters
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
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");
}
}
}