Beispiel #1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var dayProp = property.FindPropertyRelative("dayNumber");
            var date    = UnityDateOnly.FromDayNumber(dayProp.intValue);

            label = BeginProperty(position, label, property);
            BeginChangeCheck();
            var newDate = GUIControls.DateOnlyField(position, label, date);

            if (EndChangeCheck())
            {
                dayProp.intValue = newDate.DayNumber;
            }
            EndProperty();
        }
Beispiel #2
0
        public static UnityDateOnly DateOnlyField(Rect position, GUIContent label, UnityDateOnly date)
        {
            var controlRect = MultiFieldPrefixLabel(position, label, 3);

            DateOnlyValues[0] = date.Day;
            DateOnlyValues[1] = date.Month;
            DateOnlyValues[2] = date.Year;

            MultiIntField(controlRect, DateTimeLabels, DateOnlyValues);

            DateOnlyValues[2] = Mathf.Clamp(DateOnlyValues[2], DateTime.MinValue.Year, DateTime.MaxValue.Year);
            DateOnlyValues[1] = Mathf.Clamp(DateOnlyValues[1], 1, 12);
            DateOnlyValues[0] = Mathf.Clamp(DateOnlyValues[0], 1,
                                            DateTime.DaysInMonth(DateOnlyValues[2], DateOnlyValues[1]));
            var newDate = new UnityDateOnly(DateOnlyValues[2], DateOnlyValues[1], DateOnlyValues[0]);

            return(newDate);
        }