/// <summary> /// Renders the time span data as a float field with a drop-down to select the time unit (milliseconds, seconds, minutes, hours) /// </summary> /// <param name="position">The rectangle depicting the available render area</param> /// <param name="property">The property containing the float value to be displayed as a time span</param> /// <param name="displayTimeSpanAttribute">The attribute that identifies the float as a time span value</param> /// <returns>A rectangle depicting the remaining available area</returns> protected virtual Rect DisplayTimeSpanWithSingleUnit(Rect position, SerializedProperty property, DisplayTimeSpanAttribute displayTimeSpanAttribute) { TimeSpan propertyTimeSpanValue = displayTimeSpanAttribute.UnderlyingValueType.GetTimeSpanValue(property.floatValue); float columnSpacing = 1f; float columnWidth = (position.width * 0.5f) - columnSpacing; Rect valueRect = new Rect(position); valueRect.width = columnWidth; valueRect.height = EditorGUIUtility.singleLineHeight; Rect unitRect = new Rect(valueRect); unitRect.x = valueRect.xMax + columnSpacing; TimeIntervalType timeSpanUnit = displayTimeSpanAttribute.UnderlyingValueType; EditorGUI.LabelField(unitRect, timeSpanUnit.ToString()); float currentValue = timeSpanUnit.GetFloatValue(propertyTimeSpanValue); currentValue = Mathf.Abs(EditorGUI.FloatField(valueRect, currentValue)); TimeSpan currentTimespanValue = timeSpanUnit.GetTimeSpanValue(currentValue); property.floatValue = displayTimeSpanAttribute.UnderlyingValueType.GetFloatValue(currentTimespanValue); Rect returnRect = new Rect(position); returnRect.y += EditorGUIUtility.singleLineHeight; returnRect.height -= EditorGUIUtility.singleLineHeight; return(returnRect); }
/// <summary> /// 算式作成 /// </summary> /// <param name="p">題型參數</param> public override void MarkFormulaList(SchoolClockParameter p) { // 當前反推判定次數(一次推算內次數累加) int defeated = 0; // 按照指定數量作成相應的數學計算式 for (var i = 0; i < p.NumberOfQuestions; i++) { // 隨機獲取時間段類型中的一個類型 TimeIntervalType type = CommonUtil.GetRandomNumber(TimeIntervalType.Midnight, TimeIntervalType.LateNight); SchoolClockFormula formula = new SchoolClockFormula { LatestTime = new TimeType() { Hours = 0, Minutes = 0, Seconds = 0 } }; if (_timeIntervals.TryGetValue(type, out Action <SchoolClockFormula, FourOperationsType> timeInterval)) { timeInterval(formula, p.FourOperationsType); if (p.IsShowSeconds) { formula.LatestTime.Seconds = 0; } } else { throw new ArgumentException(MessageUtil.GetMessage(() => MsgResources.E0002L, type.ToString())); } if (CheckIsNeedInverseMethod(p.Formulas, formula)) { defeated++; // 如果大於兩次則認為此題無法作成繼續下一題 if (defeated == INVERSE_NUMBER) { // 當前反推判定次數復原 defeated = 0; continue; } i--; continue; } p.Formulas.Add(formula); } }