using UnityEngine;
using System.Collections;
using System;
using UnityEngine.UI;
using System.Collections.Generic;
public enum CalendarType
{
Day,
Month,
Year
}
public class Calendar : MonoBehaviour {
[Header("点击日期是是否默认关掉Calendar面板")]
public bool OnClickDayIsDefaultClose = false;
//年月日 点击回调
public Action<DateTime> OnClickDay;
public Action<DateTime> OnClickMonth;
public Action<DateTime> OnClickYear;
private DateTime m_selectDT = DateTime.Today;
private CalendarType m_calendarType = CalendarType.Day;
//当前选择的日期
private DateTime u_selectDT = DateTime.Today;
private UIButton btnLast = null;
private UIButton btnNext = null;
private UIButton btnTime = null;
private UILabel textTime = null;
private GameObject dayContent = null;
private GameObject weekContent = null;
private GameObject monthContent = null;
private UIGrid dayGrid = null;
private UIGrid weekGrid = null;
private UIGrid monthGrid = null;
private readonly List<DMY> _daysPool = new List<DMY>();
//private readonly List<GameObject> _daysPool = new List<GameObject>();
private readonly List<DMY> _monthYearPool = new List<DMY>();
private readonly CalendarData m_calendarData = new CalendarData();
private void Awake()
{
btnLast = transform.Find("Title/BtnLast").GetComponent<UIButton>();
btnNext = transform.Find("Title/BtnNext").GetComponent<UIButton>();
btnTime = transform.Find("Title/BtnTime").GetComponent<UIButton>();
textTime = transform.Find("Title/BtnTime").GetComponent<UILabel>();
dayContent = transform.Find("Date/Days").gameObject;
weekContent = transform.Find("Date/Weeks").gameObject;
monthContent = transform.Find("Date/Months").gameObject;
var dayPrefab = Resources.Load("CalendarPrefabs/DayTemplate") as GameObject;
var weekPrefab = Resources.Load("CalendarPrefabs/WeekTemplate") as GameObject;
var monthPrefab = Resources.Load("CalendarPrefabs/MonthTemplate") as GameObject;
dayGrid = dayContent.GetComponent<UIGrid>();
weekGrid = weekContent.GetComponent<UIGrid>();
monthGrid = monthContent.GetComponent<UIGrid>();
DayPoolCreate(dayPrefab, dayContent);
WeekPoolCreate(weekPrefab, weekContent);
MonthPoolCreate(monthPrefab, monthContent);
}
private void Start()
{
UIEventListener.Get(btnLast.gameObject).onClick += OnClickBtnLast;
UIEventListener.Get(btnTime.gameObject).onClick += OnClickBtnTime;
UIEventListener.Get(btnNext.gameObject).onClick += OnClickBtnNext;
monthContent.gameObject.SetActive(false);
Refresh();
}
private void OnClickBtnLast(GameObject go)
{
if (m_calendarType == CalendarType.Day)
m_selectDT = m_selectDT.AddMonths(-1);
else if (m_calendarType == Calenda