DatePickerGroup.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace JC.Unity.Picker
  6. {
  7. /// <summary>
  8. /// 日期选择组
  9. /// </summary>
  10. public class DatePickerGroup : MonoBehaviour
  11. {
  12. public DateTime minDate, maxDate, selectDate;
  13. public List<DatePicker> datePickerList;
  14. [SerializeField] Button btnClose;
  15. [SerializeField] Button btnEnter;
  16. public Action<DatePickerGroup> onEnter;
  17. void Awake()
  18. {
  19. minDate = new DateTime(1950, 1, 1, 0, 0, 0);
  20. maxDate = DateTime.Now;
  21. selectDate = new DateTime(2000, 1, 1, 0, 0, 0);
  22. Init();
  23. }
  24. void Start()
  25. {
  26. if (btnClose) {
  27. btnClose.onClick.AddListener(() => {
  28. Destroy(transform.GetComponentInParent<Canvas>().gameObject);
  29. });
  30. }
  31. if (btnEnter) {
  32. btnEnter.onClick.AddListener(() => {
  33. Destroy(transform.GetComponentInParent<Canvas>().gameObject);
  34. onEnter?.Invoke(this);
  35. });
  36. }
  37. }
  38. public void Init() {
  39. for (int i = 0; i < datePickerList.Count; i++) {
  40. datePickerList[i].myGroup = this;
  41. datePickerList[i].Init();
  42. }
  43. }
  44. public void onDateUpdate() {
  45. foreach (var item in datePickerList) {
  46. item.Refresh();
  47. }
  48. // Debug.Log("当前选择日期:" + selectDate.ToString("yyyy年MM月dd日 HH : mm : ss"));
  49. }
  50. public string GetSelectDateStr() {
  51. return selectDate.ToString("yyyy-MM-dd");
  52. }
  53. private float _height = -1;
  54. public float GetHeight() {
  55. if (_height == -1) {
  56. _height = transform.GetComponent<RectTransform>().sizeDelta.y;
  57. }
  58. return _height;
  59. }
  60. }
  61. }