Community Made Tools

Have you made any useful utilities with Odin?

Login and submit your creations here

DateTime and TimeSpan Drawers

Authored by Frantasad
Shared 03-05-2024

Simple library of drawers for TimeSpan and DateTime with date time picker Get code on Github.

DateTime

// Use serializable class UDateTime to serialize DateTime in Unity Objects
[SerializeField]
private UDateTime Date;

// You can also just show private data
[ShowInInspector]
private DateTime _date;

TimeSpan

// Use serializable class UTimeSpan to serialize TimeSpan in Unity Objects
[SerializeField]
private UTimeSpan _ExampleTime1;

// You can also just show private data
[ShowInInspector]
private UTimeSpan _exampleTime;

// Utilize TimeSpanDrawerSettings attribute to customize your drawer
[TimeSpanDrawerSettings(TimeUnit.Minutes)]
[SerializeField]
private UTimeSpan _ExampleTime2;

[TimeSpanDrawerSettings(TimeUnit.Hours, TimeUnit.Minutes)]
[SerializeField]
private UTimeSpan _ExampleTime3;

[TimeSpanDrawerSettings(TimeUnit.Days, TimeUnit.Days)]
[SerializeField]
private UTimeSpan _ExampleTime4;

TimeSpan Range

// Use TimeSpanRange attribute to visualize range in time, 
// combine with TimeSpanDrawerSettings to get better results
[TimeSpanDrawerSettings(TimeUnit.Minutes)]
[TimeSpanRange("@TimeSpan.FromMinutes(10)")]
[SerializeField]
private UTimeSpan _ExampleTimeRange1;

[TimeSpanDrawerSettings(TimeUnit.Minutes)]
[TimeSpanRange("@TimeSpan.FromMinutes(10)", true)]
[SerializeField]
private UTimeSpan _ExampleTimeRange2;

TimeSpan MinMax

// Use TimeSpanRange on UTimeSpanRange class to create Min-Max variant of range,
// can also be combined with TimeSpanDrawerSettings
[TimeSpanRange("@TimeSpan.FromMinutes(10)")]
[TimeSpanDrawerSettings(TimeUnit.Minutes)]
[SerializeField]
private UTimeSpanRange _ExampleTimeRangeMinMax;


[TimeSpanRange("@TimeSpan.FromMinutes(10)", true)]
[TimeSpanDrawerSettings(TimeUnit.Minutes)]
[SerializeField]
private UTimeSpanRange _ExampleTimeRangeMinMax2;