mirror of
https://github.com/DerTyp7/example-top-down-unity.git
synced 2025-10-30 04:47:09 +01:00
open calendar with "c"
This commit is contained in:
8
Assets/Scripts/Calendar.meta
Normal file
8
Assets/Scripts/Calendar.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 419a6c97c6863fe4bba52001e71d1df1
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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:
|
||||
@@ -5,7 +5,14 @@ using UnityEngine;
|
||||
// Handles the player input, such as interactions
|
||||
public class PlayerController : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
GameObject calendar;
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetButtonDown("Calendar") && calendar != null)
|
||||
{
|
||||
calendar.SetActive(!calendar.activeSelf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class TimeManager : MonoBehaviour
|
||||
@@ -34,13 +35,10 @@ public class TimeManager : MonoBehaviour
|
||||
{
|
||||
dateTime = dateTime.AddMinutes(minutesPerInterval);
|
||||
CheckPartsOfDay();
|
||||
Debug.Log(GetTime());
|
||||
}
|
||||
|
||||
void CheckPartsOfDay()
|
||||
{
|
||||
Debug.Log(dateTime.Hour);
|
||||
|
||||
if (dateTime.Hour >= 22)
|
||||
partOfDay = PartOfDay.NIGHT;
|
||||
else if(dateTime.Hour < 6)
|
||||
@@ -52,6 +50,4 @@ public class TimeManager : MonoBehaviour
|
||||
else if (dateTime.Hour >= 17 && dateTime.Hour < 22)
|
||||
partOfDay = PartOfDay.EVENING;
|
||||
}
|
||||
|
||||
// For Plant growth maybe add a List<GameObject/Script> where those plants can register themselves and every "TimeUp()" they get checked by the TimeManager
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user