Files
peng-zhihui 06ec2e469e Released.
2022-03-13 06:31:07 +08:00

103 lines
2.3 KiB
C#

namespace UIWidgets.Examples
{
using System;
using UIWidgets;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// Test TimePicker.
/// </summary>
public class TestTimePicker : MonoBehaviour, IUpgradeable
{
/// <summary>
/// DatePicker template.
/// </summary>
[SerializeField]
protected TimePicker PickerTemplate;
/// <summary>
/// Text component to display selected value.
/// </summary>
[SerializeField]
[HideInInspector]
[Obsolete("Replaced with InfoAdapter.")]
protected Text Info;
/// <summary>
/// Text component to display selected value.
/// </summary>
[SerializeField]
protected TextAdapter InfoAdapter;
TimeSpan currentValue = DateTime.Now.TimeOfDay;
/// <summary>
/// Open picker and log selected value.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Required")]
public void Test()
{
// create picker from template
var picker = PickerTemplate.Clone();
// show picker
picker.Show(currentValue, ValueSelected, Canceled);
}
void ValueSelected(TimeSpan value)
{
currentValue = value;
Debug.Log(string.Format("value: {0}", value.ToString()));
}
void Canceled()
{
Debug.Log("canceled");
}
/// <summary>
/// Open picker and display selected value.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "HAA0603:Delegate allocation from a method group", Justification = "Required")]
public void TestShow()
{
// create picker from template
var picker = PickerTemplate.Clone();
// show picker
picker.Show(currentValue, ShowValueSelected, ShowCanceled);
}
void ShowValueSelected(TimeSpan value)
{
currentValue = value;
InfoAdapter.text = string.Format("Value: {0}", value.ToString());
}
void ShowCanceled()
{
InfoAdapter.text = "Canceled";
}
/// <summary>
/// Upgrade this instance.
/// </summary>
public virtual void Upgrade()
{
#pragma warning disable 0612, 0618
Utilities.GetOrAddComponent(Info, ref InfoAdapter);
#pragma warning restore 0612, 0618
}
#if UNITY_EDITOR
/// <summary>
/// Validate this instance.
/// </summary>
protected virtual void OnValidate()
{
Compatibility.Upgrade(this);
}
#endif
}
}