_xiaofang/xiaofang/Assets/Bitsplash/Modular Date Picker/Base/Script/Elements/MonthTextBox.cs
2024-11-29 16:19:12 +08:00

71 lines
1.6 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace Bitsplash.DatePicker
{
public class MonthTextBox : DatePickerText , IDatePickerSettingsItem
{
[SerializeField]
private string dateFormat = "MMMM, yyyy";
public string DateFormat
{
get { return dateFormat; }
set
{
dateFormat = value;
RefreshText();
}
}
public int Order { get { return 8; } }
public string EditorTitle
{
get { return "Month Text Box - " + gameObject.name; }
}
protected override void SetContent(DatePickerContent content)
{
if (Content != null)
Content.OnDisplayChanged.RemoveListener(DisplayChanged);
base.SetContent(content);
if (Content != null)
{
Content.OnDisplayChanged.AddListener(DisplayChanged);
DisplayChanged();
}
}
void RefreshText()
{
if (Content == null)
return;
try
{
Text = (Content.DisplayDate.ToString(dateFormat));
}
catch (Exception)
{
Debug.LogWarning("Invalid date format for text box - " + DateFormat);
}
}
void DisplayChanged()
{
RefreshText();
}
void OnDestroy()
{
if (Content != null)
Content.OnDisplayChanged.RemoveListener(DisplayChanged);
}
}
}