12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- namespace Devdog.SciFiDesign.UI
- {
- public class SetDateTime : MonoBehaviour
- {
- [SerializeField]
- private Text _textTimeHour;
- [SerializeField]
- private Text _textTimeMinute;
- [SerializeField]
- private Text _textColon;
- [SerializeField]
- private Text _textDay;
- public bool blinkColon = false;
- public float blinkColonInterval = 0.5f;
- protected void Start()
- {
- InvokeRepeating("UpdateTime", 0f, 60f);
- if (blinkColon)
- {
- InvokeRepeating("UpdateColon", 0f, blinkColonInterval);
- }
- }
- protected void UpdateTime()
- {
- var n = System.DateTime.Now;
- if (_textTimeHour != null)
- {
- _textTimeHour.text = n.Hour < 10 ? "0" + n.Hour : n.Hour.ToString();
- }
- if (_textTimeHour != null)
- {
- _textTimeMinute.text = n.Minute < 10 ? "0" + n.Minute : n.Minute.ToString();
- }
- if (_textDay != null)
- {
- _textDay.text = n.DayOfWeek.ToString().ToUpper();
- }
- }
- protected void UpdateColon()
- {
- if (string.IsNullOrEmpty(_textColon.text))
- {
- _textColon.text = ":";
- }
- else
- {
- _textColon.text = "";
- }
- }
- }
- }
|