/// <summary> Creates a new instance of the drawer or returns a reusable instance from the pool. </summary> /// <param name="parent"> The parent drawer of the created drawer. Can be null. </param> /// <param name="label"> The prefix label. </param> /// <param name="setReadOnly"> True if control should be read only. </param> /// <returns> The instance, ready to be used. </returns> public static CustomDataSetDrawer Create(IParentDrawer parent, GUIContent label, bool setReadOnly) { CustomDataSetDrawer result; if (!DrawerPool.TryGet(out result)) { result = new CustomDataSetDrawer(); } result.Setup(null, typeof(object[]), null, parent, label, setReadOnly); result.LateSetup(); return(result); }
/// <inheritdoc /> protected override void DoBuildMembers() { bool readOnly = memberInfo != null && !memberInfo.CanWrite; if (readOnly) { DrawerArrayPool.Resize(ref members, 0); } else { DrawerArrayPool.Resize(ref members, 2); var min = TimeSpan.MinValue; var max = TimeSpan.MaxValue; var group = CustomDataSetDrawer.Create(this, GUIContentPool.Create("Days / Hours"), ReadOnly); { var groupMembers = DrawerArrayPool.Create(2); var groupMember = ClampedIntDrawer.Create(Days, min.Days, max.Days, null, group, GUIContentPool.Create("D"), ReadOnly); groupMember.OnValueChanged += SetDays; groupMembers[0] = groupMember; groupMember = ClampedIntDrawer.Create(Hours, MinHours, MaxHours, null, group, GUIContentPool.Create("H"), ReadOnly); groupMember.OnValueChanged += SetHours; groupMember.OverrideValidateValue = ValidateHours; groupMembers[1] = groupMember; group.SetMembers(groupMembers, true); members[0] = group; } group = CustomDataSetDrawer.Create(this, GUIContentPool.Create("Minutes / Seconds"), ReadOnly); { var groupMembers = DrawerArrayPool.Create(2); var groupMember = ClampedIntDrawer.Create(Minutes, MinMinutes, MaxMinutes, null, group, GUIContentPool.Create("M"), ReadOnly); groupMember.OnValueChanged += SetMinutes; groupMember.OverrideValidateValue = ValidateMinutes; groupMembers[0] = groupMember; var secondsMember = ClampedFloatDrawer.Create(SecondsWithFractions, MinSeconds, MaxSeconds, null, group, GUIContentPool.Create("S"), ReadOnly); secondsMember.OnValueChanged += SetSeconds; secondsMember.OverrideValidateValue = ValidateSeconds; groupMembers[1] = secondsMember; group.SetMembers(groupMembers, true); members[1] = group; } } }
/// <inheritdoc /> protected override void DoBuildMembers() { if (ReadOnly) { DrawerArrayPool.Resize(ref members, 0); } else { DrawerArrayPool.Resize(ref members, 2); var value = Value; asString = StringUtils.TimeToString(value); int year = value.Year; int month = value.Month; int day = value.Day; int hour = value.Hour; int minute = value.Minute; float second = value.Second + value.Millisecond * 0.001f; var min = DateTime.MinValue; var max = DateTime.MaxValue; var group = CustomDataSetDrawer.Create(this, GUIContentPool.Create("Date"), false); { var groupMembers = DrawerArrayPool.Create(3); var groupMember = ClampedIntDrawer.Create(year, min.Year, max.Year, null, group, GUIContentPool.Create("Y"), false); groupMember.OnValueChanged += SetYear; groupMember.OverrideValidateValue = ValidateYear; groupMember.overrideReset = ResetToOne; groupMembers[YearMemberIndex] = groupMember; groupMember = ClampedIntDrawer.Create(month, min.Month, max.Month, null, group, GUIContentPool.Create("M"), false); groupMember.OnValueChanged += SetMonth; groupMember.OverrideValidateValue = ValidateMonth; groupMember.overrideReset = ResetToOne; groupMembers[MonthMemberIndex] = groupMember; groupMember = ClampedIntDrawer.Create(day, min.Day, max.Day, null, group, GUIContentPool.Create("D"), false); groupMember.OnValueChanged += SetDay; groupMember.OverrideValidateValue = ValidateDay; groupMember.overrideReset = ResetToOne; groupMembers[DayMemberIndex] = groupMember; group.SetMembers(groupMembers, true); members[0] = group; } group = CustomDataSetDrawer.Create(this, GUIContentPool.Create("Time"), false); { var groupMembers = DrawerArrayPool.Create(3); var groupMember = ClampedIntDrawer.Create(hour, 0, 23, null, group, GUIContentPool.Create("H"), false); groupMember.OnValueChanged += SetHour; groupMember.OverrideValidateValue = ValidateHour; groupMembers[HourMemberIndex] = groupMember; groupMember = ClampedIntDrawer.Create(minute, 0, 59, null, group, GUIContentPool.Create("M"), false); groupMember.OnValueChanged += SetMinute; groupMember.OverrideValidateValue = ValidateMinute; groupMembers[MinuteMemberIndex] = groupMember; var secondsMember = ClampedFloatDrawer.Create(second, 0f, 60f - float.Epsilon, null, group, GUIContentPool.Create("S"), false); secondsMember.OnValueChanged += SetSeconds; secondsMember.OverrideValidateValue = ValidateSecond; groupMembers[SecondMemberIndex] = secondsMember; group.SetMembers(groupMembers, true); members[1] = group; } } }