Class TimePicker
A component for picking a time of day with spinner columns.
Implements
Inherited Members
Namespace: Unity.AppUI.UI
Assembly: Unity.AppUI.dll
Syntax
[UxmlElement]
public class TimePicker : BaseVisualElement, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, IContextOverrideElement, IAdditionalDataHolder, INotifyValueChanged<TimeSpan>
Remarks
The TimePicker holds the shared time value and lays out one TimePickerColumn per segment. By default it builds hours and minutes columns, adding a seconds column when showSeconds is set and an AM/PM column when hour12 is set.
The default columns are only built when the picker has none of its own, so a UXML author can reorder or subset them by declaring TimePickerColumn children explicitly. Once you do, the picker stops managing the column set and leaves your layout alone.
The value is a TimeSpan time of day, normalized into [00:00:00, 24:00:00), the same
model TimeField uses. Each column steps its own segment and wraps inside that
segment's unit, so minutes rolling over from 59 to 00 never carry into the hour.
Examples
Basic usage in UXML:
<UXML xmlns:appui="Unity.AppUI.UI">
<appui:TimePicker value="14:30:00" />
</UXML>
A custom column layout, minutes first and no hours:
<UXML xmlns:appui="Unity.AppUI.UI">
<appui:TimePicker minute-step="5">
<appui:TimePickerColumn segment="Minutes" />
<appui:TimePickerColumn segment="Seconds" />
</appui:TimePicker>
</UXML>
Creating a 12-hour picker in C#:
var picker = new TimePicker
{
hour12 = true,
showSeconds = true,
value = new TimeSpan(14, 30, 0)
};
picker.RegisterValueChangedCallback(evt => {
Debug.Log($"Picked time: ");
});
Constructors
TimePicker()
Default constructor.
Declaration
public TimePicker()
Fields
separatorUssClassName
The TimePicker segment separator styling class.
Declaration
public static readonly string separatorUssClassName
Field Value
| Type | Description |
|---|---|
| string |
ussClassName
The TimePicker main styling class.
Declaration
public static readonly string ussClassName
Field Value
| Type | Description |
|---|---|
| string |
Properties
hour12
Whether the picker uses a 12-hour clock, adding an AM/PM column. Defaults to false.
Declaration
[CreateProperty]
[UxmlAttribute("hour12")]
public bool hour12 { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
minuteStep
The number of minutes stepped per spinner click. Defaults to 1. Values below 1 are clamped to 1.
Declaration
[CreateProperty]
[UxmlAttribute("minute-step")]
public int minuteStep { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
showSeconds
Whether the picker shows a seconds column. Defaults to false.
Declaration
[CreateProperty]
[UxmlAttribute("show-seconds")]
public bool showSeconds { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
value
The current value of the picker, a time of day in [00:00:00, 24:00:00).
Declaration
[CreateProperty]
[UxmlAttribute]
public TimeSpan value { get; set; }
Property Value
| Type | Description |
|---|---|
| TimeSpan |
Methods
SetValueWithoutNotify(TimeSpan)
Sets the value of the picker without sending a change event.
Declaration
public void SetValueWithoutNotify(TimeSpan newValue)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSpan | newValue | The new value. It is normalized into |
StepSegment(TimeSegment, int)
Steps a single segment of the value, wrapping inside that segment's own unit.
Declaration
public void StepSegment(TimeSegment segment, int delta)
Parameters
| Type | Name | Description |
|---|---|---|
| TimeSegment | segment | The segment to step. |
| int | delta | The number of steps, negative to step down. |