Unity中日历面板

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值