/*
* JacobKay --20220903
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using ZTools;
///
/// 使用示例
///
public class ZCalendarDemo : MonoBehaviour
{
public ZCalendar zCalendar;
///
///
///
public Button btnClose;
///
///
///
public Button btnShow;
///
/// 定义一个公共事件供其他脚本调用
///
public event System.Action onConfirm;
///
/// 日期输入框
///
private InputField inputMain;
///
/// 日期
///
private string inputDate;
///
///
///
public Button btnHide;
// Start is called before the first frame update
void Start()
{
zCalendar.UpdateDateEvent += ZCalendar_UpdateDateEvent;
zCalendar.ChoiceDayEvent += ZCalendar_ChoiceDayEvent;
zCalendar.RangeTimeEvent += ZCalendar_RangeTimeEvent;
zCalendar.CompleteEvent += ZCalendar_CompleteEvent;
//zCalendar.Init();
//zCalendar.Init(System.DateTime.Now);
//zCalendar.Init("2022-02-02");
//zCalendar.Show();
//zCalendar.Hide();
btnClose.onClick.AddListener(()=> {
zCalendar.Hide();
zCalendar.Init();
});
btnShow.onClick.AddListener(()=> {
if (inputMain != null)
{
inputMain.text = inputDate;
zCalendar.Hide();
zCalendar.Init();
}
});
btnHide.onClick.AddListener(()=> {
zCalendar.Hide();
zCalendar.Init();
});
}
///
/// 输入框
///
///
public void show(InputField inputField)
{
inputMain=inputField;
}
///
/// 加载结束
///
private void ZCalendar_CompleteEvent()
{
Debug.Log("ZCalendar加载结束");
if (null != zCalendar.CrtTime)
{
Debug.Log($"当前时间{zCalendar.CrtTime.Day}");
}
}
///
/// 区间时间
///
///
///
private void ZCalendar_RangeTimeEvent(ZCalendarDayItem arg1, ZCalendarDayItem arg2)
{
Debug.Log($"选择的时间区间:{arg1.Day}到{arg2.Day}");
}
///
/// 获取选择的日期
///
///
private void ZCalendar_ChoiceDayEvent(ZCalendarDayItem obj)
{
string date = obj.Year + "/" + obj.Month.ToString("00") + "/" + obj.Day.ToString("00");
Debug.Log($"选择的日期:{date}");
inputDate = date;
ZCalendarModel zCalendarModel = this.GetComponent();
if (zCalendarModel)
{
zCalendarModel.WriteDate(date);
}
}
///
/// 切换月份时,可拿到每一天的item对象
///
///
private void ZCalendar_UpdateDateEvent(ZCalendarDayItem obj)
{
//Debug.Log($"加载日期:{obj.Day}");
}
private void OnDestroy()
{
zCalendar.UpdateDateEvent -= ZCalendar_UpdateDateEvent;
zCalendar.ChoiceDayEvent -= ZCalendar_ChoiceDayEvent;
zCalendar.RangeTimeEvent -= ZCalendar_RangeTimeEvent;
zCalendar.CompleteEvent -= ZCalendar_CompleteEvent;
}
}