DatePickerElement.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Bitsplash.DatePicker
  5. {
  6. /// <summary>
  7. /// base class for date picker elements. They included buttons and texts
  8. /// </summary>
  9. public abstract class DatePickerElement : MonoBehaviour
  10. {
  11. [SerializeField]
  12. [HideInInspector]
  13. private bool isOpen;
  14. protected virtual void Start()
  15. {
  16. SetLinkedElements();
  17. }
  18. /// <summary>
  19. /// notifys the date picker element of the DatePickerSettings and DatePickerContent objects that govern it.
  20. /// these objects are used to query and modify the date picker
  21. /// </summary>
  22. void SetLinkedElements()
  23. {
  24. var main = GetComponentInParent<DatePickerSettings>();
  25. if (main == null)
  26. Debug.LogError("Date Picker elements must have a parent GameObject with the behviour DatePickerSettings");
  27. else
  28. {
  29. var content = main.Content;
  30. if (content != null)
  31. {
  32. SetMain(main);
  33. SetContent(content);
  34. content.SettingsChanged -= OnSettingsChanged;
  35. content.SettingsChanged += OnSettingsChanged;
  36. }
  37. }
  38. }
  39. protected virtual void OnSettingsChanged()
  40. {
  41. }
  42. public virtual void OnValidate()
  43. {
  44. if(isActiveAndEnabled)
  45. SetLinkedElements();
  46. }
  47. /// <summary>
  48. /// sets the main DatePickerSettings object assicuated with this script
  49. /// </summary>
  50. /// <param name="main"></param>
  51. protected abstract void SetMain(DatePickerSettings main);
  52. /// <summary>
  53. /// sets the main DatePickerContent object assicuated with this script
  54. /// </summary>
  55. /// <param name="content"></param>
  56. protected abstract void SetContent(DatePickerContent content);
  57. }
  58. }