MonthTextBox.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. namespace Bitsplash.DatePicker
  7. {
  8. public class MonthTextBox : DatePickerText , IDatePickerSettingsItem
  9. {
  10. [SerializeField]
  11. private string dateFormat = "MMMM, yyyy";
  12. public string DateFormat
  13. {
  14. get { return dateFormat; }
  15. set
  16. {
  17. dateFormat = value;
  18. RefreshText();
  19. }
  20. }
  21. public int Order { get { return 8; } }
  22. public string EditorTitle
  23. {
  24. get { return "Month Text Box - " + gameObject.name; }
  25. }
  26. protected override void SetContent(DatePickerContent content)
  27. {
  28. if (Content != null)
  29. Content.OnDisplayChanged.RemoveListener(DisplayChanged);
  30. base.SetContent(content);
  31. if (Content != null)
  32. {
  33. Content.OnDisplayChanged.AddListener(DisplayChanged);
  34. DisplayChanged();
  35. }
  36. }
  37. void RefreshText()
  38. {
  39. if (Content == null)
  40. return;
  41. try
  42. {
  43. Text = (Content.DisplayDate.ToString(dateFormat));
  44. }
  45. catch (Exception)
  46. {
  47. Debug.LogWarning("Invalid date format for text box - " + DateFormat);
  48. }
  49. }
  50. void DisplayChanged()
  51. {
  52. RefreshText();
  53. }
  54. void OnDestroy()
  55. {
  56. if (Content != null)
  57. Content.OnDisplayChanged.RemoveListener(DisplayChanged);
  58. }
  59. }
  60. }