mirror of
https://github.com/DerTyp7/example-top-down-unity.git
synced 2025-10-30 12:57:08 +01:00
open calendar with "c"
This commit is contained in:
61
Assets/Scripts/Calendar/Calendar.cs
Normal file
61
Assets/Scripts/Calendar/Calendar.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class Calendar : MonoBehaviour
|
||||
{
|
||||
TimeManager timeManager;
|
||||
Image prevImage;
|
||||
Transform daysTransform;
|
||||
|
||||
[SerializeField]
|
||||
Color currentDayColor;
|
||||
Color originDayColor;
|
||||
private void Start()
|
||||
{
|
||||
daysTransform = transform.Find("Days");
|
||||
timeManager = GameObject.Find("GameManager").GetComponent<TimeManager>();
|
||||
originDayColor = daysTransform.Find("1").gameObject.GetComponent<Image>().color;
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if(gameObject.activeSelf)
|
||||
RefreshCalendar();
|
||||
}
|
||||
|
||||
void RefreshCalendar()
|
||||
{
|
||||
DateTime dateTime = timeManager.GetDateTime();
|
||||
|
||||
int counter;
|
||||
|
||||
int daysInMonth = DateTime.DaysInMonth(dateTime.Year, dateTime.Month);
|
||||
|
||||
counter = 1;
|
||||
while (counter <= 31)
|
||||
{
|
||||
if (counter >= daysInMonth + 1)
|
||||
{
|
||||
daysTransform.Find(counter.ToString()).gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
daysTransform.Find(counter.ToString()).gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
counter++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (prevImage != daysTransform.Find(dateTime.Day.ToString()).gameObject.GetComponent<Image>())
|
||||
{
|
||||
if (prevImage != null)
|
||||
prevImage.color = originDayColor;
|
||||
|
||||
daysTransform.Find(dateTime.Day.ToString()).gameObject.GetComponent<Image>().color = currentDayColor;
|
||||
prevImage = daysTransform.Find(dateTime.Day.ToString()).gameObject.GetComponent<Image>();
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Calendar/Calendar.cs.meta
Normal file
11
Assets/Scripts/Calendar/Calendar.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96c62da3e09569940847187705433290
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user