public override VisualElement Draw(object source, Type type, string label = "", Action <object> onValueChanged = null) { var container = new VisualElement(); if (!(source is IList list)) { return(container); } var foldout = UiElementFactory.CreateFoldout($"[{label} : {list.Count}]"); container.Add(foldout); var collectionType = list.GetType(); var genericType = collectionType. GetGenericArguments(). FirstOrDefault(); var listView = new ListView(list, 20, () => { return(new VisualElement()); }, (x, i) => { var item = list[i]; var targetType = genericType != null ? genericType : item?.GetType(); x.Add(UiElementFactory.Create( list[i], targetType, value => list[i] = value, i.ToStringFromCache())); }); container.Add(listView); return(container); }
public override VisualElement Draw(object source, Type type, string label = "", Action <object> onValueChanged = null) { var fields = type.GetFields( BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Default); var visibleFields = fields. Where(UiElementFactory.IsVisibleField). ToList(); var container = new VisualElement(); foreach (var field in visibleFields) { var fieldContainer = container; var value = field.GetValue(source); var element = UiElementFactory.Create( value, field.FieldType, x => field.SetValue(source, x), field.Name); if (element == null) { continue; } if (IsFoldoutObject(field.FieldType)) { var foldout = UiElementFactory.CreateFoldout(string.IsNullOrEmpty(label) ? field.Name : label); fieldContainer.Add(foldout); fieldContainer = foldout; } fieldContainer.Add(element); } return(container); }