Ok, i know that i can create a custom inspector for a specific component, but whan i mean here i slightly different.
In a component i used a public variable of type System.TimeSpan but it isn’t displayed in the inspector, my first taught is that unity have inspector defined for the commonly used variable type, so i made a custom inspector for this particular component, but: is it possibile to tell unity once for all that all the variable of a certain type has to be displayed in a custom defined way in the inspector without re-implementing it in every inspector?
As @HarshadK said you can make your own propertydrawer. And yes the serialization is something you have to keep in mind.
I mean if you have a component with a DateTime field, it usually wouldn’t be useful to be able to edit its value in inspector if you don’t serialize the the results to be used by your game. Unity can only serialize a limited amount of types automatically for you and those types already have a propertydrawer.
So what you can do is make your own class that stores a DateTime as long using its Ticks
[Serializable]
public class SerializedDateTime {
[SerializeField]
private long rawTicks;
public static explicit operator DateTime(SerializedDateTime sdt) {
return new DateTime(sdt.rawTicks);
}
}
Then make a PropertyDrawer that has for example int fields for year, month and day and have the drawer create a DateTime based on them whenever they change. Then have the drawer set the rawValue of the SerializedDateTime object it edits to the value of DateTime.Ticks
Then you can use SerializedDateTime as the type whenever you need to store a DateTime in a prefab for example. You can also make the cast operator implicit so you dont have to put (DateTime) in front of every usage, or keep it to avoid mixups