Tz2/Assets/3rdParty/ZCalendar/Scripts/ZCalendarDemo.cs

135 lines
3.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* JacobKay --20220903
*/
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using ZTools;
/// <summary>
/// 使用示例
/// </summary>
public class ZCalendarDemo : MonoBehaviour
{
public ZCalendar zCalendar;
/// <summary>
///
/// </summary>
public Button btnClose;
/// <summary>
///
/// </summary>
public Button btnShow;
/// <summary>
/// 定义一个公共事件供其他脚本调用
/// </summary>
public event System.Action onConfirm;
/// <summary>
/// 日期输入框
/// </summary>
private InputField inputMain;
/// <summary>
/// 日期
/// </summary>
private string inputDate;
/// <summary>
///
/// </summary>
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();
});
}
/// <summary>
/// 输入框
/// </summary>
/// <param name="inputField"></param>
public void show(InputField inputField)
{
inputMain=inputField;
}
/// <summary>
/// 加载结束
/// </summary>
private void ZCalendar_CompleteEvent()
{
Debug.Log("ZCalendar加载结束");
if (null != zCalendar.CrtTime)
{
Debug.Log($"当前时间{zCalendar.CrtTime.Day}");
}
}
/// <summary>
/// 区间时间
/// </summary>
/// <param name="arg1"></param>
/// <param name="arg2"></param>
private void ZCalendar_RangeTimeEvent(ZCalendarDayItem arg1, ZCalendarDayItem arg2)
{
Debug.Log($"选择的时间区间:{arg1.Day}到{arg2.Day}");
}
/// <summary>
/// 获取选择的日期
/// </summary>
/// <param name="obj"></param>
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<ZCalendarModel>();
if (zCalendarModel)
{
zCalendarModel.WriteDate(date);
}
}
/// <summary>
/// 切换月份时可拿到每一天的item对象
/// </summary>
/// <param name="obj"></param>
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;
}
}