DatePickerGroup.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. }
  23. void Start()
  24. {
  25. Init();
  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. int languageID = PlayerPrefs.GetInt("Language", 0);
  44. string title = languageID == 0 ? "日期选择" : "Date Select";
  45. string title0 = languageID == 0 ? "年" : "Year";
  46. string title1 = languageID == 0 ? "月" : "Month";
  47. string title2 = languageID == 0 ? "日" : "Day";
  48. transform.Find("TopBar/Title").GetComponent<Text>().text = title;
  49. transform.Find("TitleBG/Item").GetComponentInChildren<Text>().text = title0;
  50. transform.Find("TitleBG/Item (1)").GetComponentInChildren<Text>().text = title1;
  51. transform.Find("TitleBG/Item (2)").GetComponentInChildren<Text>().text = title2;
  52. }
  53. public void onDateUpdate() {
  54. foreach (var item in datePickerList) {
  55. item.Refresh();
  56. }
  57. // Debug.Log("当前选择日期:" + selectDate.ToString("yyyy年MM月dd日 HH : mm : ss"));
  58. }
  59. public string GetSelectDateStr() {
  60. return selectDate.ToString("yyyy-MM-dd");
  61. }
  62. private float _height = -1;
  63. public float GetHeight() {
  64. if (_height == -1) {
  65. _height = transform.GetComponent<RectTransform>().sizeDelta.y;
  66. }
  67. return _height;
  68. }
  69. }
  70. }