void CheckMaxBlockPermutationsAllowed(bool isBlockVariable) { if (!isBlockVariable || valuesProperty.arraySize <= ExperimentDesign.MaxBlockPermutationsAllowed) { return; } IExperimentDesignFile iExperimentDesignFile = VariableProperty.serializedObject.targetObject as IExperimentDesignFile; if (iExperimentDesignFile == null) { return; } if (iExperimentDesignFile.GetBlockOrderConfigurations.Count == 0) { VariableValidationResults.AddError( "Too many Block Values for automatic permutation. " + "Must define possible Block orders manually using BlockOrderDefinition files. " + "Please see docs."); } if (!iExperimentDesignFile.GetBlockOrderIsValid) { VariableValidationResults.AddWarning("A recent change has invalidated your manual block order configurations. " + "Please update them before running your experiment"); } }
void CheckProbabilityErrors(bool customProb) { if (!customProb || probabilitiesProperty.arraySize == 0) { return; } float runningTotal = GetRunningTotal(); string direction = ""; float remainder = 1 - runningTotal; if (Math.Abs(remainder) > 0.01f && probabilitiesProperty.arraySize > 0) { if (runningTotal > 1) { direction = " (too high)"; } if (runningTotal < 1) { direction = " (too low)"; } VariableValidationResults.AddError($"Custom Probabilities Error: Total = {runningTotal}{direction}"); } }
public void DrawInspector() { if (Deleted) { throw new NullReferenceException("Trying To Draw deleted variable inspector"); } if (deleteDialogIsOpen) { return; } VariableValidationResults = new VariableValidationResults(); int oldIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; EditorGUILayout.BeginVertical(EditorGuiHelper.AlternateColorBox); SerializedProperty expandSettingsProp = VariableProperty.FindPropertyRelative(nameof(Variable.ExpandSettings)); bool expanded; try { expanded = expandSettingsProp.boolValue; } catch (InvalidOperationException) { // this can happen if variable is deleted from the dialog, and viewer still gets called. Should be fixed by deleteDialogIsOpen check above. but keeping just in case. return; } DrawVariableHeader(expandSettingsProp); EditorGUI.indentLevel++; if (expanded) { DrawVariableSpecificInspector(); } EditorGUI.indentLevel--; EditorGUILayout.Space(); if (!VariableValidationResults.IsValid) { DrawVariableErrors(); } EditorGUILayout.Space(); EditorGUILayout.EndVertical(); EditorGUI.indentLevel = oldIndentLevel; DrawVariableDeleteButton(); EditorGUILayout.Space(); EditorGUILayout.Space(); }
public static void Validate(string nameStringValue, VariableValidationResults resultContainer) { if (!nameStringValue.All(c => Char.IsLetterOrDigit(c) || c == '_')) { resultContainer.AddError(InvalidName); } if (nameStringValue == UnnamedColumn.Name) { resultContainer.AddError(Unnamed); } }
protected override void DrawVariableSpecificInspector() { SerializedProperty blockProperty = VariableProperty.FindPropertyRelative(nameof(IndependentVariable.Block)); CheckMaxBlockPermutationsAllowed(blockProperty.boolValue); EditorGUILayout.PropertyField(blockProperty); SerializedProperty mixType = VariableProperty.FindPropertyRelative(nameof(IndependentVariable.MixingType)); VariableMixingType op = (VariableMixingType)mixType.intValue; op = (VariableMixingType)EditorGUILayout.EnumPopup("Mixing Type", op); mixType.intValue = (int)op; if (valuesProperty.arraySize == 0) { VariableValidationResults.AddWarning("No values"); } bool isCustomProbability = CheckIfCustomProbability(); EditorGUILayout.Space(); EditorGUILayout.Space(); valuesList.DoLayoutList(); EditorGUILayout.Space(); if (isCustomProbability) { CalculateFinalProbability(); CheckProbabilityErrors(true); } if (waitingToClearAllValues) { int n = valuesProperty.arraySize; for (int i = 0; i < n; i++) { RemoveValue(0); RemoveProbability(0); } waitingToClearAllValues = false; } }