| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- namespace JC.Unity.Picker
- {
- /// <summary>
- /// 日期选择组
- /// </summary>
- public class DatePickerGroup : MonoBehaviour
- {
- public DateTime minDate, maxDate, selectDate;
- public List<DatePicker> datePickerList;
- [SerializeField] Button btnClose;
- [SerializeField] Button btnEnter;
- public Action<DatePickerGroup> onEnter;
- void Awake()
- {
- minDate = new DateTime(1950, 1, 1, 0, 0, 0);
- maxDate = DateTime.Now;
- selectDate = new DateTime(2000, 1, 1, 0, 0, 0);
- }
- void Start()
- {
- Init();
- if (btnClose) {
- btnClose.onClick.AddListener(() => {
- Destroy(transform.GetComponentInParent<Canvas>().gameObject);
- });
- }
- if (btnEnter) {
- btnEnter.onClick.AddListener(() => {
- Destroy(transform.GetComponentInParent<Canvas>().gameObject);
- onEnter?.Invoke(this);
- });
- }
- }
- public void Init() {
- for (int i = 0; i < datePickerList.Count; i++) {
- datePickerList[i].myGroup = this;
- datePickerList[i].Init();
- }
- int languageID = PlayerPrefs.GetInt("Language", 0);
- string title = languageID == 0 ? "日期选择" : "Date Select";
- string title0 = languageID == 0 ? "年" : "Year";
- string title1 = languageID == 0 ? "月" : "Month";
- string title2 = languageID == 0 ? "日" : "Day";
- transform.Find("TopBar/Title").GetComponent<Text>().text = title;
- transform.Find("TitleBG/Item").GetComponentInChildren<Text>().text = title0;
- transform.Find("TitleBG/Item (1)").GetComponentInChildren<Text>().text = title1;
- transform.Find("TitleBG/Item (2)").GetComponentInChildren<Text>().text = title2;
- }
- public void onDateUpdate() {
- foreach (var item in datePickerList) {
- item.Refresh();
- }
- // Debug.Log("当前选择日期:" + selectDate.ToString("yyyy年MM月dd日 HH : mm : ss"));
- }
- public string GetSelectDateStr() {
- return selectDate.ToString("yyyy-MM-dd");
- }
- private float _height = -1;
- public float GetHeight() {
- if (_height == -1) {
- _height = transform.GetComponent<RectTransform>().sizeDelta.y;
- }
- return _height;
- }
- }
- }
|