namespace UIWidgets.Examples { using System; using UIWidgets; using UnityEngine; using UnityEngine.UI; /// /// Test DateTimePicker. /// public class TestDateTimePicker : MonoBehaviour, IUpgradeable { /// /// DatePicker template. /// [SerializeField] protected DateTimePicker PickerTemplate; /// /// Text component to display selected value. /// [SerializeField] [HideInInspector] [Obsolete("Replaced with InfoAdapter.")] protected Text Info; /// /// Text component to display selected value. /// [SerializeField] protected TextAdapter InfoAdapter; DateTime currentValue = DateTime.Now; /// /// Open picker and log selected value. /// [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(DateTime value) { currentValue = value; Debug.Log(string.Format("value: {0}", value.ToString())); } void Canceled() { Debug.Log("canceled"); } /// /// Open picker and display selected value. /// [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(DateTime value) { currentValue = value; InfoAdapter.text = string.Format("Value: {0}", value.ToString()); } void ShowCanceled() { InfoAdapter.text = "Canceled"; } /// /// Upgrade this instance. /// public virtual void Upgrade() { #pragma warning disable 0612, 0618 Utilities.GetOrAddComponent(Info, ref InfoAdapter); #pragma warning restore 0612, 0618 } #if UNITY_EDITOR /// /// Validate this instance. /// protected virtual void OnValidate() { Compatibility.Upgrade(this); } #endif } }