| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- /// <summary>
- /// 日期选择组
- /// </summary>
- public class DatePickerGroupNew : MonoBehaviour
- {
- /// <summary>
- /// 最小日期和最大日期
- /// </summary>
- public DateTime _minDate, _maxDate;
- /// <summary>
- /// 选择的日期(年月日时分秒)
- /// </summary>
- public DateTime _selectDate;
- /// <summary>
- /// 时间选择器列表
- /// </summary>
- public List<DatePickerNew> _datePickerList;
- /// <summary>
- /// 当选择日期的委托事件
- /// </summary>
- public event OnDateUpdate _OnDateUpdate;
- public static DateTime _selectTime;
- [SerializeField] Button btnClose;
- [SerializeField] Button btnEnter;
- public Action<DatePickerGroupNew> onEnter;
- void Awake()
- {
- //设置最大最小日期
- _minDate = new DateTime(1950, 1, 1, 0, 0, 0);
- _maxDate = new DateTime(2060, 1, 1, 0, 0, 0);
- Init();
- if (btnClose)
- {
- btnClose.onClick.AddListener(() => {
- Destroy(transform.GetComponentInParent<Canvas>().gameObject);
- });
- }
- if (btnEnter)
- {
- btnEnter.onClick.AddListener(() => {
- Destroy(transform.GetComponentInParent<Canvas>().gameObject);
- onEnter?.Invoke(this);
- });
- }
- }
- private void Update()
- {
- }
- public void Init(DateTime dt)
- {
- _selectDate = dt;
- for (int i = 0; i < _datePickerList.Count; i++)
- {
- _datePickerList[i].myGroup = this;
- _datePickerList[i].Init();
- _datePickerList[i]._onDateUpdate += onDateUpdate;
- }
- }
- public void Init()
- {
- _selectDate = new DateTime(1995, 1, 1, 0, 0, 0); //DateTime.Now;
- for (int i = 0; i < _datePickerList.Count; i++)
- {
- _datePickerList[i].myGroup = this;
- _datePickerList[i].Init();
- _datePickerList[i]._onDateUpdate += onDateUpdate;
- }
- 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("ViewPort/DatePicker_Year/year").GetComponentInChildren<Text>().text = title0;
- transform.Find("ViewPort/DatePicker_Month/month").GetComponentInChildren<Text>().text = title1;
- transform.Find("ViewPort/DatePicker_Day/day").GetComponentInChildren<Text>().text = title2;
- }
- /// <summary>
- /// 当选择的日期更新
- /// </summary>
- public void onDateUpdate()
- {
- // Debug.Log("当前选择日期:" + _selectDate.ToString("yyyy年MM月dd日 HH : mm : ss"));
- //将选中的时间给_selectTime ,供其他界面调用
- _selectTime = _selectDate;
- for (int i = 0; i < _datePickerList.Count; i++)
- {
- _datePickerList[i].RefreshDateList();
- }
- }
- public string GetSelectDateStr()
- {
- _selectTime = _selectDate;
- return _selectTime.ToString("yyyy-MM-dd");
- }
- }
|