private static void AddToSchemaDictionary(JsonSchemaToView self, ObjectFieldView objectFieldView) { if (objectFieldView == null) { Log.w("Passed fieldView was null, will skip AddToSchemaDictionary process"); return; } RestorePropertiesFromChildrenGOs(objectFieldView); JsonSchema schema = objectFieldView.field; if (schema.modelType.IsNullOrEmpty()) { Log.w("Missing schema.modelType in passsed ObjectFieldView.field", objectFieldView.gameObject); return; } if (!schema.properties.IsNullOrEmpty()) { // After the fieldView properties are reconstructed correctly again fill the schemaGenerator fieldView map to have a central lookup location if (!self.schemaGenerator.schemas.ContainsKey(schema.modelType)) { self.schemaGenerator.schemas.Add(schema.modelType, schema); } } else { Log.d($"Will skip {schema.title} since it seems to be a partly unresolved type"); } }
/// <summary> Since the rootFieldView.properties are not correctly serialized by unity, this Dictionary has to be reconstructed from the /// FieldViews in the children GameObjects.So first fill the properties of the rootFieldView again with the fields of the /// direct children GameObjects.And do this recursively for all found ObjectFieldViews </summary> private static void RestorePropertiesFromChildrenGOs(ObjectFieldView targetFieldView) { AssertV2.IsNotNull(targetFieldView, "targetFieldView"); if (targetFieldView.field.properties.IsNullOrEmpty()) { var children = targetFieldView.mainLink.gameObject.GetChildren().Map(c => c.GetComponent <FieldView>()).Filter(x => x != null); if (children.IsNullOrEmpty()) { Log.w(targetFieldView.fieldName + " had no children fieldViews"); } else { foreach (var vm in children.OfType <ObjectFieldView>()) { RestorePropertiesFromChildrenGOs(vm); } var fieldDict = children.ToDictionary(x => x.fieldName, x => x.field); if (!fieldDict.IsNullOrEmpty()) { targetFieldView.field.properties = fieldDict; } } } }