public static ImmutableList <Error> checkComponent( CheckContext context, Object component, Option <CustomObjectValidator> customObjectValidatorOpt ) { var errors = ImmutableList <Error> .Empty; foreach (var mb in F.opt(value: component as MonoBehaviour)) { var componentType = component.GetType(); if (!context.checkedComponentTypes.Contains(item: componentType)) { errors = errors.AddRange(items: checkComponentType(context: context, go: mb.gameObject, type: componentType)); context = context.withCheckedComponentType(c: componentType); } } var serObj = new SerializedObject(obj: component); var sp = serObj.GetIterator(); while (sp.NextVisible(enterChildren: true)) { if ( sp.propertyType == SerializedPropertyType.ObjectReference && sp.objectReferenceValue == null && sp.objectReferenceInstanceIDValue != 0 ) { errors = errors.Add(value: Error.missingReference( o: component, property: sp.name, context: context )); } if (sp.type == nameof(UnityEvent)) { var evt = sp.findFieldValueInObject(component).flatMap(o => F.opt(o as UnityEvent)).getOrThrow(() => new Exception( $"There should have been a {nameof(UnityEvent)} in property '{sp.name}' " + $"on '{component}' @ '{AssetDatabase.GetAssetPath(component)}', " + $"but we could not find it! This seems like a programmer error!" ) ); errors = errors.AddRange(checkUnityEvent( evt: evt, component: component, propertyName: sp.name, context: context ).asEnum()); } } var fieldErrors = validateFields( containingComponent: component, objectBeingValidated: component, createError: new ErrorFactory(component, context), customObjectValidatorOpt: customObjectValidatorOpt ); errors = errors.AddRange(items: fieldErrors); return(errors); }
public static ImmutableList <Error> checkComponent( CheckContext context, Object component, Option <CustomObjectValidator> customObjectValidatorOpt, Option <UniqueValuesCache> uniqueCache = default ) { Option.ensureValue(ref uniqueCache); var errors = ImmutableList <Error> .Empty; foreach (var mb in F.opt(value: component as MonoBehaviour)) { var componentType = component.GetType(); if (!context.checkedComponentTypes.Contains(item: componentType)) { errors = errors.AddRange(items: checkComponentType(context: context, go: mb.gameObject, type: componentType)); context = context.withCheckedComponentType(c: componentType); } } var serObj = new SerializedObject(obj: component); var sp = serObj.GetIterator(); while (sp.NextVisible(enterChildren: true)) { if ( sp.propertyType == SerializedPropertyType.ObjectReference && sp.objectReferenceValue == null && sp.objectReferenceInstanceIDValue != 0 ) { errors = errors.Add(value: Error.missingReference( o: component, property: sp.name, context: context )); } } var fieldErrors = validateFields( containingComponent: component, objectBeingValidated: component, createError: new ErrorFactory(component, context), customObjectValidatorOpt: customObjectValidatorOpt, uniqueValuesCache: uniqueCache ); errors = errors.AddRange(items: fieldErrors); return(errors); }
public static ImmutableList <Error> checkComponent(CheckContext context, Object component) { var errors = ImmutableList <Error> .Empty; foreach (var mb in F.opt(component as MonoBehaviour)) { var componentType = component.GetType(); if (!context.checkedComponentTypes.Contains(componentType)) { errors = errors.AddRange(checkComponentType(context, mb.gameObject, componentType)); context = context.withCheckedComponentType(componentType); } } var serObj = new SerializedObject(component); var sp = serObj.GetIterator(); while (sp.NextVisible(enterChildren: true)) { if ( sp.propertyType == SerializedPropertyType.ObjectReference && sp.objectReferenceValue == null && sp.objectReferenceInstanceIDValue != 0 ) { errors = errors.Add(Error.missingReference( component, ObjectNames.NicifyVariableName(sp.name), context )); } if (sp.type == nameof(UnityEvent)) { foreach (var evt in getUnityEvent(component, sp.propertyPath)) { foreach (var err in checkUnityEvent(evt, component, sp.name, context)) { errors = errors.Add(err); } } } } var fieldErrors = validateFieldsWithAttributes( component, (err, fieldHierarchy) => { switch (err) { case FieldAttributeError.NullField: return(Error.nullReference(component, fieldHierarchy, context)); case FieldAttributeError.EmptyCollection: return(Error.emptyCollection(component, fieldHierarchy, context)); case FieldAttributeError.TextFieldBadTag: return(Error.textFieldBadTag(component, fieldHierarchy, context)); } return(F.matchErr <Error>(nameof(FieldAttributeError), err.ToString())); } ); errors = errors.AddRange(fieldErrors); return(errors); }