DisplayTutorial.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace Bitsplash.DatePicker.Tutorials
  7. {
  8. public class DisplayTutorial : MonoBehaviour
  9. {
  10. public DatePickerSettings Picker;
  11. public Text YearText;
  12. public Text InfoText;
  13. // Start is called before the first frame update
  14. void Start()
  15. {
  16. if(InfoText != null)
  17. {
  18. InfoText.text = Picker.Content.DisplayDate.ToString("MM-yyyy"); // shows the display date of the picker
  19. }
  20. Picker.Content.OnDisplayChanged.AddListener(DisplayChanged); // triggred when the used navigates the date picker display
  21. }
  22. void DisplayChanged()
  23. {
  24. InfoText.text = Picker.Content.DisplayDate.ToString("MM-yyyy"); // shows the display date of the picker
  25. }
  26. public void ModifyYear()
  27. {
  28. try
  29. {
  30. int newYear = int.Parse(YearText.text);
  31. if (newYear < 1800 && newYear > 2025)
  32. Debug.Log("Invalid year");
  33. else
  34. {
  35. Picker.Content.SetYear(newYear); // set the display year for the datepicker
  36. }
  37. }
  38. catch(Exception)
  39. {
  40. }
  41. }
  42. // Update is called once per frame
  43. void Update()
  44. {
  45. }
  46. }
  47. }