Created
February 19, 2024 08:38
-
-
Save mikejurka/ce48ea04b30a8f57f8217c1786bc5974 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using UnityEngine; | |
using System; | |
using System.Globalization; | |
#if UNITY_EDITOR | |
using Unity.VisualScripting; | |
using UnityEditor; | |
#endif | |
namespace BuddyBlitz | |
{ | |
[CreateAssetMenu(fileName = "EventsDatabase", menuName = "Buddy Blitz/New Events Database", order = 4)] | |
public class EventsDatabase : ScriptableObject | |
{ | |
[Serializable] | |
public class Event | |
{ | |
public string name; | |
public string startDateString; | |
public string endDateString; | |
public DateTime startDate; | |
public DateTime endDate; | |
} | |
[SerializeField] private Event[] events; | |
public void Awake() | |
{ | |
DateTime result; | |
foreach (var ev in events) | |
{ | |
if (DateTime.TryParseExact(ev.startDateString, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out result)) | |
{ | |
ev.startDate = result; | |
} | |
if (DateTime.TryParseExact(ev.endDateString, "yyyy-MM-dd", CultureInfo.InvariantCulture, DateTimeStyles.None, out result)) | |
{ | |
ev.endDate = result; | |
} | |
} | |
} | |
public Event GetActiveEvent() | |
{ | |
var now = DateTime.Now; | |
foreach (Event ev in events) | |
{ | |
if (now > ev.startDate && now < ev.endDate) | |
{ | |
return ev; | |
} | |
} | |
return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment